From 6c75ce19f49aa24c26a2fc897ca2a82aeeb79f09 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Fri, 7 May 2021 10:55:43 +0800 Subject: [PATCH] support snmalloc and rpmalloc --- Cargo.lock | 49 +++++++++++++++++++++++++++++++++++++ Cargo.toml | 5 ++++ README.md | 10 +++++--- bin/common/allocator/mod.rs | 8 ++++++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7284de2..af4aa80e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -205,6 +205,15 @@ dependencies = [ "vec_map", ] +[[package]] +name = "cmake" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855" +dependencies = [ + "cc", +] + [[package]] name = "core-foundation" version = "0.9.1" @@ -1302,6 +1311,26 @@ dependencies = [ "winapi", ] +[[package]] +name = "rpmalloc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dae55d27fc56f399aec2583434bf22c7100fe983b2115bbc1d961ec4f7df5db" +dependencies = [ + "rpmalloc-sys", +] + +[[package]] +name = "rpmalloc-sys" +version = "0.2.1+1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3e9198b851305d2f4bf86353b98016d79b871158ea5f9d0756b84022aefb99" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "rustls" version = "0.19.1" @@ -1528,7 +1557,9 @@ dependencies = [ "log4rs", "mimalloc", "qrcode", + "rpmalloc", "shadowsocks-service", + "snmalloc-rs", "tcmalloc", "tokio", ] @@ -1604,6 +1635,24 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +[[package]] +name = "snmalloc-rs" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5a6194d59b08fc87381e7c8a04ab4ab9967282b00f409bb742e08f3514ed0b" +dependencies = [ + "snmalloc-sys", +] + +[[package]] +name = "snmalloc-sys" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9518813a25ab2704a6df4968f609aa6949705409b6a854dcc87018d12961cbc8" +dependencies = [ + "cmake", +] + [[package]] name = "socket2" version = "0.3.19" diff --git a/Cargo.toml b/Cargo.toml index b74045d1..e429876a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,6 +98,9 @@ jemalloc = ["jemallocator"] # Enable bundled tcmalloc tcmalloc-vendored = ["tcmalloc/bundled"] +# Enable snmalloc for binaries +snmalloc = ["snmalloc-rs"] + # Enable tokio's multi-threaded runtime multi-threaded = ["tokio/rt-multi-thread"] @@ -125,6 +128,8 @@ tokio = { version = "1", features = ["rt", "signal"] } mimalloc = { version = "0.1", optional = true } tcmalloc = { version = "0.3", optional = true } jemallocator = { version = "0.3", optional = true } +snmalloc-rs = { version = "0.2", optional = true } +rpmalloc = { version = "0.2", optional = true } shadowsocks-service = { version = "1.10.6", path = "./crates/shadowsocks-service" } diff --git a/README.md b/README.md index 46283fca..3ef5a641 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ This is a port of [shadowsocks](https://github.com/shadowsocks/shadowsocks). shadowsocks is a fast tunnel proxy that helps you bypass firewalls. -| Library | Description | -| ------- | ----------- | -| [**shadowsocks**](https://crates.io/crates/shadowsocks) | [![crates.io](https://img.shields.io/crates/v/shadowsocks.svg)](https://crates.io/crates/shadowsocks) [![docs.rs](https://img.shields.io/docsrs/shadowsocks)](https://docs.rs/shadowsocks) shadowsocks core protocol | +| Library | Description | +| ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [**shadowsocks**](https://crates.io/crates/shadowsocks) | [![crates.io](https://img.shields.io/crates/v/shadowsocks.svg)](https://crates.io/crates/shadowsocks) [![docs.rs](https://img.shields.io/docsrs/shadowsocks)](https://docs.rs/shadowsocks) shadowsocks core protocol | | [**shadowsocks-service**](https://crates.io/crates/shadowsocks-service) | [![crates.io](https://img.shields.io/crates/v/shadowsocks-service.svg)](https://crates.io/crates/shadowsocks-service) [![docs.rs](https://img.shields.io/docsrs/shadowsocks-service)](https://docs.rs/shadowsocks-service) Services for serving shadowsocks | -| [**shadowsocks-rust**](https://crates.io/crates/shadowsocks-rust) | [![crates.io](https://img.shields.io/crates/v/shadowsocks-rust.svg)](https://crates.io/crates/shadowsocks-rust) Binaries running common shadowsocks services | +| [**shadowsocks-rust**](https://crates.io/crates/shadowsocks-rust) | [![crates.io](https://img.shields.io/crates/v/shadowsocks-rust.svg)](https://crates.io/crates/shadowsocks-rust) Binaries running common shadowsocks services | ## Build & Install @@ -46,6 +46,8 @@ This project uses system (libc) memory allocator (Rust's default). But it also a * `jemalloc` - Uses [jemalloc](http://jemalloc.net/) as global memory allocator * `mimalloc` - Uses [mi-malloc](https://microsoft.github.io/mimalloc/) as global memory allocator * `tcmalloc` - Uses [TCMalloc](https://google.github.io/tcmalloc/overview.html) as global memory allocator. It tries to link system-wide tcmalloc by default, use vendored from source with `tcmalloc-vendored`. +* `snmalloc` - Uses [snmalloc](https://github.com/microsoft/snmalloc) as gloal memory allocator +* `rpmalloc` - Uses [rpmalloc](https://github.com/mjansson/rpmalloc) as global memory allocator ### **crates.io** diff --git a/bin/common/allocator/mod.rs b/bin/common/allocator/mod.rs index 46fcc652..f95d125f 100644 --- a/bin/common/allocator/mod.rs +++ b/bin/common/allocator/mod.rs @@ -11,3 +11,11 @@ static ALLOC: tcmalloc::TCMalloc = tcmalloc::TCMalloc; #[cfg(feature = "mimalloc")] #[global_allocator] static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; + +#[cfg(feature = "snmalloc")] +#[global_allocator] +static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; + +#[cfg(feature = "rpmalloc")] +#[global_allocator] +static ALLOC: rpmalloc::RpMalloc = rpmalloc::RpMalloc;