How to obtain the number of mapped memory regions (mm_struct->map_count) from userspace
Asked Answered
C

0

6

I'd like add the number of mapped memory regions to the status report of my daemon.

There's a number of reasons why you may want this:

  1. There's a limit for that (vm.max_map_count) so it's good to monitor the current value.
  2. A growing number may be a sign of an allocator bug resulting in unnecessary virtual memory fragmentation.
  3. A growing number may be a sign of leaking file mappings. They don't necessarily result in growing RSS and may not trigger an OOM. However, they pollute the VMA tree and may exceed max_map_count limit.

The question is: what it is the best way to get this number from the inside of your process?

One way is to count lines in /prof/self/map but it doesn't look optimal. Neither I want to parse a 10K lines text file to obtain a single integer nor the kernel needs to materialize the whole buffer each time.

There's already a counter in the kernel (mm_struct->map_count) so I'd expect it to be present somewhere in /proc/self/* but cannot actually find it. Any ideas?

Crematorium answered 18/10, 2018 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.