diff --git a/Cargo.lock b/Cargo.lock index ee5604d..e2a1cc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -611,6 +611,7 @@ dependencies = [ "libproc", "linked-hash-map", "maxminddb", + "mimalloc", "netlink-packet-core", "netlink-packet-sock-diag", "netlink-sys", @@ -2122,6 +2123,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "libmimalloc-sys" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libproc" version = "0.13.0" @@ -2265,6 +2276,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mimalloc" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.16" diff --git a/boltconn/Cargo.toml b/boltconn/Cargo.toml index 0f12dab..03197f8 100644 --- a/boltconn/Cargo.toml +++ b/boltconn/Cargo.toml @@ -96,6 +96,7 @@ netlink-sys = "0.8.3" netlink-packet-core = "0.5.0" netlink-packet-sock-diag = "0.4.0" procfs = "0.16.0" +mimalloc = "0.1.43" [dev-dependencies] tracing-test = "0.2.4" diff --git a/boltconn/src/main.rs b/boltconn/src/main.rs index f66cd91..928f03a 100644 --- a/boltconn/src/main.rs +++ b/boltconn/src/main.rs @@ -27,6 +27,14 @@ mod platform; mod proxy; mod transport; +// System default allocator (glibc) won't reclaim freed memory actively on Linux. +// Without enough SWAP and RAM, this may cause OOM. Use MiMalloc to mitigate this issue. +#[cfg(target_os = "linux")] +use mimalloc::MiMalloc; +#[cfg(target_os = "linux")] +#[global_allocator] +static GLOBAL: MiMalloc = MiMalloc; + #[derive(Debug, Parser)] #[clap(name = "boltconn", about = "CLI interface of BoltConn", version = env!("CARGO_PKG_VERSION"))] struct ProgramArgs {