linuxmemory-managementaddress-space

global or local linear address space in Linux?


In linux, because the bases of segments are all 0, so the logical address coincide with the linear address (Book "Understanding the linux kernel"). I think the logical address of different process may be the same, so the linear address of different process may be the same and as each process view 4GB, each process will have its own linear address space (local address space). But some other articles says there is a large linear address space shared by all process, and the segment mechanism is used to map different process into different part of the linear address space. Sounds like a global linear address space with wider address bits. Where am I wrong? Or they are used in different architecture?


Solution

  • Each Linux process has its own address space; it is virtual memory. Different processes have different address spaces (but all the threads inside a process share the same address space).

    You can get a map of process 1234 on Linux by reading /proc/1234/maps or from inside the process /proc/self/maps

    Try the following commands

     cat /proc/$$/maps
     cat /proc/self/maps
    

    and think about their output; the first command shows the memory map of your shell; the second one shows the memory map of the process running cat

    The address space is set with execve(2) at program startup and changed with the mmap(2) and related syscalls.

    An application interact with the kernel only thru syscalls. The kernel has a "different" address space, which you should not care about (unless you are coding inside the kernel).

    Read also a good book like Advanced Unix Programming and/or Advanced Linux Programming

    See also this explanation on syscalls.

    Notice that segmented addressing is specific to i386 and is obsolete: most systems don't use it anymore. It has completely disappeared in 64 bits mode of x86-64. All Linux systems use a flat memory model

    Please read carefully all the references.