Debian Codegraph @

src/collection/memory/arc.rs

raw symbols SCIP
1 #[cfg(all(feature = "zfs", any(target_os = "linux", target_os = "freebsd")))]
2 use superrust-analyzer cargo bottom 0.14.9 collection/memory/::MemDatarust-analyzer cargo bottom 0.14.9 collection/memory/MemData#;
3 #[cfg(all(feature = "zfs", any(target_os = "linux", target_os = "freebsd")))]
4 /// Return ARC usage.
5 pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn get_arc_usagerust-analyzer cargo bottom 0.14.9 collection/memory/arc/get_arc_usage().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(MemDatarust-analyzer cargo bottom 0.14.9 collection/memory/MemData#, u64)> {
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#;
7
8 let (mem_total, mem_used, mem_min) = {
9 cfg_selectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/cfg_select!! {
10 target_os = "linux" => {
11 // TODO: [OPT] is this efficient?
12 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().;
13 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(arc_stats) = read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().("/proc/spl/kstat/zfs/arcstats") {
14 let mut mem_arc = 0;
15 let mut mem_total = 0;
16 let mut mem_min = 0;
17 let mut zfs_keys_read: u8 = 0;
18 const ZFS_KEYS_NEEDEDrust-analyzer cargo bottom 0.14.9 collection/memory/arc/ZFS_KEYS_NEEDED.: u8 = 3;
19
20 for line in arc_stats.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
21 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((label, value)) = line.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(' ') {
22 let to_write = match label {
23 "size" => &mut mem_arc,
24 "c_max" => &mut mem_total,
25 "c_min" => &mut mem_min,
26 _ => {
27 continue;
28 }
29 };
30
31 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_type, number)) = value.trim_startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start().().rsplit_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rsplit_once().(' ') {
32 // Parse the value, remember it's in bytes!
33 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(number) = number.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<u64>() {
34 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().to_write = number;
35 // We only need a few keys, so we can bail early.
36 zfs_keys_read += 1;
37 if zfs_keys_read == ZFS_KEYS_NEEDEDrust-analyzer cargo bottom 0.14.9 collection/memory/arc/ZFS_KEYS_NEEDED. {
38 break;
39 }
40 }
41 }
42 }
43 }
44 (mem_total, mem_arc, mem_min)
45 } else {
46 (0, 0, 0)
47 }
48 }
49 target_os = "freebsd" => {
50 use sysctl::Sysctl;
51 if let (Ok(mem_arc_value), Ok(mem_sys_value), Ok(mem_min_value)) = (
52 sysctl::Ctl::new("kstat.zfs.misc.arcstats.size"),
53 sysctl::Ctl::new("kstat.zfs.misc.arcstats.c_max"),
54 sysctl::Ctl::new("kstat.zfs.misc.arcstats.c_min"),
55 ) {
56 if let (Ok(sysctl::CtlValue::U64(arc)), Ok(sysctl::CtlValue::U64(mem)), Ok(sysctl::CtlValue::U64(min))) =
57 (mem_arc_value.value(), mem_sys_value.value(), mem_min_value.value())
58 {
59 (mem, arc, min)
60 } else {
61 (0, 0, 0)
62 }
63 } else {
64 (0, 0, 0)
65 }
66 }
67 _ => {
68 (0, 0, 0)
69 }
70 }
71 };
72
73 NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new().(mem_total).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|total_bytes| {
74 (
75 MemDatarust-analyzer cargo bottom 0.14.9 collection/memory/MemData# {
76 total_bytesrust-analyzer cargo bottom 0.14.9 collection/memory/MemData#total_bytes.,
77 used_bytesrust-analyzer cargo bottom 0.14.9 collection/memory/MemData#used_bytes.: mem_used,
78 },
79 mem_min,
80 )
81 })
82 }