fix: set M_MMAP_THRESHOLD to prevent glibc memory fragmentation
This commit is contained in:
parent
84a0bd71cb
commit
91dadaec90
1 changed files with 22 additions and 0 deletions
|
|
@ -28,6 +28,25 @@ use ron::error::SpannedError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::prelude::*;
|
||||||
|
|
||||||
|
/// Access glibc malloc tunables.
|
||||||
|
#[cfg(target_env = "gnu")]
|
||||||
|
mod malloc {
|
||||||
|
use std::os::raw::c_int;
|
||||||
|
|
||||||
|
const M_MMAP_THRESHOLD: c_int = -3;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn mallopt(param: c_int, value: c_int) -> c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Prevents glibc from hoarding memory via memory fragmentation.
|
||||||
|
pub fn limit_mmap_threshold() {
|
||||||
|
unsafe {
|
||||||
|
mallopt(M_MMAP_THRESHOLD, 65536);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug, Serialize, Deserialize, Clone)]
|
#[derive(Parser, Debug, Serialize, Deserialize, Clone)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
#[command(propagate_version = true)]
|
#[command(propagate_version = true)]
|
||||||
|
|
@ -140,6 +159,9 @@ impl CosmicFlags for Args {
|
||||||
///
|
///
|
||||||
/// Returns error if iced fails to run the application.
|
/// Returns error if iced fails to run the application.
|
||||||
pub fn main() -> color_eyre::Result<()> {
|
pub fn main() -> color_eyre::Result<()> {
|
||||||
|
#[cfg(target_env = "gnu")]
|
||||||
|
malloc::limit_mmap_threshold();
|
||||||
|
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
|
||||||
if std::env::var("RUST_SPANTRACE").is_err() {
|
if std::env::var("RUST_SPANTRACE").is_err() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue