[Linux] Process (10)--Process address space

Source: Internet
Author: User

1, the virtual memory of the process:

Background knowledge
A.out segment and run time memory structure Click to open the link

Linux Process address space

Linux Process address space

\

[CPP]View Plaincopy
    1. struct mm_struct {    
    2.         struct vm_ area_struct  *mmap;                /* LIST OF MEMORY AREAS */  
    3.         struct  rb_root         mm_rb;                /* red-black tree of  vmas */  
    4.          ...   
    5. }  

Mmap and MM_RB Two different data structures describe the same object, which describes the entire memory area of the address space (struct vm_area_struct), but the former in the form of a list, the latter in the form of red and black trees, the list of advantages is that can efficiently traverse all elements, The red and black trees are more suitable for searching for the specified element. The first element of the MM_STRUCT structure is the INIT_MM memory descriptor, which represents the address space of the INIT process. There is a mm field in the process descriptor task_struct, where the memory descriptor used by the process is stored, through current-> MM can point to the memory descriptor of the current process

The kernel thread does not have an address space, so the member in task_struct in the kernel thread is empty. When the kernel is dispatched, the address space of the previous process is preserved if the Mm_struct area is found to be empty

The memory area is represented by the VM_AREA_STRUCT structure, which describes a separate memory range for contiguous space within the specified address space. The kernel manages each memory region as a separate memory object, with consistent attributes for each memory object, such as access permissions, etc.

All areas of the address space of each process can be viewed through the output of the/proc/<pid>/maps, with the format input for each row

Start-end access right offset main device number: Secondary device number I node file

Mmap () and Do_mmap () functions
The kernel uses the Do_mmap () function to create a new address space, and if the address space created is adjacent to an already existing address space and the properties are the same, then two intervals are merged into one. The Do_mmap () function adds an address space to the address space of the process

[CPP]View Plaincopy
    1. struct Mm_struct {
    2. pgd_t *PGD; / * Page Global directory * /
    3. 。。。。。。。。
    4. }

Page tables are used to transform virtual addresses to physical addresses, and each process's memory descriptor has its own page table, which is pointed to by the PGD member in the mm_struct struct.

[Linux] Process (10)--Process address space

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.