forked from 1jehuang/jcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
58 lines (48 loc) · 2.16 KB
/
main.rs
File metadata and controls
58 lines (48 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#[cfg(feature = "jemalloc")]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
// Tune jemalloc for a long-running server with bursty allocations (e.g. loading
// and unloading an ~87 MB ONNX embedding model). The defaults (muzzy_decay_ms:0,
// retain:true, narenas:8*ncpu) caused 1.4 GB RSS in previous testing.
//
// dirty_decay_ms:1000 — return dirty pages to OS after 1 s idle
// muzzy_decay_ms:1000 — release muzzy pages after 1 s
// narenas:4 — limit arena count (17 threads don't need 64 arenas)
// prof:true — enable profiling support in jemalloc-prof builds
// prof_active:false — keep sampling disabled until explicitly enabled at runtime
#[cfg(all(feature = "jemalloc", not(feature = "jemalloc-prof")))]
// jemalloc reads this exact exported symbol name at startup.
#[allow(non_upper_case_globals)]
#[unsafe(no_mangle)]
pub static malloc_conf: Option<&'static [u8; 50]> =
Some(b"dirty_decay_ms:1000,muzzy_decay_ms:1000,narenas:4\0");
#[cfg(feature = "jemalloc-prof")]
// jemalloc reads this exact exported symbol name at startup.
#[allow(non_upper_case_globals)]
#[unsafe(no_mangle)]
pub static malloc_conf: Option<&'static [u8; 78]> =
Some(b"dirty_decay_ms:1000,muzzy_decay_ms:1000,narenas:4,prof:true,prof_active:false\0");
use anyhow::Result;
#[cfg(all(target_os = "linux", not(feature = "jemalloc")))]
fn configure_system_allocator() {
unsafe extern "C" {
fn mallopt(param: i32, value: i32) -> i32;
}
const M_ARENA_MAX: i32 = -8;
let arena_max = std::env::var("JCODE_GLIBC_ARENA_MAX")
.ok()
.and_then(|value| value.trim().parse::<i32>().ok())
.filter(|value| *value > 0)
.unwrap_or(4);
let _ = unsafe { mallopt(M_ARENA_MAX, arena_max) };
}
#[cfg(not(all(target_os = "linux", not(feature = "jemalloc"))))]
fn configure_system_allocator() {}
fn main() -> Result<()> {
configure_system_allocator();
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
runtime.block_on(async { jcode::run().await })
}