了解 Linux /proc/id/maps

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1401359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:40:50  来源:igfitidea点击:

Understanding Linux /proc/id/maps

linuxembedded

提问by simon

I am trying to understand my embedded Linux application's memory use. The /proc/pid/mapsutility/file seems to be a good resource for seeing the details. Unfortunately I don't understand all the columns and entries.

我试图了解我的嵌入式 Linux 应用程序的内存使用情况。该/proc/pid/maps实用程序/文件似乎是看到细节的好资源。不幸的是,我不明白所有的列和条目。

What does the anonymous inode 0 entries mean? These seem to be some of the larger memory segments.

匿名 inode 0 条目是什么意思?这些似乎是一些较大的内存段。

采纳答案by Jay Conrod

Each row in /proc/$PID/mapsdescribes a region of contiguous virtual memory in a process or thread. Each row has the following fields:

中的每一行/proc/$PID/maps描述了进程或线程中的一个连续虚拟内存区域。每行具有以下字段:

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 pwill 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 mprotectsystem 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: "What is linux-gate.so.1?"
  • address- 这是进程地址空间中区域的起始地址和结束地址
  • 权限- 这描述了如何访问该区域中的页面。有四种不同的权限:读取、写入、执行和共享。如果读/写/执行是禁用,-会出现,而不是r/ w/ x。如果区域未共享,则它是私有的,因此p将出现 a 而不是s。如果进程尝试以不允许的方式访问内存,则会生成分段错误。可以使用mprotect系统调用更改权限。
  • offset- 如果区域是从文件映射的(使用mmap),则这是映射开始的文件中的偏移量。如果内存不是从文件映射的,则它只是 0。
  • device- 如果区域是从文件映射的,则这是文件所在的主要和次要设备号(以十六进制表示)。
  • inode- 如果区域是从文件映射的,则这是文件编号。
  • 路径名- 如果区域是从文件映射的,则这是文件的名称。对于匿名映射区域,此字段为空。还有一些特殊区域的名称,如[heap][stack]、 或[vdso][vdso]代表虚拟动态共享对象。系统调用使用它来切换到内核模式。这是一篇关于它的好文章:“什么是 linux-gate.so.1?”

You might notice a lot of anonymous regions. These are usually created by mmapbut 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.

您可能会注意到许多匿名区域。这些通常由mmap任何文件创建但不附加到任何文件。它们用于许多杂项,例如共享内存或未在堆上分配的缓冲区。例如,我认为 pthread 库使用匿名映射区域作为新线程的堆栈。

回答by Xeor

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

内存映射不仅用于将文件映射到内存中,而且还是从内核请求 RAM 的工具。这些是 inode 0 条目 - 您的堆栈、堆、bss 段等等

回答by cahit beyaz

Please check: http://man7.org/linux/man-pages/man5/proc.5.html

请检查:http: //man7.org/linux/man-pages/man5/proc.5.html

address           perms offset  dev   inode       pathname
00400000-00452000 r-xp 00000000 08:02 173521      /usr/bin/dbus-daemon

The address field is the address space in the process that the mapping occupies.

地址字段是映射占用的进程中的地址空间。

The perms field is a set of permissions:

perms 字段是一组权限:

 r = read
 w = write
 x = execute
 s = shared
 p = private (copy on write)

The offset field is the offset into the file/whatever;

offset 字段是文件/任何内容的偏移量;

dev is the device (major:minor);

dev 是设备(主要:次要);

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).

inode 是该设备上的 inode。0 表示没有 inode 与内存区域相关联,就像 BSS(未初始化数据)的情况一样。

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).

路径名字段通常是支持映射的文件。对于 ELF 文件,您可以通过查看 ELF 程序头 (readelf -l) 中的 Offset 字段轻松地与 offset 字段进行协调。

Under Linux 2.0, there is no field giving pathname.

在 Linux 2.0 下,没有给出路径名的字段。