mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-30 15:03:42 +00:00
Merge #7334
7334: Add back jemalloc support r=jonas-schievink a=jonas-schievink jemalloc is useful due to its introspection API, which allows obtaining quick and accurate memory usage statistics without running into `mallinfo`'s limitations. Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
08efb8a943
7 changed files with 94 additions and 4 deletions
65
Cargo.lock
generated
65
Cargo.lock
generated
|
@ -448,6 +448,12 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fs_extra"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fsevent"
|
name = "fsevent"
|
||||||
version = "2.0.2"
|
version = "2.0.2"
|
||||||
|
@ -757,6 +763,38 @@ version = "0.4.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jemalloc-ctl"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7"
|
||||||
|
dependencies = [
|
||||||
|
"jemalloc-sys",
|
||||||
|
"libc",
|
||||||
|
"paste",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jemalloc-sys"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"fs_extra",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jemallocator"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
|
||||||
|
dependencies = [
|
||||||
|
"jemalloc-sys",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jod-thread"
|
name = "jod-thread"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
@ -1104,6 +1142,25 @@ dependencies = [
|
||||||
"drop_bomb",
|
"drop_bomb",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "0.1.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880"
|
||||||
|
dependencies = [
|
||||||
|
"paste-impl",
|
||||||
|
"proc-macro-hack",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste-impl"
|
||||||
|
version = "0.1.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-hack",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "paths"
|
name = "paths"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
@ -1164,6 +1221,12 @@ version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
|
checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-hack"
|
||||||
|
version = "0.5.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.24"
|
version = "1.0.24"
|
||||||
|
@ -1212,6 +1275,7 @@ name = "profile"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
|
"jemalloc-ctl",
|
||||||
"la-arena",
|
"la-arena",
|
||||||
"libc",
|
"libc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
@ -1354,6 +1418,7 @@ dependencies = [
|
||||||
"ide",
|
"ide",
|
||||||
"ide_db",
|
"ide_db",
|
||||||
"itertools 0.10.0",
|
"itertools 0.10.0",
|
||||||
|
"jemallocator",
|
||||||
"jod-thread",
|
"jod-thread",
|
||||||
"log",
|
"log",
|
||||||
"lsp-server",
|
"lsp-server",
|
||||||
|
|
|
@ -14,12 +14,14 @@ once_cell = "1.3.1"
|
||||||
cfg-if = "1"
|
cfg-if = "1"
|
||||||
libc = "0.2.73"
|
libc = "0.2.73"
|
||||||
la-arena = { version = "0.2.0", path = "../../lib/arena" }
|
la-arena = { version = "0.2.0", path = "../../lib/arena" }
|
||||||
|
jemalloc-ctl = { version = "0.3.3", optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
perf-event = "0.4"
|
perf-event = "0.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
cpu_profiler = []
|
cpu_profiler = []
|
||||||
|
jemalloc = ["jemalloc-ctl"]
|
||||||
|
|
||||||
# Uncomment to enable for the whole crate graph
|
# Uncomment to enable for the whole crate graph
|
||||||
# default = [ "cpu_profiler" ]
|
# default = [ "cpu_profiler" ]
|
||||||
|
|
|
@ -24,7 +24,12 @@ impl std::ops::Sub for MemoryUsage {
|
||||||
impl MemoryUsage {
|
impl MemoryUsage {
|
||||||
pub fn current() -> MemoryUsage {
|
pub fn current() -> MemoryUsage {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
|
if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
|
||||||
|
jemalloc_ctl::epoch::advance().unwrap();
|
||||||
|
MemoryUsage {
|
||||||
|
allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize),
|
||||||
|
}
|
||||||
|
} else if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
|
||||||
// Note: This is incredibly slow.
|
// Note: This is incredibly slow.
|
||||||
let alloc = unsafe { libc::mallinfo() }.uordblks as isize;
|
let alloc = unsafe { libc::mallinfo() }.uordblks as isize;
|
||||||
MemoryUsage { allocated: Bytes(alloc) }
|
MemoryUsage { allocated: Bytes(alloc) }
|
||||||
|
|
|
@ -61,8 +61,14 @@ proc_macro_srv = { path = "../proc_macro_srv", version = "0.0.0" }
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = "0.3.8"
|
winapi = "0.3.8"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
|
jemallocator = { version = "0.3.2", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
expect-test = "1.1"
|
expect-test = "1.1"
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
mbe = { path = "../mbe" }
|
mbe = { path = "../mbe" }
|
||||||
tt = { path = "../tt" }
|
tt = { path = "../tt" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
jemalloc = ["jemallocator", "profile/jemalloc"]
|
||||||
|
|
|
@ -15,6 +15,10 @@ use vfs::AbsPathBuf;
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Err(err) = try_main() {
|
if let Err(err) = try_main() {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
|
|
|
@ -67,6 +67,7 @@ pub struct ServerOpt {
|
||||||
pub enum Malloc {
|
pub enum Malloc {
|
||||||
System,
|
System,
|
||||||
Mimalloc,
|
Mimalloc,
|
||||||
|
Jemalloc,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InstallCmd {
|
impl InstallCmd {
|
||||||
|
@ -176,6 +177,7 @@ fn install_server(opts: ServerOpt) -> Result<()> {
|
||||||
let features = match opts.malloc {
|
let features = match opts.malloc {
|
||||||
Malloc::System => &[][..],
|
Malloc::System => &[][..],
|
||||||
Malloc::Mimalloc => &["--features", "mimalloc"],
|
Malloc::Mimalloc => &["--features", "mimalloc"],
|
||||||
|
Malloc::Jemalloc => &["--features", "jemalloc"],
|
||||||
};
|
};
|
||||||
|
|
||||||
let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}");
|
let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}");
|
||||||
|
|
|
@ -49,7 +49,8 @@ FLAGS:
|
||||||
--client[=CLIENT] Install only VS Code plugin.
|
--client[=CLIENT] Install only VS Code plugin.
|
||||||
CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'
|
CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'
|
||||||
--server Install only the language server
|
--server Install only the language server
|
||||||
--mimalloc Use mimalloc for server
|
--mimalloc Use mimalloc allocator for server
|
||||||
|
--jemalloc Use jemalloc allocator for server
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
|
@ -65,8 +66,13 @@ FLAGS:
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let malloc =
|
let malloc = if args.contains("--mimalloc") {
|
||||||
if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
|
Malloc::Mimalloc
|
||||||
|
} else if args.contains("--jemalloc") {
|
||||||
|
Malloc::Jemalloc
|
||||||
|
} else {
|
||||||
|
Malloc::System
|
||||||
|
};
|
||||||
|
|
||||||
let client_opt = args.opt_value_from_str("--client")?;
|
let client_opt = args.opt_value_from_str("--client")?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue