/proc/$pid/maps shows pages with no rwx permission

2019-01-17 17:48发布

/proc/$pid/maps shows pages with no rwx permissions on x86_64 linux. I noticed that when I read /proc/$pid/maps at 64bit linux I have memory pages that have no permissions, but in a 32bit linux, they aren't there.

I’m trying to monitor the memory usage of my process, but Im confused. Why are there pages with no rwx privileges. They are consuming my memory!

This is a snippet of the output of a 64bit linux for ‘top’

% cat /proc/21367/maps

3154200000-315420d000 r-xp 00000000 fd:00 4835776 /lib64/libproc-3.2.7.so <br/>
315420d000-315440d000 **---p** 0000d000 fd:00 4835776 /lib64/libproc-3.2.7.so <br/>
315440d000-315440e000 rw-p 0000d000 fd:00 4835776 /lib64/libproc-3.2.7.so

please advise.

1条回答
2楼-- · 2019-01-17 18:46

These mappings are used for shared libraries:

In general for each shared library loaded we will have four mappings:

3b7cc00000-3b7cd86000 r-xp 00000000 fd:00 661350            /lib64/libc-2.12.so
3b7cd86000-3b7cf86000 ---p 00186000 fd:00 661350            /lib64/libc-2.12.so
3b7cf86000-3b7cf8a000 r--p 00186000 fd:00 661350            /lib64/libc-2.12.so
3b7cf8a000-3b7cf8b000 rw-p 0018a000 fd:00 661350            /lib64/libc-2.12.so

The first one is the code segment with executable permissions, the second one the PROT_NONE (no permissions) mapping, and the last two ones the data segment (read only part and read write).

The PROT_NONE mappings are created to do with keeping libraries efficiently sharable and to mark guard pages so buffer overflows can be catched.

Just keep in mind that these mappings are only using part of the virtual address space but they are not actually consuming the systems memory.

Here you can find a complete explanation:

http://www.greenend.org.uk/rjk/tech/dataseg.html

查看更多
登录 后发表回答