classic memory layout&…
来源:互联网 发布:局域网涉及的网络协议 编辑:程序博客网 时间:2024/04/29 17:24
先写个概要吧。
本文阐述了 经典的虚拟内存布局 和 易变虚拟内存布局;
上图,有图一切都明白了。
flexible memory layout:
classic memory layout:
易变虚拟内存布局就是在各个虚拟内存区中引用随机的偏移量。从而使Hacker很难猜测出函数库,映射文件等等的位置。从而一定程度上使程序得到保护,但是32位系统用户空间的狭小,削弱了这种效果。
我们也可以从这个patch的原作者的mail中得到一些有用的信息:
http://lwn.net/Articles/90311/
the goal of the patch is to change the way virtual memory isallocated,
from:
//传统虚拟内存布局
0x08000000 ... binary image
0x08xxxxxx ... brk area, grows upwards
0x40000000 ... start of mmap, new mmaps go afteroldones//从1G开始 向上增长,这导致了一个问题,无法完全利用虚拟内存空间。
0xbfxxxxxx ... stack
to a more flexible top-down mmap() method:
//易变虚拟内存布局
0x08000000 ... binary image
0x08xxxxxx ... brk area, grows upwards
0xbfxxxxxx ... _end_ of all mmaps, new mmaps gobelow old ones//从stack+randomoffset开始 向下增长,可以用满虚拟内存空间
0xbfyyyyyy ... stack
the new layout has a couple of advantages:
- primarily this layout enables both malloc(), mmap()/shmat() usersto
utilize the full address space: 3GB on stockx86, 4GB on x86 4:4 or
x86-64 running x86 apps.
- the new layout is also in essence 'self-tuning' the mmap()and
malloc() limits: no hacks like/proc/PID/mmap_base are needed - both
malloc() and mmap() can grow until all theaddress space is full.
With the old layout, malloc() space was limitedto 900MB, mmap() space
to ~2GB.
- The new layout also allows very large continuous mmap()s becausethe
'free space' is always a continuous hole(statistically).
- there's also a ~4K pagetable saved per typical process, becausewe
dont allocate at 1GB anymore and dont fragmentthe VM that much -
there are only 2 main chunks, the binary image +brk(), and the mmap()
area + stack.
以上为flexible memroy layout 输出结果。可以与上图对比着看一下
内核的/proc文件系统也提供了相应的控制接口,来确定使用哪种虚拟内存布局
from:
//传统虚拟内存布局
to a more flexible top-down mmap() method:
//易变虚拟内存布局
the new layout has a couple of advantages:
- primarily this layout enables both malloc(), mmap()/shmat() usersto
- the new layout is also in essence 'self-tuning' the mmap()and
- The new layout also allows very large continuous mmap()s becausethe
- there's also a ~4K pagetable saved per typical process, becausewe
- [root@localhoststudy]#
pmap -x1 - 1:
init [3] - Address Kbytes RSS Dirty Mode Mapping
- 002e7000 4 4 0 r-x--
[ anon ] - 00469000 104 84 0 r-x--
ld-2.5.so - 00483000 4 4 4 r-x--
ld-2.5.so - 00484000 4 4 4 rwx--
ld-2.5.so - 00487000 1276 356 0 r-x--
libc-2.5.so - 005c6000 4 0 0
--x-- libc-2.5.so - 005c7000 8 8 4 r-x--
libc-2.5.so - 005c9000 4 4 4 rwx--
libc-2.5.so - 005ca000 12 12 12 rwx--
[ anon ] - 005f8000 8 8 0 r-x--
libdl-2.5.so - 005fa000 4 4 4 r-x--
libdl-2.5.so - 005fb000 4 4 4 rwx--
libdl-2.5.so - 00638000 88 40 0 r-x--
libselinux.so.1 - 0064e000 8 8 8 rwx--
libselinux.so.1 - 00652000 236 16 0 r-x--
libsepol.so.1 - 0068d000 4 4 4 rwx--
libsepol.so.1 - 0068e000 40 0 0 rwx--
[ anon ] - 08048000 32 32 0 r-x--
init - 08050000 4 4 4 rw---
init - 098db000 132 16 16 rw---
[ anon ] - b7f32000 8 8 8 rw---
[ anon ] - bfc07000 84 16 16 rw---
[ stack ] - --------
------- ------- ------- ------- - total kB 2072
- - - - [root@localhoststudy]#
cat /proc/1/maps - 002e7000-002e8000r-xp 002e700000:000
[vdso] - 00469000-00483000r-xp 0000000008:031182164
/lib/ld-2.5.so - 00483000-00484000r-xp 0001900008:031182164
/lib/ld-2.5.so - 00484000-00485000rwxp 0001a000 08:031182164
/lib/ld-2.5.so - 00487000-005c6000r-xp 0000000008:031182165
/lib/libc-2.5.so - 005c6000-005c7000
--xp0013f000 08:031182165 /lib/libc-2.5.so - 005c7000-005c9000r-xp 0013f00008:031182165
/lib/libc-2.5.so - 005c9000-005ca000rwxp 00141000 08:031182165
/lib/libc-2.5.so - 005ca000-005cd000rwxp 005ca000 00:000
- 005f8000-005fa000r-xp 0000000008:031182169
/lib/libdl-2.5.so - 005fa000-005fb000r-xp 0000100008:031182169
/lib/libdl-2.5.so - 005fb000-005fc000rwxp 00002000 08:031182169
/lib/libdl-2.5.so - 00638000-0064e000r-xp 0000000008:031182183
/lib/libselinux.so.1 - 0064e000-00650000rwxp 00015000 08:031182183
/lib/libselinux.so.1 - 00652000-0068d000r-xp 0000000008:031182182
/lib/libsepol.so.1 - 0068d000-0068e000rwxp 0003b000 08:031182182
/lib/libsepol.so.1 - 0068e000-00698000rwxp 0068e000 00:000
- 08048000-08050000r-xp 0000000008:03884969
/sbin/init - 08050000-08051000rw-p 0000800008:03884969
/sbin/init - 098db000-098fc000rw-p 098db00000:000
[heap] - b7f32000-b7f34000rw-p b7f3200000:000
- bfc07000-bfc1c000rw-p bffea00000:000
[stack]
内核的/proc文件系统也提供了相应的控制接口,来确定使用哪种虚拟内存布局
echo 1 > /proc/sys/vm/legacy_va_layout
1 使用传统虚拟内存布局
0 使用易变虚拟内存布局
0 0
- classic memory layout&…
- classic memory layout&…
- shared memory realm&nb…
- weibo 登录&nbsp…
- Android edittext&nbsp…
- !!! FAILED BINDER&nbsp…
- OGNL & ValueStack&…
- classic memory layout & flexible memory layout
- Javascript_DOMContentLoaded&nbsp…
- ApplicationEventMulticaster&nbsp…
- LA 5713 Qin&nbsp…
- Convex Hull Algorithms & general…
- ORACLE:shared memory realm does …
- Media Player Classic播放文件时没…
- google desktop search&…
- Running Health Checks&…
- script for Tablespace&…
- Note 452067.1 &n…
- uboot SPL Overview
- uboot SPL Overview
- git如何获取标签下的代码
- git如何获取标签下的代码
- classic memory layout&…
- classic memory layout&…
- linux 内核与用户空间通信之n…
- linux 内核与用户空间通信之n…
- oracel 多行 字符串 合为一行
- Android Vold架构
- Android Vold架构
- Linux设备驱动子系统第二弹 - SD卡
- Linux设备驱动子系统第二弹 - SD卡
- android中编译资源文件的相关问题