integrate trim-on-park memory reclamation to runtime
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
7a8ca8842a
commit
77d8e26efe
2 changed files with 33 additions and 1 deletions
|
@ -80,6 +80,18 @@ pub(crate) struct Args {
|
||||||
default_missing_value = "true",
|
default_missing_value = "true",
|
||||||
)]
|
)]
|
||||||
pub(crate) worker_affinity: bool,
|
pub(crate) worker_affinity: bool,
|
||||||
|
|
||||||
|
/// Toggles feature to promote memory reclamation by the operating system
|
||||||
|
/// when tokio worker runs out of work.
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
hide(true),
|
||||||
|
env = "CONDUWUIT_RUNTIME_GC_ON_PARK",
|
||||||
|
action = ArgAction::Set,
|
||||||
|
num_args = 0..=1,
|
||||||
|
require_equals(false),
|
||||||
|
)]
|
||||||
|
pub(crate) gc_on_park: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse commandline arguments into structured data
|
/// Parse commandline arguments into structured data
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
|
result::LogErr,
|
||||||
utils::sys::compute::{nth_core_available, set_affinity},
|
utils::sys::compute::{nth_core_available, set_affinity},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
@ -22,12 +23,17 @@ const WORKER_KEEPALIVE: u64 = 36;
|
||||||
const MAX_BLOCKING_THREADS: usize = 1024;
|
const MAX_BLOCKING_THREADS: usize = 1024;
|
||||||
|
|
||||||
static WORKER_AFFINITY: OnceLock<bool> = OnceLock::new();
|
static WORKER_AFFINITY: OnceLock<bool> = OnceLock::new();
|
||||||
|
static GC_ON_PARK: OnceLock<Option<bool>> = OnceLock::new();
|
||||||
|
|
||||||
pub(super) fn new(args: &Args) -> Result<tokio::runtime::Runtime> {
|
pub(super) fn new(args: &Args) -> Result<tokio::runtime::Runtime> {
|
||||||
WORKER_AFFINITY
|
WORKER_AFFINITY
|
||||||
.set(args.worker_affinity)
|
.set(args.worker_affinity)
|
||||||
.expect("set WORKER_AFFINITY from program argument");
|
.expect("set WORKER_AFFINITY from program argument");
|
||||||
|
|
||||||
|
GC_ON_PARK
|
||||||
|
.set(args.gc_on_park)
|
||||||
|
.expect("set GC_ON_PARK from program argument");
|
||||||
|
|
||||||
let mut builder = Builder::new_multi_thread();
|
let mut builder = Builder::new_multi_thread();
|
||||||
builder
|
builder
|
||||||
.enable_io()
|
.enable_io()
|
||||||
|
@ -138,7 +144,21 @@ fn thread_unpark() {}
|
||||||
name = %thread::current().name().unwrap_or("None"),
|
name = %thread::current().name().unwrap_or("None"),
|
||||||
),
|
),
|
||||||
)]
|
)]
|
||||||
fn thread_park() {}
|
fn thread_park() {
|
||||||
|
match GC_ON_PARK
|
||||||
|
.get()
|
||||||
|
.as_ref()
|
||||||
|
.expect("GC_ON_PARK initialized by runtime::new()")
|
||||||
|
{
|
||||||
|
| Some(true) | None if cfg!(feature = "jemalloc_conf") => gc_on_park(),
|
||||||
|
| _ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gc_on_park() {
|
||||||
|
#[cfg(feature = "jemalloc")]
|
||||||
|
conduwuit::alloc::je::this_thread::decay().log_err().ok();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(tokio_unstable)]
|
#[cfg(tokio_unstable)]
|
||||||
#[tracing::instrument(
|
#[tracing::instrument(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue