Skip to content

Commit

Permalink
update proposal.
Browse files Browse the repository at this point in the history
- snmalloc to last version.
- then adding a handful of available build options, diabling TLS support and LTO linkage.

Signed-off-by: David Carlier <[email protected]>
  • Loading branch information
devnexen committed Feb 10, 2024
1 parent aa0d241 commit a39f227
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ native-cpu = ["snmalloc-sys/native-cpu"]
local_dynamic_tls = ["snmalloc-sys/local_dynamic_tls"]
win8compat = ["snmalloc-sys/win8compat"]
usecxx17 = ["snmalloc-sys/usecxx17"]
check = ["snmalloc-sys/check"]
check = ["snmalloc-sys/check"]
lto = ["snmalloc-sys/lto"]
notls = ["snmalloc-sys/notls"]
2 changes: 2 additions & 0 deletions snmalloc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ local_dynamic_tls = []
win8compat = []
usecxx17 = []
check = []
lto = []
notls = []
50 changes: 32 additions & 18 deletions snmalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,22 @@ fn main() {
}

if cfg!(feature = "cache-friendly") {
eprintln!("cache-friendly feature flag is deprecated and no longer has any effect. \
it may be removed in a future release");
eprintln!(
"cache-friendly feature flag is deprecated and no longer has any effect. \
it may be removed in a future release"
);
// The following code no longer works
// build.define("CACHE_FRIENDLY_OFFSET", "64");
}

if cfg!(feature = "lto") {
build.define("SNMALLOC_IPO", "ON");
}

if cfg!(feature = "notls") {
build.define("SNMALLOC_ENABLE_DYNAMIC_LOADING", "ON");
}

build.compile(target);

if target_env == "msvc" {
Expand All @@ -140,14 +150,16 @@ fn main() {
// no need
} else {
// link c++ runtime
println!("cargo:rustc-link-lib={}",
std::env::var("CXXSTDLIB").unwrap_or_else(|_| {
if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") {
"c++".to_string()
} else {
"stdc++".to_string()
}
}))
println!(
"cargo:rustc-link-lib={}",
std::env::var("CXXSTDLIB").unwrap_or_else(|_| {
if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") {
"c++".to_string()
} else {
"stdc++".to_string()
}
})
)
}
}

Expand Down Expand Up @@ -305,13 +317,15 @@ fn main() {
// not need for explicit c++ runtime
} else {
// link c++ runtime
println!("cargo:rustc-link-lib={}",
std::env::var("CXXSTDLIB").unwrap_or_else(|_| {
if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") {
"c++".to_string()
} else {
"stdc++".to_string()
}
}))
println!(
"cargo:rustc-link-lib={}",
std::env::var("CXXSTDLIB").unwrap_or_else(|_| {
if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") {
"c++".to_string()
} else {
"stdc++".to_string()
}
})
)
}
}
2 changes: 1 addition & 1 deletion snmalloc-sys/snmalloc
Submodule snmalloc updated 41 files
+28 −15 .github/workflows/main.yml
+13 −2 CMakeLists.txt
+2 −1 README.md
+1 −4 src/snmalloc/aal/aal.h
+1 −1 src/snmalloc/aal/aal_arm.h
+5 −5 src/snmalloc/aal/aal_cheri.h
+56 −64 src/snmalloc/aal/aal_concept.h
+5 −1 src/snmalloc/aal/aal_x86.h
+11 −0 src/snmalloc/backend/backend.h
+2 −4 src/snmalloc/backend/fixedglobalconfig.h
+2 −2 src/snmalloc/backend_helpers/buddy.h
+0 −1 src/snmalloc/backend_helpers/range_helpers.h
+0 −1 src/snmalloc/backend_helpers/smallbuddyrange.h
+4 −3 src/snmalloc/ds/aba.h
+2 −2 src/snmalloc/ds_core/helpers.h
+4 −4 src/snmalloc/ds_core/mitigations.h
+35 −50 src/snmalloc/ds_core/redblacktree.h
+3 −0 src/snmalloc/ds_core/seqset.h
+2 −1 src/snmalloc/global/memcpy.h
+92 −112 src/snmalloc/mem/backend_concept.h
+82 −17 src/snmalloc/mem/corealloc.h
+9 −2 src/snmalloc/mem/localalloc.h
+7 −10 src/snmalloc/mem/metadata.h
+23 −57 src/snmalloc/mem/pool.h
+25 −1 src/snmalloc/mem/pooled.h
+4 −3 src/snmalloc/mem/remoteallocator.h
+9 −3 src/snmalloc/mem/sizeclasstable.h
+2 −2 src/snmalloc/override/jemalloc_compat.cc
+180 −0 src/snmalloc/override/libc.h
+28 −149 src/snmalloc/override/malloc.cc
+1 −1 src/snmalloc/override/memcpy.cc
+22 −28 src/snmalloc/override/new.cc
+3 −3 src/snmalloc/override/rust.cc
+65 −84 src/snmalloc/pal/pal_concept.h
+1 −1 src/snmalloc/pal/pal_noalloc.h
+1 −0 src/snmalloc/snmalloc_front.h
+1 −2 src/test/func/cheri/cheri.cc
+2 −4 src/test/func/domestication/domestication.cc
+9 −15 src/test/func/pool/pool.cc
+2 −2 src/test/func/sandbox/sandbox.cc
+94 −0 src/test/perf/startup/startup.cc
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ unsafe impl GlobalAlloc for SnMalloc {
ffi::sn_rust_alloc(layout.align(), layout.size()) as _
}


/// De-allocate the memory at the given address with the given alignment and size.
/// The client must assure the following things:
/// - the memory is acquired using the same allocator and the pointer points to the start position.
Expand Down Expand Up @@ -113,4 +112,15 @@ mod tests {
alloc.dealloc(ptr, layout);
}
}

#[test]
fn it_frees_large_alloc() {
unsafe {
let layout = Layout::from_size_align(1 << 20, 32).unwrap();
let alloc = SnMalloc;

let ptr = alloc.alloc(layout);
alloc.dealloc(ptr, layout);
}
}
}

0 comments on commit a39f227

Please sign in to comment.