了解Linux / proc / id / maps [英] Understanding Linux /proc/id/maps
问题描述
proc / pid / maps实用程序/文件是否有一个很好的资源/文档?
匿名inode 0条目是什么意思?这些似乎是一些较大的内存段。
/ proc / $ PID中的每一行/ maps
描述进程或线程中连续虚拟内存的区域。每行都有以下字段:
address perms offset dev inode pathname
08048000-08056000 r-xp 00000000 03: 0c 64593 / usr / sbin / gpm
- strong> - 这是进程地址空间中的区域的起始和结束地址
- 权限 - 这将描述如何访问该区域的页面。有四种不同的权限:读取,写入,执行和共享。如果读/写/执行被禁用,将出现' - '而不是'r'/'w'/'x'。如果一个区域不是共享的,它是私有的,所以'p'将会出现,而不是's'。如果进程尝试以不允许的方式访问内存,则会生成分段错误。权限可以使用
mprotect
系统调用更改。 - 偏移量 - 如果区域从文件(使用
mmap
),这是映射开始的文件中的偏移量。如果内存没有从文件映射,则只是0。 - 设备 - 如果区域是从文件映射的,这是主要和次要设备
- inode - 如果区域是从文件映射的,则是文件号。
- 路径名 - 如果区域是从文件映射的,则是文件的名称。匿名映射区域的该字段为空。还有一些特殊区域,名称如
[heap]
,[stack]
或VDSO]
。[vdso]
代表虚拟动态共享对象。系统调用用于切换到内核模式。 这是一篇很好的文章。
您可能会注意到很多匿名地区。这些通常由 mmap
创建,但不附加到任何文件。它们用于许多杂项,例如共享内存或未分配在堆上的缓冲区。例如,我认为pthread库使用匿名映射区域作为新线程的堆栈。
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.
Each row in /proc/$PID/maps
describes a region of contiguous virtual memory in a process or thread. Each row has the following fields:
address perms offset dev inode pathname
08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm
- address - This is the starting and ending address of the region in the process's address space
- permissions - This describes how pages in the region can be accessed. There are four different permissions: read, write, execute, and shared. If read/write/execute are disabled, a '-' will appear instead of the 'r'/'w'/'x'. If a region is not shared, it is private, so a 'p' will appear instead of an 's'. If the process attempts to access memory in a way that is not permitted, a segmentation fault is generated. Permissions can be changed using the
mprotect
system call. - offset - If the region was mapped from a file (using
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. - device - If the region was mapped from a file, this is the major and minor device number (in hex) where the file lives.
- inode - If the region was mapped from a file, this is the file number.
- pathname - If the region was mapped from a file, this is the name of the file. This field is blank for anonymous mapped regions. There are also special regions with names like
[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.
这篇关于了解Linux / proc / id / maps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!