main: Increase soft file limit
This commit is contained in:
parent
fa7926f7c1
commit
6ba7242cfc
6 changed files with 60 additions and 21 deletions
|
|
@ -5,5 +5,6 @@ pub(crate) use self::ids::id_gen;
|
|||
pub mod geometry;
|
||||
pub mod iced;
|
||||
pub mod prelude;
|
||||
pub mod rlimit;
|
||||
pub mod screenshot;
|
||||
pub mod tween;
|
||||
|
|
|
|||
30
src/utils/rlimit.rs
Normal file
30
src/utils/rlimit.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use rustix::process::{getrlimit, setrlimit, Resource, Rlimit};
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
static OLD_LIMIT: AtomicU64 = AtomicU64::new(0);
|
||||
static MAX_LIMIT: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
pub fn increase_nofile_limit() {
|
||||
let mut limits = getrlimit(Resource::Nofile);
|
||||
|
||||
OLD_LIMIT.store(limits.current.unwrap_or(0), Ordering::SeqCst);
|
||||
MAX_LIMIT.store(limits.maximum.unwrap_or(0), Ordering::SeqCst);
|
||||
limits.current = limits.maximum;
|
||||
|
||||
if let Err(err) = setrlimit(Resource::Nofile, limits) {
|
||||
tracing::warn!("Failed to raise nofile soft limit: {:?}", err);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn restore_nofile_limit() {
|
||||
let current = OLD_LIMIT.load(Ordering::SeqCst);
|
||||
let maximum = MAX_LIMIT.load(Ordering::SeqCst);
|
||||
let limits = Rlimit {
|
||||
current: (current > 0).then_some(current),
|
||||
maximum: (maximum > 0).then_some(maximum),
|
||||
};
|
||||
|
||||
if let Err(err) = setrlimit(Resource::Nofile, limits) {
|
||||
eprintln!("Failed to restore nofile soft limit: {:?}", err);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue