I am trying to understand my embedded Linux application's memory use. The /proc/pid/maps
utility/file seems to be a good resource for seeing the details. Unfortunately I don't understand all the columns and entries.
Is there a good resource/documentation for the proc/pid/maps
utility/file?
What does the anonymous inode 0 entries mean? These seem to be some of the larger memory segments.
Please check: http://man7.org/linux/man-pages/man5/proc.5.html
The address field is the address space in the process that the mapping occupies.
The perms field is a set of permissions:
The offset field is the offset into the file/whatever;
dev is the device (major:minor);
inode is the inode on that device.0 indicates that no inode is associated with the memoryregion, as would be the case with BSS (uninitialized data).
The pathname field will usually be the file that is backing the mapping. For ELF files, you can easily coordinate with the offset field by looking at the Offset field in the ELF program headers (readelf -l).
Under Linux 2.0, there is no field giving pathname.
Each row in
/proc/$PID/maps
describes a region of contiguous virtual memory in a process or thread. Each row has the following fields:-
will appear instead of ther
/w
/x
. If a region is not shared, it is private, so ap
will appear instead of ans
. If the process attempts to access memory in a way that is not permitted, a segmentation fault is generated. Permissions can be changed using themprotect
system call.mmap
), this is the offset in the file where the mapping begins. If the memory was not mapped from a file, it's just 0.[heap]
,[stack]
, or[vdso]
.[vdso]
stands for virtual dynamic shared object. It's used by system calls to switch to kernel mode. Here's a good article about it.You might notice a lot of anonymous regions. These are usually created by
mmap
but are not attached to any file. They are used for a lot of miscellaneous things like shared memory or buffers not allocated on the heap. For instance, I think the pthread library uses anonymous mapped regions as stacks for new threads.proc(5)
mmap(2)
"Understanding the Linux Kernel" 9.3. Memory Regions; 16.2. Memory Mapping
"Understanding the Linux Virtual Memory Manager" 4.4 Memory Regions
memory mapping is not only used to map files into memory but is also a tool to request RAM from kernel. These are those inode 0 entries - your stack, heap, bss segments and more