From c07e88ee4eaa942e13561a5a7c87bebfd128ee49 Mon Sep 17 00:00:00 2001 From: zephyr Date: Tue, 26 Jul 2022 14:01:17 +0900 Subject: [PATCH] add optional page-allocator --- Cargo.lock | 10 ++++++++++ Cargo.toml | 2 ++ readme.md | 1 + src/bin.rs | 6 +++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index bb53e1e..3e9a986 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -629,6 +629,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "mmap-allocator" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f0d1de3adf2053ad56a86a2b35fd0e74d9a82eb6d204821a2186cc96cb6a6c7" +dependencies = [ + "libc", +] + [[package]] name = "ntapi" version = "0.3.6" @@ -867,6 +876,7 @@ dependencies = [ "jemallocator", "log", "mimalloc", + "mmap-allocator", "realm_core", "realm_io 0.3.3", "realm_syscall 0.1.4", diff --git a/Cargo.toml b/Cargo.toml index bca2b72..96da08f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ mimalloc = { version = "0.1", optional = true } [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = { version = "0.5", optional = true } +mmap-allocator = { version = "0.3", optional = true } [dev-dependencies] @@ -70,6 +71,7 @@ multi-thread = ["tokio/rt-multi-thread"] brutal-shutdown = ["realm_io/brutal-shutdown"] jemalloc = ["jemallocator"] mi-malloc = ["mimalloc"] +page-alloc = ["mmap-allocator"] [profile.release] diff --git a/readme.md b/readme.md index 4b69b81..d34dfe0 100644 --- a/readme.md +++ b/readme.md @@ -69,6 +69,7 @@ RUSTFLAGS='-C target_cpu=native' cargo build --release - multi-thread: enable tokio's multi-threaded IO scheduler. - mi-malloc: custom memory allocator. - jemalloc: custom memory allocator. +- page-alloc: custom memory allocator. Default: hook + proxy + balance + transport + multi-thread. diff --git a/src/bin.rs b/src/bin.rs index 6d6f9f2..9daa39c 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -9,7 +9,7 @@ use realm::relay; use realm::ENV_CONFIG; cfg_if! { - if #[cfg(all(feature = "mi-malloc"))] { + if #[cfg(feature = "mi-malloc")] { use mimalloc::MiMalloc; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; @@ -17,6 +17,10 @@ cfg_if! { use jemallocator::Jemalloc; #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; + } else if #[cfg(all(feature = "page-alloc", unix))] { + use mmap_allocator::MmapAllocator; + #[global_allocator] + static GLOBAL: MmapAllocator = MmapAllocator::new(); } }