fix: set M_MALLOC_THRESHOLD to prevent memory fragmentation

This commit is contained in:
Michael Aaron Murphy 2025-02-04 16:25:57 +01:00 committed by Michael Murphy
parent 726c8288da
commit 8b4e2578ec
3 changed files with 10 additions and 1 deletions

1
Cargo.lock generated
View file

@ -1353,6 +1353,7 @@ dependencies = [
"cosmic-applet-time",
"cosmic-applet-workspaces",
"cosmic-panel-button",
"libc",
"libcosmic",
"tracing",
"tracing-log",

View file

@ -20,6 +20,7 @@ cosmic-applet-time = { path = "../cosmic-applet-time" }
cosmic-applet-workspaces = { path = "../cosmic-applet-workspaces" }
cosmic-applet-input-sources = { path = "../cosmic-applet-input-sources" }
cosmic-panel-button = { path = "../cosmic-panel-button" }
libc = "0.2"
libcosmic.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

View file

@ -4,6 +4,13 @@
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() -> cosmic::iced::Result {
// Prevents glibc from hoarding memory, such as cosmic-applet-minimize
// consuming 100s of megabytes on restoring a minimized window.
#[cfg(target_env = "gnu")]
unsafe {
libc::mallopt(libc::M_MMAP_THRESHOLD, 65536);
}
tracing_subscriber::fmt().with_env_filter("warn").init();
let _ = tracing_log::LogTracer::init();
@ -32,6 +39,6 @@ fn main() -> cosmic::iced::Result {
"cosmic-applet-workspaces" => cosmic_applet_workspaces::run(),
"cosmic-applet-input-sources" => cosmic_applet_input_sources::run(),
"cosmic-panel-button" => cosmic_panel_button::run(),
_ => return Ok(()),
_ => Ok(()),
}
}