此内容没有您所选择的语言版本。

15.2. Linux Memory Layout


The 4 GB address space in 32 bit x86 Linux is usually split into different sections for every process on the system:
  • 0GB-1GB User space - Used for text, code and brk/sbrk allocations. malloc uses brk for small chunks.
  • 1GB-3GB User space - Used for shared libraries, shared memory, and the stack. Shared memory and malloc use mmap. malloc uses mmap for large chunks.
  • 3GB-4GB Kernel Space - Used by and for the kernel itself
In older Linux systems the split between brk(2) and mmap(2) was changed by setting the kernel parameter TASK_UNMAPPED_BASE and by recompiling the kernel. However, on all Red Hat Enterprise Linux systems this parameter can be changed dynamically as will be shown later. The mmap allocated memory grow bottom up from 1GB and the stack grows top down from around 3GB. The split between userspace and kernelspace is set by the kernel parameter PAGE_OFFSET which is usually 0xc0000000 (3GB).
By default, in Red Hat Enterprise Linux 2.1 the address space between 0x40000000 (1 GB) and 0xc0000000 (3 GB) is available for mapping shared libraries and shared memory segments. The default mapped base for loading shared libraries is 0x40000000 (1 GB) and the SGA attach address for shared memory segments is above the shared libraries. In Oracle 9i on Red Hat Enterprise Linux 2.1 the default SGA attach address for shared memory is 0x50000000 (1.25 GB) where the SGA is mapped. This leaves 0.25 GB space for loading shared libraries between 0x40000000 (1 GB) and 0x50000000 (1.25 GB).
The address mappings of processes can be checked by viewing the proc file /proc/<pid>/maps where pid stands for the process ID. Here is an example of a default address mapping of an Oracle 9i process in Red Hat Enterprise Linux 2.1:
08048000-0ab11000 r-xp 00000000 08:09 273078 /ora/product/9.2.0/bin/oracle
0ab11000-0ab99000 rw-p 02ac8000 08:09 273078 /ora/product/9.2.0/bin/oracle
0ab99000-0ad39000 rwxp 00000000 00:00 0
40000000-40016000 r-xp 00000000 08:01 16     /lib/ld-2.2.4.so
40016000-40017000 rw-p 00015000 08:01 16     /lib/ld-2.2.4.so
40017000-40018000 rw-p 00000000 00:00 0
40018000-40019000 r-xp 00000000 08:09 17935  /ora/product/9.2.0/lib/libodmd9.so
40019000-4001a000 rw-p 00000000 08:09 17935  /ora/product/9.2.0/lib/libodmd9.so
4001a000-4001c000 r-xp 00000000 08:09 16066  /ora/product/9.2.0/lib/libskgxp9.so
...
42606000-42607000 rw-p 00009000 08:01 50     /lib/libnss_files-2.2.4.so
50000000-50400000 rw-s 00000000 00:04 163842 /SYSV00000000 (deleted)
51000000-53000000 rw-s 00000000 00:04 196611 /SYSV00000000 (deleted)
53000000-55000000 rw-s 00000000 00:04 229380 /SYSV00000000 (deleted)
...
bfffb000-c0000000 rwxp ffffc000 00:00 0
As this address mapping shows, shared libraries start at 0x40000000 (1 GB) and System V shared memory, in this case SGA, starts at 0x50000000 (1.25 GB). Here is a summary of all the entries:
The text (code) section is mapped at 0x08048000:
08048000-0ab11000 r-xp 00000000 08:09 273078  /ora/product/9.2.0/bin/oracle
The data section is mapped at 0x0ab11000:
0ab11000-0ab99000 rw-p 02ac8000 08:09 273078  /ora/product/9.2.0/bin/oracle
The uninitialized data segment .bss is allocated at 0x0ab99000:
0ab99000-0ad39000 rwxp 00000000 00:00 0
The base address for shared libraries is 0x40000000:
40000000-40016000 r-xp 00000000 08:01 16      /lib/ld-2.2.4.so
The base address for System V shared memory, in this case SGA, is 0x50000000:
50000000-50400000 rw-s 00000000 00:04 163842  /SYSV00000000 (deleted)
The stack is allocated at 0xbfffb000:
bfffb000-c0000000 rwxp ffffc000 00:00 0
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.