1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use crate::{read_file, read_value, write_value, ProcResult};
use std::time::Duration;
pub mod binfmt_misc;
pub mod epoll;
#[derive(Debug, Clone)]
pub struct DEntryState {
pub nr_dentry: u32,
pub nr_unused: u32,
pub age_limit: Duration,
pub want_pages: bool,
}
impl DEntryState {
fn from_str(s: &str) -> ProcResult<DEntryState> {
let mut s = s.split_whitespace();
let nr_dentry = from_str!(u32, expect!(s.next()));
let nr_unused = from_str!(u32, expect!(s.next()));
let age_limit_sec = from_str!(u32, expect!(s.next()));
let want_pages = from_str!(u32, expect!(s.next()));
Ok(DEntryState {
nr_dentry,
nr_unused,
age_limit: Duration::from_secs(age_limit_sec as u64),
want_pages: want_pages != 0,
})
}
}
pub fn dentry_state() -> ProcResult<DEntryState> {
let s: String = read_file("/proc/sys/fs/dentry-state")?;
DEntryState::from_str(&s)
}
pub fn file_max() -> ProcResult<usize> {
read_value("/proc/sys/fs/file-max")
}
pub fn set_file_max(max: usize) -> ProcResult<()> {
write_value("/proc/sys/fs/file-max", max)
}
#[derive(Debug, Clone)]
pub struct FileState {
pub allocated: u64,
pub free: u64,
pub max: u64,
}
pub fn file_nr() -> ProcResult<FileState> {
let s = read_file("/proc/sys/fs/file-nr")?;
let mut s = s.split_whitespace();
let allocated = from_str!(u64, expect!(s.next()));
let free = from_str!(u64, expect!(s.next()));
let max = from_str!(u64, expect!(s.next()));
Ok(FileState { allocated, free, max })
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dentry() {
let d = dentry_state().unwrap();
println!("{:?}", d);
}
#[test]
fn filenr() {
let f = file_nr().unwrap();
println!("{:?}", f);
}
}