How to accout max_rss precisely

杨贺然 herany1999 at gmail.com
Sat Jun 1 03:01:32 EDT 2024


Hi,

I'm working on a utility to report the maximum memory usage of a certain
program. I intend to show the max_rss of this process and its children, but
it's hard to use getrusage to get the RSS precisely, so I'm trying to
leverage cgroups.

However on the document of cgroups v2, `memory.peak` says: The max memory
usage recorded for the cgroup and its descendants since the creation of the
cgroup. It didn't explain the composition of memory usage. So I want to ask
that is the memory usage in `memory.peak` the maximum of RSS? I made a
quick test on an empty program like:

```c
// a.c
int main() {}
```

It shows that `memory.peak` of this program is ~500KiB, which does not make
sense to me.

I also wonder how to implement the same function under OS without cgroups,
like BSD and macOS.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20240601/21887bfd/attachment.html>


More information about the Kernelnewbies mailing list