Vendor asic-rs 0.8.1 (280 crates, offline builds) + wxWidgets 3.3.3 (pristine + patch queue); UI spec + ADR-0003; M1 on asic-rs
This commit is contained in:
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
#[cfg(unix)]
|
||||
mod unix_limits {
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
|
||||
use rlimit::Resource;
|
||||
|
||||
const DEFAULT_NOFILE_LIMIT: u64 = 16384; // or another number
|
||||
|
||||
/// Try to increase NOFILE limit and return the current soft limit.
|
||||
pub fn increase_nofile_limit() -> io::Result<u64> {
|
||||
let (soft, hard) = Resource::NOFILE.get()?;
|
||||
println!("Before increasing: soft = {soft}, hard = {hard}");
|
||||
|
||||
let target = cmp::min(DEFAULT_NOFILE_LIMIT, hard);
|
||||
println!("Try to increase: target = {target}");
|
||||
Resource::NOFILE.set(target, hard)?;
|
||||
|
||||
let (soft, hard) = Resource::NOFILE.get()?;
|
||||
println!("After increasing: soft = {soft}, hard = {hard}");
|
||||
Ok(soft)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
match unix_limits::increase_nofile_limit() {
|
||||
Ok(soft) => println!("NOFILE limit: soft = {soft}"),
|
||||
Err(err) => println!("Failed to increase NOFILE limit: {err}"),
|
||||
}
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
println!("Do nothing on non-Unix systems");
|
||||
}
|
||||
}
|
||||
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
//! Example demonstrating how to read system-wide file descriptor limits.
|
||||
//!
|
||||
//! This example shows the difference between:
|
||||
//! - System-wide limits from /proc/sys/fs/
|
||||
//! - Per-process limits from getrlimit()
|
||||
//!
|
||||
//! Run with: cargo run --example sys_limits
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn main() {
|
||||
use rlimit::{Resource, SysLimits};
|
||||
|
||||
println!("=== System-wide File Descriptor Limits ===\n");
|
||||
|
||||
// Read system-wide limits
|
||||
match SysLimits::read() {
|
||||
Ok(limits) => {
|
||||
if let Some(file_max) = limits.file_max {
|
||||
println!("System file-max: {}", file_max);
|
||||
println!(" (Maximum number of file descriptors system-wide)");
|
||||
}
|
||||
|
||||
if let Some(file_nr) = &limits.file_nr {
|
||||
println!("\nCurrent file descriptor usage:");
|
||||
println!(" Allocated: {}", file_nr.allocated);
|
||||
println!(" Free: {}", file_nr.free);
|
||||
println!(" Maximum: {}", file_nr.maximum);
|
||||
|
||||
let usage_percent = if file_nr.maximum > 0 {
|
||||
(file_nr.allocated as f64 / file_nr.maximum as f64) * 100.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
println!(" Usage: {:.2}%", usage_percent);
|
||||
}
|
||||
|
||||
if let Some(nr_open) = limits.nr_open {
|
||||
println!("\nPer-process nr_open: {}", nr_open);
|
||||
println!(" (Maximum NOFILE limit that can be set per-process)");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to read system limits: {}", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
println!("\n=== Per-process NOFILE Limit ===\n");
|
||||
|
||||
// Compare with per-process NOFILE limit
|
||||
match Resource::NOFILE.get() {
|
||||
Ok((soft, hard)) => {
|
||||
println!("NOFILE soft limit: {}", soft);
|
||||
println!("NOFILE hard limit: {}", hard);
|
||||
println!(" (Limits for this process only)");
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to get NOFILE limit: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
println!("\n=== Key Differences ===\n");
|
||||
println!("• file-max: System-wide limit on total file descriptors");
|
||||
println!("• nr_open: Maximum value for per-process NOFILE limit");
|
||||
println!("• NOFILE: Actual limit for this specific process");
|
||||
println!();
|
||||
println!("Hierarchy: file-max >= sum(all process NOFILE) and NOFILE <= nr_open");
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
fn main() {
|
||||
println!("This example only works on Linux and Android systems.");
|
||||
println!("System-wide limits are not available on this platform.");
|
||||
}
|
||||
Reference in New Issue
Block a user