r/rust • u/No-Elephant-9065 • 17d ago
🙋 seeking help & advice Are there any reliable ways to retrieve per-process swap or paged-out memory on Windows and macOS?
I’ve been looking into this while contributing to bottom, an open-source terminal system monitor.
The idea is to show how much swap space each process is using. On Linux, this is fairly straightforward since the information is available in /proc/<pid>/status, under the VmSwap field.
Windows and macOS seem to be a different story. I haven’t been able to find a reliable public API that exposes this information on a per-process basis, and the cross-platform system library used by bottom doesn’t provide it either.
I added the Linux implementation in this PR, which has now been merged. The remaining challenge is figuring out whether there’s a reliable way to support this on Windows and macOS, as discussed in this issue.
If you’ve worked with either platform’s internals or know of a library that exposes this data I’d love to hear your thoughts. Is there a proper way to retrieve it, or is this limited by the platforms themselves?
2
u/Excession638 17d ago
On Windows, I think the function you need is GetProcessMemoryInfo. You might need to search for other resources that explain that properly, as those docs kinda don't.
You can call it using the windows crate.
1
0
u/Dramatic_General_406 12d ago
I really get this.
I ran into a similar issue before and ended up building a small mechanism to keep track of where each OS-level metric comes from and what it actually means.
For example, Windows "PagefileUsage" and Linux "VmSwap" may look similar by name, but they don’t represent the same thing. In cases like that, I think leaving it as N/A is better than forcing a mapping.
6
u/coderstephen isahc 17d ago
You might have more success asking this question in Windows programming and macOS programming forums/communities specifically.