OXYGENHUB
◆ v0.1.0 oxygen / src / main.rs
1.3 KiB · Rust · last changed Two malloc arenas 1 month ago source blame history raw
1
//! `oxy`: command-line interface for Oxygen.
2
//!
3
//! Command definitions and dispatch live in `cli`; each command group has
4
//! its own module there.
5
6
mod cli;
7
8
#[cfg(feature = "alloc-stats")]
9
#[global_allocator]
10
static ALLOC: oxy_core::alloc_stats::Counting = oxy_core::alloc_stats::Counting;
11
12
fn main() {
13
    // Behave like other CLI tools when output is piped into `head`: die
14
    // quietly on SIGPIPE instead of panicking on a failed write.
15
    #[cfg(unix)]
16
    unsafe {
17
        libc::signal(libc::SIGPIPE, libc::SIG_DFL);
18
    }
19
    // glibc gives each thread that allocates an arena of its own and keeps
20
    // what is freed there: the first commit of the Linux tree, read and
21
    // hashed across threads, held 4.3 GB for 2.7 GB in use. Two arenas
22
    // hold 3.1 GB, no slower. MALLOC_ARENA_MAX still has the last word.
23
    #[cfg(all(target_os = "linux", target_env = "gnu"))]
24
    if std::env::var_os("MALLOC_ARENA_MAX").is_none() {
25
        unsafe {
26
            libc::mallopt(libc::M_ARENA_MAX, 2);
27
        }
28
    }
29
    let result = cli::run();
30
    oxy_core::timing::memory_summary();
31
    match result {
32
        Ok(code) => std::process::exit(code),
33
        Err(e) => {
34
            cli::ui::init(false);
35
            eprintln!("{} {e:#}", cli::ui::err("error:"));
36
            std::process::exit(1);
37
        }
38
    }
39
}