Process address space-Data Structure

Source: Internet
Author: User

The process description structure task_struct contains the following members:

        struct mm_struct *mm, *active_mm;

Each process descriptor includes mm and active _ mm. The mm Member points to the memory descriptor owned by the process, while active_mm points to the memory descriptor currently being executed.

For common processes, the two are the same, but there is no memory descriptor for the kernel thread, mm is empty, and active_mm is the mm of the previous execution process.

Mm_struct

This structure stores the memory management information of processes.

156 struct mm_struct {157         struct vm_area_struct * mmap;           /* list of VMAs */158         struct rb_root mm_rb;159         struct vm_area_struct * mmap_cache;     /* last find_vma result */160         unsigned long (*get_unmapped_area) (struct file *filp,161                                 unsigned long addr, unsigned long len,162                                 unsigned long pgoff, unsigned long flags);163         void (*unmap_area) (struct mm_struct *mm, unsigned long addr);164         unsigned long mmap_base;                /* base of mmap area */165         unsigned long task_size;                /* size of task vm space */166         unsigned long cached_hole_size;         /* if non-zero, the largest hole below free_area_cache */167         unsigned long free_area_cache;          /* first hole of size cached_hole_size or larger */168         pgd_t * pgd;169         atomic_t mm_users;                      /* How many users with user space? */170         atomic_t mm_count;                      /* How many references to "struct mm_struct" (users count as 1) */171         int map_count;                          /* number of VMAs */172         struct rw_semaphore mmap_sem;173         spinlock_t page_table_lock;             /* Protects page tables and some counters */174 175         struct list_head mmlist;                /* List of maybe swapped mm's.  These are globally strung176                                                  * together off init_mm.mmlist, and are protected177                                                  * by mmlist_lock178                                                  */179 180         /* Special counters, in some configurations protected by the181          * page_table_lock, in other configurations by being atomic.182          */183         mm_counter_t _file_rss;184         mm_counter_t _anon_rss;185 186         unsigned long hiwater_rss;      /* High-watermark of RSS usage */187         unsigned long hiwater_vm;       /* High-water virtual memory usage */188 189         unsigned long total_vm, locked_vm, shared_vm, exec_vm;190         unsigned long stack_vm, reserved_vm, def_flags, nr_ptes;191         unsigned long start_code, end_code, start_data, end_data;192         unsigned long start_brk, brk, start_stack;193         unsigned long arg_start, arg_end, env_start, env_end;194 195         unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */196 197         cpumask_t cpu_vm_mask;198 199         /* Architecture-specific MM context */200         mm_context_t context;201 202         /* Swap token stuff */203         /*204          * Last value of global fault stamp as seen by this process.205          * In other words, this value gives an indication of how long206          * it has been since this task got the token.207          * Look at mm/thrash.c208          */209         unsigned int faultstamp;210         unsigned int token_priority;211         unsigned int last_interval;212 213         unsigned long flags; /* Must use atomic bitops to access the bits */214 215         /* coredumping support */216         int core_waiters;217         struct completion *core_startup_done, core_done;218 219         /* aio bits */220         rwlock_t                ioctx_list_lock;221         struct kioctx           *ioctx_list;222 };

Description of memory layout information:

Mem_base: the region used for address ing in the virtual address space. In the early stage, MMAP increased from mem_base and eventually joined the stack. A new layout is introduced, MMAP can grow down from mem_base, and eventually match with each other.

Start_code, end_code defines the start address and end address of the Code. Start_code and end_code do not change in the process lifecycle.

Start_data, end_data defines the start address and end address of the initialized data zone. Start_data and end_data do not change in the process lifecycle.

Start_brk, BRK defines the starting and ending addresses of the heap region. start_brk does not change in the process lifecycle, and the BRK changes with the increase and decrease of the heap.

Arg_start, arg_end stores the parameter list, which is located in the highest address area on the stack.

Env_start and env_end are used to save environment variables, which are located in the highest address area in the stack.

Task_size: the length of the process's address space, excluding the kernel part.

Get_unmapped_area: This function searches for the process address space and finds an available linear address area. This function can be divided into two situations: File Memory ing and anonymous memory ing.

The memory area of the virtual address space:

MMAP: Virtual Memory zone single-chain table. All virtual memory zones of a process are linked to this single-chain table.

Mm_rb: Root Node of the red/black tree in the virtual memory area.

Map_cache: The last fina_vma query result. According to the locality theory, the next access may also happen in this region.

Map_count: Number of memory ing areas. The maximum number is sysctl_max_map_count, 65536

Virtual memory usage statistics

RSS: Number of physical page boxes allocated to processes. Also known as the number of resident memory.

Anon_rss: Number of anonymous memory ing page boxes allocated to processes

Total_vm: Number of address space pages used by the process. The total number is the number of virtual memory. This number should be the VSS column in the ps command.

Locked_vm: Number of virtual memory pages locked by calling the mlock system. Once mapped, these pages cannot be exchanged. Note that this number is the number of virtual address pages, not the number of physical pages.

Shared_vm: the number of virtual memory mapped to file sharing. This number is counted as long as it is a file ing.

Exec_vm: if the memory ing is a file ing and an executable part, count this value.

Stack_vm: the virtual page size of the process stack space. The initial value is 1 page. Expanding the stack will increase the stack_vm.

Reserved_vm:

Other members

PGD: page table of the current process

Mm_users: indicates the number of threads using this mm structure. For example, if two threads use this structure, the value is 2.

Mm_count: The Use count of the MM structure. If the value is 0, no user is available and can be released. Because the MM structure may be borrowed by the kernel thread, in order to ensure that it will not be released during the borrow period, the mm_count will be added to 1. In addition, the MM thread shares a usage count, that is to say, if the value of mm_users is greater than 1, only the value of mm_count is increased by 1.

Mmlist: All mm instances are linked to a two-way linked list and linked together through mmlist. One node of this list is init_mm.mmlist, that is, the memory descriptor of process 0.

Mmlist_lock: used to protect the spin lock of mmlist

Vm_area_struct

Kernel uses vm_area_struct to represent a memory area

 93 /* 94  * This struct defines a memory VMM memory area. There is one of these 95  * per VM-area/task.  A VM area is any part of the process virtual memory 96  * space that has a special rule for the page-fault handlers (ie a shared 97  * library, the executable area etc). 98  */ 99 struct vm_area_struct {100         struct mm_struct * vm_mm;       /* The address space we belong to. */101         unsigned long vm_start;         /* Our start address within vm_mm. */102         unsigned long vm_end;           /* The first byte after our end address103                                            within vm_mm. */104 105         /* linked list of VM areas per task, sorted by address */106         struct vm_area_struct *vm_next;107 108         pgprot_t vm_page_prot;          /* Access permissions of this VMA. */109         unsigned long vm_flags;         /* Flags, listed below. */110 111         struct rb_node vm_rb;112 113         /*114          * For areas with an address space and backing store,115          * linkage into the address_space->i_mmap prio tree, or116          * linkage to the list of like vmas hanging off its node, or117          * linkage of vma in the address_space->i_mmap_nonlinear list.118          */119         union {120                 struct {121                         struct list_head list;122                         void *parent;   /* aligns with prio_tree_node parent */123                         struct vm_area_struct *head;124                 } vm_set;125 126                 struct raw_prio_tree_node prio_tree_node;127         } shared;128 129         /*130          * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma131          * list, after a COW of one of the file pages.  A MAP_SHARED vma132          * can only be in the i_mmap tree.  An anonymous MAP_PRIVATE, stack133          * or brk vma (with NULL file) can only be in an anon_vma list.134          */135         struct list_head anon_vma_node; /* Serialized by anon_vma->lock */136         struct anon_vma *anon_vma;      /* Serialized by page_table_lock */137 138         /* Function pointers to deal with this struct. */139         struct vm_operations_struct * vm_ops;140 141         /* Information about our backing store: */142         unsigned long vm_pgoff;         /* Offset (within vm_file) in PAGE_SIZE143                                            units, *not* PAGE_CACHE_SIZE */144         struct file * vm_file;          /* File we map to (can be NULL). */145         void * vm_private_data;         /* was vm_pte (shared mem) */146         unsigned long vm_truncate_count;/* truncate_count or restart_addr */147 148 #ifndef CONFIG_MMU149         atomic_t vm_usage;              /* refcount (VMAs shared if !MMU) */150 #endif151 #ifdef CONFIG_NUMA152         struct mempolicy *vm_policy;    /* NUMA policy for the VMA */153 #endif154 };

Vm_mm: The address space of the memory area

Vm_start: Start address in the memory address space

Vm_end: end address of the address space in the memory Zone

Vm_next: The process address space contains a single-chain table of memory areas. All memory areas are linked through this single-chain table. The header is mm-> MMAP.

Vm_page_prot: generated by vm_flags. Vm_page_prot is used to set the protection bit of the table item of the PTE page. The methods for setting the protection bit of the PTE vary with the architecture.

Vm_flags: attributes of the storage memory area, including the following flag bits

Vm_read, vm_write, vm_exec, and vm_shared are used to identify whether the page content is read, written, executed, and can be shared by several processes.

Vm_mayread, vm_maywrite, vm_mayexec, and vm_mayshare determine whether vm_read, vm_write, vm_exec, and vm_shared can be set. This flag is checked when the system calls mprotext.

Vm_grownsdown and vm_growsup indicate the growth direction of the memory area. Heap increases from bottom to top, so it is set to vm_growsup; stack increases from top to bottom, so it is set to vm_growsdown

Vm_dontcopy: the memory zone is not copied when the fork system is called.

Vm_dontexpand, do not use mremap system call to expand this memory Zone

Vm_hugetlb: In some architectures, the memory zone is managed using huge pages. This flag is set at this time.

Vm_rb: the memory zone is connected to the red/black tree of the process address space through this node.

Anon_vma_node and anon_vma

Vm_ops: a collection of many methods used to perform various standard operations in the memory area.

  • When you create or delete a memory area, the open close function is called respectively. Generally, we set it to null, indicating that this interface is not used.
  • Fault is the final method. When a virtual address in the address space is accessed, there is no physical memory ing (or no page write permission ), automatically triggered page missing Exception management will eventually call this function. This function will process address ing, Data Reading, and copy on write.

Vm_pgoffset: Specifies the offset of the file ing. This value is only used when a part of the file content is mapped. (If the entire file is mapped, the offset is 0)

Vm_file: pointer to the file object of the ing file. If the VM maps to a file. If the mapped object does not love you, otherwise it is null

Vm_private_data: used to store private data and cannot be operated by common memory management programs.

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.