Skip to main content

zebrad/components/metrics/
process_memory.rs

1//! Records this process's memory use, so operators can see a node approaching its memory limit
2//! before the kernel stops it.
3
4use std::time::Duration;
5#[cfg(target_os = "linux")]
6use std::{
7    collections::HashMap,
8    path::{Component, Path, PathBuf},
9};
10
11#[cfg(target_os = "linux")]
12use crate::components::zcashd_compat::parse_self_cgroup_paths;
13
14/// How often [`record_process_memory`] samples memory use.
15///
16/// Shorter than the Prometheus scrape and Sentry flush intervals, so each one sees a recent value.
17const SAMPLE_INTERVAL: Duration = Duration::from_secs(15);
18
19/// Records this process's memory use every [`SAMPLE_INTERVAL`], until the task is aborted.
20pub async fn record_process_memory() {
21    let mut interval = tokio::time::interval(SAMPLE_INTERVAL);
22    loop {
23        interval.tick().await;
24        record();
25    }
26}
27
28/// Sets the `process.memory.rss_bytes` gauge to the resident set size of this process, and
29/// `process.memory.rss_fraction` to that size as a fraction of the memory it can use: the cgroup
30/// memory limit, or the machine's memory if no cgroup sets a lower limit.
31///
32/// Does nothing on platforms without `/proc`, or if the values can't be read.
33pub(crate) fn record() {
34    let Some(rss) = read("/proc/self/status").and_then(|status| kib_field(&status, "VmRSS:"))
35    else {
36        return;
37    };
38    // Memory sizes are far below the integers f64 represents exactly.
39    metrics::gauge!("process.memory.rss_bytes").set(rss as f64);
40
41    let machine = read("/proc/meminfo").and_then(|meminfo| kib_field(&meminfo, "MemTotal:"));
42    #[cfg(target_os = "linux")]
43    let cgroup = tightest_cgroup_limit(
44        &read("/proc/self/cgroup").unwrap_or_default(),
45        &read("/proc/self/mountinfo").unwrap_or_default(),
46        |path| std::fs::read_to_string(path).ok(),
47    );
48    #[cfg(not(target_os = "linux"))]
49    let cgroup = None;
50    if let Some(available) = available_memory(machine, cgroup) {
51        metrics::gauge!("process.memory.rss_fraction").set(rss as f64 / available as f64);
52    }
53}
54
55fn read(path: &str) -> Option<String> {
56    std::fs::read_to_string(path).ok()
57}
58
59/// Returns the value in bytes of a `name  <value> kB` line, as in `/proc/self/status` and
60/// `/proc/meminfo`.
61fn kib_field(contents: &str, name: &str) -> Option<u64> {
62    contents
63        .lines()
64        .find_map(|line| line.strip_prefix(name))?
65        .split_whitespace()
66        .next()?
67        .parse::<u64>()
68        .ok()?
69        .checked_mul(1024)
70}
71
72/// Returns the tightest memory limit on this process's cgroups, given the contents of
73/// `/proc/self/cgroup` and `/proc/self/mountinfo`.
74///
75/// A service usually runs in a nested cgroup, such as a systemd unit under `system.slice`, and any
76/// cgroup between it and the root can set the limit that applies. So this checks the process's
77/// cgroup and every ancestor visible in a mount, under both the cgroup v2 and the v1 `memory`
78/// hierarchies.
79#[cfg(target_os = "linux")]
80fn tightest_cgroup_limit(
81    self_cgroup: &str,
82    mountinfo: &str,
83    read: impl Fn(&Path) -> Option<String>,
84) -> Option<u64> {
85    let (v2_path, v1_path) = parse_self_cgroup_paths(self_cgroup);
86    let (mut v2_mounts, mut v1_mounts) = cgroup_mounts(mountinfo);
87    if v2_mounts.is_empty() && v1_mounts.is_empty() {
88        v2_mounts.push(CgroupMount::at_root("/sys/fs/cgroup"));
89        v1_mounts.push(CgroupMount::at_root("/sys/fs/cgroup/memory"));
90    }
91
92    limit_files(&v2_mounts, v2_path.as_deref(), "memory.max")
93        .into_iter()
94        .chain(limit_files(
95            &v1_mounts,
96            v1_path.as_deref(),
97            "memory.limit_in_bytes",
98        ))
99        .filter_map(|path| read(&path))
100        .filter_map(|limit| cgroup_limit(&limit))
101        .min()
102}
103
104/// A mounted cgroup hierarchy.
105#[cfg(target_os = "linux")]
106#[derive(Clone, Debug, PartialEq, Eq)]
107struct CgroupMount {
108    /// The cgroup in the hierarchy that the mount shows at its mount point. Membership paths in
109    /// `/proc/self/cgroup` are relative to the hierarchy, not to this cgroup.
110    root: PathBuf,
111    /// Where the cgroup at `root` appears in the filesystem.
112    mount_point: PathBuf,
113}
114
115#[cfg(target_os = "linux")]
116impl CgroupMount {
117    fn at_root(mount_point: &str) -> Self {
118        Self {
119            root: PathBuf::from("/"),
120            mount_point: PathBuf::from(mount_point),
121        }
122    }
123}
124
125/// Returns the cgroup v2 mounts and the cgroup v1 `memory` mounts listed in
126/// `/proc/self/mountinfo` that no other mount hides.
127#[cfg(target_os = "linux")]
128fn cgroup_mounts(mountinfo: &str) -> (Vec<CgroupMount>, Vec<CgroupMount>) {
129    /// The cgroup hierarchy a mount shows, if any.
130    enum Hierarchy {
131        V2,
132        V1Memory,
133        Other,
134    }
135
136    struct Mount {
137        id: u64,
138        parent_id: u64,
139        hierarchy: Hierarchy,
140        cgroup: CgroupMount,
141    }
142
143    let mut mounts = Vec::new();
144    for line in mountinfo.lines() {
145        // Optional fields come before the ` - ` separator, so the mount fields are counted from
146        // the start and the filesystem fields from the separator.
147        let Some((mount, filesystem)) = line.split_once(" - ") else {
148            continue;
149        };
150        let mut mount = mount.split_whitespace();
151        let (Some(id), Some(parent_id), Some(_device), Some(root), Some(mount_point)) = (
152            mount.next().and_then(|id| id.parse().ok()),
153            mount.next().and_then(|id| id.parse().ok()),
154            mount.next(),
155            mount.next(),
156            mount.next(),
157        ) else {
158            continue;
159        };
160        let mut filesystem = filesystem.split_whitespace();
161        let (Some(fs_type), Some(_source), super_options) =
162            (filesystem.next(), filesystem.next(), filesystem.next())
163        else {
164            continue;
165        };
166        let hierarchy = if fs_type == "cgroup2" {
167            Hierarchy::V2
168        } else if fs_type == "cgroup"
169            && super_options.is_some_and(|options| options.split(',').any(|o| o == "memory"))
170        {
171            Hierarchy::V1Memory
172        } else {
173            Hierarchy::Other
174        };
175
176        mounts.push(Mount {
177            id,
178            parent_id,
179            hierarchy,
180            cgroup: CgroupMount {
181                root: PathBuf::from(unescape_mountinfo(root)),
182                mount_point: PathBuf::from(unescape_mountinfo(mount_point)),
183            },
184        });
185    }
186
187    let parents: HashMap<u64, u64> = mounts
188        .iter()
189        .map(|mount| (mount.id, mount.parent_id))
190        .collect();
191    // Returns the mount that a lookup of `path` lands on, starting above the top of the mount
192    // chain `id` is on. Like the kernel, the lookup goes down one directory at a time, and at
193    // each one moves onto the last mount on that directory, repeatedly for stacked mounts. The
194    // walks are bounded by the number of mounts, in case of a parent cycle.
195    let lookup = |id: u64, path: &Path| {
196        let mut current = std::iter::successors(Some(id), |id| parents.get(id).copied())
197            .take(mounts.len() + 1)
198            .last()
199            .unwrap_or(id);
200        let mut directories: Vec<_> = path.ancestors().collect();
201        directories.reverse();
202        for directory in directories {
203            for _ in 0..mounts.len() {
204                let Some(above) = mounts.iter().rev().find(|mount| {
205                    mount.parent_id == current
206                        && mount.id != current
207                        && mount.cgroup.mount_point == directory
208                }) else {
209                    break;
210                };
211                current = above.id;
212            }
213        }
214        current
215    };
216    // A mount is hidden when another mount covers its mount point or a directory above it. Its
217    // paths would then lead into the other mount, and could read a different cgroup's limit.
218    let is_visible = |mount: &Mount| lookup(mount.id, &mount.cgroup.mount_point) == mount.id;
219
220    let mut v2 = Vec::new();
221    let mut v1_memory = Vec::new();
222    for mount in &mounts {
223        match mount.hierarchy {
224            Hierarchy::V2 if is_visible(mount) => v2.push(mount.cgroup.clone()),
225            Hierarchy::V1Memory if is_visible(mount) => v1_memory.push(mount.cgroup.clone()),
226            _ => {}
227        }
228    }
229
230    (v2, v1_memory)
231}
232
233/// Decodes the octal escapes (such as `\040` for a space) that `/proc/self/mountinfo` uses in
234/// paths.
235#[cfg(target_os = "linux")]
236fn unescape_mountinfo(field: &str) -> String {
237    let bytes = field.as_bytes();
238    let mut decoded = Vec::with_capacity(bytes.len());
239    let mut i = 0;
240    while i < bytes.len() {
241        let escape = bytes.get(i + 1..i + 4).filter(|digits| {
242            bytes[i] == b'\\' && digits.iter().all(|digit| (b'0'..=b'7').contains(digit))
243        });
244        match escape
245            .and_then(|digits| u8::from_str_radix(std::str::from_utf8(digits).ok()?, 8).ok())
246        {
247            Some(byte) => {
248                decoded.push(byte);
249                i += 4;
250            }
251            None => {
252                decoded.push(bytes[i]);
253                i += 1;
254            }
255        }
256    }
257    String::from_utf8_lossy(&decoded).into_owned()
258}
259
260/// Returns the paths of `file_name` in the cgroup at `membership` and in each of its ancestors,
261/// through every mount that shows them.
262///
263/// Mounts can overlap: a mount of a subtree shows the process's cgroup but not the ancestors above
264/// the subtree, which a broader mount of the same hierarchy may still show. So this collects the
265/// paths from every mount whose root contains the cgroup.
266///
267/// A membership path that leaves the hierarchy (`..`, seen when the cgroup is outside this cgroup
268/// namespace) only checks the mount points.
269#[cfg(target_os = "linux")]
270fn limit_files(mounts: &[CgroupMount], membership: Option<&str>, file_name: &str) -> Vec<PathBuf> {
271    let membership = Path::new(membership.unwrap_or("/"));
272    if !membership
273        .components()
274        .all(|component| matches!(component, Component::RootDir | Component::Normal(_)))
275    {
276        return mounts
277            .iter()
278            .map(|mount| mount.mount_point.join(file_name))
279            .collect();
280    }
281
282    mounts
283        .iter()
284        .filter_map(|mount| Some((mount, membership.strip_prefix(&mount.root).ok()?)))
285        .flat_map(|(mount, relative_path)| {
286            mount
287                .mount_point
288                .join(relative_path)
289                .ancestors()
290                .take_while(|dir| dir.starts_with(&mount.mount_point))
291                .map(|dir| dir.join(file_name))
292                .collect::<Vec<_>>()
293        })
294        .collect()
295}
296
297/// Returns a cgroup memory limit in bytes, or `None` if the cgroup has no limit.
298///
299/// cgroup v2 writes `max` for no limit. cgroup v1 writes a value near `i64::MAX`, which is larger
300/// than any machine's memory, so [`available_memory`] ignores it.
301fn cgroup_limit(contents: &str) -> Option<u64> {
302    contents.trim().parse().ok()
303}
304
305/// Returns the memory this process can use: the smaller of the machine's memory and the cgroup
306/// limit, ignoring values that are unknown or zero.
307fn available_memory(machine: Option<u64>, cgroup: Option<u64>) -> Option<u64> {
308    machine
309        .into_iter()
310        .chain(cgroup)
311        .filter(|bytes| *bytes > 0)
312        .min()
313}
314
315#[cfg(test)]
316mod tests {
317    use super::*;
318
319    #[test]
320    fn reads_kib_fields_as_bytes() {
321        let status = "Name:\tzebrad\nVmHWM:\t 7067912 kB\nVmRSS:\t 6886020 kB\nThreads:\t34\n";
322
323        assert_eq!(kib_field(status, "VmRSS:"), Some(6_886_020 * 1024));
324        assert_eq!(
325            kib_field("MemTotal:       8131200 kB\n", "MemTotal:"),
326            Some(8_131_200 * 1024)
327        );
328        assert_eq!(kib_field(status, "MemTotal:"), None);
329    }
330
331    #[test]
332    fn uses_the_smaller_of_the_machine_and_cgroup_limits() {
333        let gib = 1024 * 1024 * 1024;
334
335        assert_eq!(cgroup_limit("max\n"), None);
336        assert_eq!(cgroup_limit("4294967296\n"), Some(4 * gib));
337
338        assert_eq!(available_memory(Some(8 * gib), None), Some(8 * gib));
339        assert_eq!(
340            available_memory(Some(8 * gib), Some(4 * gib)),
341            Some(4 * gib)
342        );
343        // cgroup v1 reports no limit as a value near i64::MAX.
344        assert_eq!(
345            available_memory(Some(8 * gib), Some(9_223_372_036_854_771_712)),
346            Some(8 * gib)
347        );
348        assert_eq!(available_memory(None, Some(0)), None);
349    }
350
351    #[cfg(target_os = "linux")]
352    const V2_MOUNTINFO: &str =
353        "25 30 0:22 / /sys/fs/cgroup rw,nosuid shared:9 - cgroup2 cgroup2 rw,nsdelegate\n";
354
355    #[cfg(target_os = "linux")]
356    const V1_MOUNTINFO: &str = "\
357        30 25 0:26 / /sys/fs/cgroup/cpu,cpuacct rw shared:10 - cgroup cgroup rw,cpu,cpuacct\n\
358        31 25 0:27 / /sys/fs/cgroup/memory rw shared:11 - cgroup cgroup rw,memory\n";
359
360    #[cfg(target_os = "linux")]
361    #[test]
362    fn finds_cgroup_mounts_in_mountinfo() {
363        let mountinfo = "\
364            22 1 8:1 / / rw,relatime shared:1 - ext4 /dev/sda1 rw\n\
365            25 22 0:22 /tenant /mnt/tenant\\040cgroups rw shared:9 master:2 - cgroup2 cgroup2 rw\n\
366            31 22 0:27 /docker /sys/fs/cgroup/memory rw - cgroup cgroup rw,memory\n\
367            32 22 0:28 / /sys/fs/cgroup/pids rw - cgroup cgroup rw,pids\n";
368
369        let (v2, v1_memory) = cgroup_mounts(mountinfo);
370
371        assert_eq!(
372            v2,
373            vec![CgroupMount {
374                root: PathBuf::from("/tenant"),
375                mount_point: PathBuf::from("/mnt/tenant cgroups"),
376            }]
377        );
378        assert_eq!(
379            v1_memory,
380            vec![CgroupMount {
381                root: PathBuf::from("/docker"),
382                mount_point: PathBuf::from("/sys/fs/cgroup/memory"),
383            }]
384        );
385    }
386
387    #[cfg(target_os = "linux")]
388    #[test]
389    fn uses_the_mount_root_to_find_cgroups_in_a_subtree_mount() {
390        let gib: u64 = 1024 * 1024 * 1024;
391        // The mount shows the `/tenant` cgroup at `/sys/fs/cgroup`, so the process's `/tenant/zebrad`
392        // cgroup is at `/sys/fs/cgroup/zebrad`, not `/sys/fs/cgroup/tenant/zebrad`.
393        let mountinfo = "25 30 0:22 /tenant /sys/fs/cgroup rw shared:9 - cgroup2 cgroup2 rw\n";
394        let files: std::collections::HashMap<_, _> = [
395            (
396                PathBuf::from("/sys/fs/cgroup/memory.max"),
397                format!("{}\n", 8 * gib),
398            ),
399            (
400                PathBuf::from("/sys/fs/cgroup/zebrad/memory.max"),
401                format!("{}\n", 2 * gib),
402            ),
403        ]
404        .into_iter()
405        .collect();
406
407        assert_eq!(
408            tightest_cgroup_limit("0::/tenant/zebrad\n", mountinfo, |path| files
409                .get(path)
410                .cloned()),
411            Some(2 * gib)
412        );
413
414        // A cgroup outside the mounted subtree can't be seen, so it has no visible limit.
415        assert_eq!(
416            tightest_cgroup_limit("0::/other/zebrad\n", mountinfo, |path| files
417                .get(path)
418                .cloned()),
419            None
420        );
421    }
422
423    #[cfg(target_os = "linux")]
424    #[test]
425    fn uses_ancestor_limits_from_a_broader_overlapping_mount() {
426        let gib: u64 = 1024 * 1024 * 1024;
427        // The whole hierarchy is at `/sys/fs/cgroup`, and `/tenant/service` is also at
428        // `/run/service-cgroup`. Only the broader mount shows the limit on `/tenant`.
429        let mountinfo = "\
430            25 22 0:22 / /sys/fs/cgroup rw shared:9 - cgroup2 cgroup2 rw\n\
431            40 22 0:22 /tenant/service /run/service-cgroup rw shared:9 - cgroup2 cgroup2 rw\n";
432        let files: std::collections::HashMap<_, _> = [
433            ("/sys/fs/cgroup/memory.max", "max\n".to_string()),
434            ("/sys/fs/cgroup/tenant/memory.max", format!("{}\n", 2 * gib)),
435            (
436                "/sys/fs/cgroup/tenant/service/memory.max",
437                "max\n".to_string(),
438            ),
439            (
440                "/sys/fs/cgroup/tenant/service/zebrad/memory.max",
441                "max\n".to_string(),
442            ),
443            ("/run/service-cgroup/memory.max", "max\n".to_string()),
444            ("/run/service-cgroup/zebrad/memory.max", "max\n".to_string()),
445        ]
446        .into_iter()
447        .map(|(path, value)| (PathBuf::from(path), value))
448        .collect();
449
450        assert_eq!(
451            tightest_cgroup_limit("0::/tenant/service/zebrad\n", mountinfo, |path| files
452                .get(path)
453                .cloned()),
454            Some(2 * gib)
455        );
456
457        // The same applies to cgroup v1 `memory` mounts.
458        let mountinfo = "\
459            31 22 0:27 / /sys/fs/cgroup/memory rw - cgroup cgroup rw,memory\n\
460            41 22 0:27 /tenant/service /run/service-memory rw - cgroup cgroup rw,memory\n";
461        let files: std::collections::HashMap<_, _> = [(
462            PathBuf::from("/sys/fs/cgroup/memory/tenant/memory.limit_in_bytes"),
463            format!("{}\n", 2 * gib),
464        )]
465        .into_iter()
466        .collect();
467
468        assert_eq!(
469            tightest_cgroup_limit("4:memory:/tenant/service/zebrad\n", mountinfo, |path| files
470                .get(path)
471                .cloned()),
472            Some(2 * gib)
473        );
474    }
475
476    #[cfg(target_os = "linux")]
477    #[test]
478    fn ignores_cgroup_mounts_hidden_by_other_mounts() {
479        let gib: u64 = 1024 * 1024 * 1024;
480        // Mount 50 shows `/tenant` on top of mount 25, which showed the whole hierarchy at the same
481        // place. Through mount 25, `/tenant` would map to `/sys/fs/cgroup/tenant`, which is now the
482        // `/tenant/tenant` cgroup with a sibling's limit.
483        let mountinfo = "\
484            25 22 0:22 / /sys/fs/cgroup rw shared:9 - cgroup2 cgroup2 rw\n\
485            50 25 0:22 /tenant /sys/fs/cgroup rw shared:9 - cgroup2 cgroup2 rw\n";
486        let files: std::collections::HashMap<_, _> = [
487            ("/sys/fs/cgroup/memory.max", "max\n".to_string()),
488            ("/sys/fs/cgroup/tenant/memory.max", format!("{}\n", gib)),
489            ("/sys/fs/cgroup/zebrad/memory.max", format!("{}\n", 3 * gib)),
490        ]
491        .into_iter()
492        .map(|(path, value)| (PathBuf::from(path), value))
493        .collect();
494
495        assert_eq!(
496            cgroup_mounts(mountinfo).0,
497            vec![CgroupMount {
498                root: PathBuf::from("/tenant"),
499                mount_point: PathBuf::from("/sys/fs/cgroup"),
500            }]
501        );
502        assert_eq!(
503            tightest_cgroup_limit("0::/tenant/zebrad\n", mountinfo, |path| files
504                .get(path)
505                .cloned()),
506            Some(3 * gib)
507        );
508
509        // A mount on a directory above a cgroup mount hides it too, unless the cgroup mount sits on
510        // it. Mount 70 covers `/sys/fs/cgroup` after mount 31 was mounted inside it, but mount 32
511        // was mounted on mount 70 and stays visible.
512        let mountinfo = "\
513            30 22 0:25 / /sys/fs/cgroup rw - tmpfs tmpfs rw\n\
514            31 30 0:27 / /sys/fs/cgroup/memory rw - cgroup cgroup rw,memory\n\
515            70 30 0:40 / /sys/fs/cgroup rw - tmpfs tmpfs rw\n\
516            32 70 0:41 /docker /sys/fs/cgroup/memory rw - cgroup cgroup rw,memory\n";
517
518        assert_eq!(
519            cgroup_mounts(mountinfo).1,
520            vec![CgroupMount {
521                root: PathBuf::from("/docker"),
522                mount_point: PathBuf::from("/sys/fs/cgroup/memory"),
523            }]
524        );
525    }
526
527    #[cfg(target_os = "linux")]
528    #[test]
529    fn uses_the_tightest_limit_on_nested_cgroups() {
530        let gib: u64 = 1024 * 1024 * 1024;
531        let files = |entries: &[(&str, String)]| {
532            entries
533                .iter()
534                .map(|(path, value)| (PathBuf::from(path), value.clone()))
535                .collect::<std::collections::HashMap<_, _>>()
536        };
537
538        // cgroup v2: the service has no limit of its own, but its slice does.
539        let v2 = files(&[
540            ("/sys/fs/cgroup/memory.max", "max\n".into()),
541            (
542                "/sys/fs/cgroup/system.slice/memory.max",
543                format!("{}\n", 4 * gib),
544            ),
545            (
546                "/sys/fs/cgroup/system.slice/zebrad.service/memory.max",
547                "max\n".into(),
548            ),
549        ]);
550        let self_cgroup = "0::/system.slice/zebrad.service\n";
551        assert_eq!(
552            tightest_cgroup_limit(self_cgroup, V2_MOUNTINFO, |path| v2.get(path).cloned()),
553            Some(4 * gib)
554        );
555
556        // A tighter limit on the service itself wins over its slice.
557        let mut v2_service = v2.clone();
558        v2_service.insert(
559            PathBuf::from("/sys/fs/cgroup/system.slice/zebrad.service/memory.max"),
560            format!("{}\n", 2 * gib),
561        );
562        assert_eq!(
563            tightest_cgroup_limit(self_cgroup, V2_MOUNTINFO, |path| {
564                v2_service.get(path).cloned()
565            }),
566            Some(2 * gib)
567        );
568
569        // cgroup v1: the limit is on the process's `memory` cgroup, not the hierarchy root.
570        let v1 = files(&[
571            (
572                "/sys/fs/cgroup/memory/memory.limit_in_bytes",
573                "9223372036854771712\n".into(),
574            ),
575            (
576                "/sys/fs/cgroup/memory/docker/abcdef/memory.limit_in_bytes",
577                format!("{}\n", 3 * gib),
578            ),
579        ]);
580        let self_cgroup = "12:cpu,cpuacct:/docker/abcdef\n4:memory:/docker/abcdef\n";
581        assert_eq!(
582            tightest_cgroup_limit(self_cgroup, V1_MOUNTINFO, |path| v1.get(path).cloned()),
583            Some(3 * gib)
584        );
585
586        // Without readable `/proc/self/cgroup` and `/proc/self/mountinfo`, or with a cgroup outside
587        // this namespace, only the root limit is checked.
588        let root = files(&[("/sys/fs/cgroup/memory.max", format!("{}\n", 6 * gib))]);
589        assert_eq!(
590            tightest_cgroup_limit("", "", |path| root.get(path).cloned()),
591            Some(6 * gib)
592        );
593        assert_eq!(
594            limit_files(
595                &[CgroupMount::at_root("/sys/fs/cgroup")],
596                Some("/../../user.slice"),
597                "memory.max"
598            ),
599            vec![PathBuf::from("/sys/fs/cgroup/memory.max")]
600        );
601    }
602
603    #[test]
604    fn records_this_process_on_linux() {
605        if cfg!(target_os = "linux") {
606            let rss = read("/proc/self/status").and_then(|status| kib_field(&status, "VmRSS:"));
607            assert!(rss.is_some_and(|rss| rss > 0));
608        }
609    }
610}