Memory accounting
Accounting for the memory used by your system and processes can be useful, especially when debugging. This section covers examples of how to read memory-related files and calculate reserved memory.
The actual calculations you perform will depend on your needs, and, due to the varying nature of different types of mapping, may be complex. The process counters discussed in this section provide a general value that represents reserved memory. To get an accurate value, you need to perform more complicated calculations using the raw information found in the memory manager.
- The /proc/vm/stats file allows you to display system-wide
statistics. For example:
For details, go tocat /proc/vm/statsSystem counters.
- For process totals, display the contents of /proc/pid/vmstat,
where pid is the process ID. For
example:
For details, go tocat /proc/pid/vmstatProcess counters.
- The /proc/pid/pmap file provides a
detailed look at memory regions. You can add up selected parameters in the
file's output to find out how much memory is reserved for a process. For
example:
For more information, go tocat /proc/pid/pmapMemory reservation from reading the pmap file
andThe pmap parameters.
- The /proc/pid/mappings file has detailed
mapping information for each page in your process. For
example:
For more information, go tocat /proc/pid/mappingsThe mappings file.
Alternatively, you can use the code snippets provided in Using C library APIs to calculate memory reservations
to determine how much private and shared
memory your process is using.
Terminology
The following terminology is used for this discussion of memory accounting:
- Anonymous
- Used to refer to memory that is not associated with an explicit object. Anonymous memory can come from anywhere in RAM and is zero-initialized when allocated.
- Domain
- A collection of contiguous ranges of physical memory that serve a particular type of allocation (single page, multi-page, kernel).
- Map
- A structure that is used to construct the page table entry for each page in the address space.
- Page
-
A fixed-length contiguous block of memory. The QNX OS process manager allocates memory in pages (typically 4 KB each).
- Region
- A region is a sub-range of a process's address space. It is the result of a mmap() call. The pages in a region all share the same backing object, protection bits, and flags.
