In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you how to understand the memory management of the Linux process, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Several key data structures
The virtual address space of a process is mainly described by two data knots, one is mm_struct and the other is vm_area_structs.
The mm_struct structure describes the entire virtual address space of a process, and vm_area_truct describes an interval of the virtual address space (referred to as the virtual area). The following figure is what we call the distribution of address space for processes from task_struct to mm_struct.
Each process will have its own independent mm_struct, so that each process will have its own independent address space, so that it can not interfere with each other. When the address space between processes is shared, we can understand that this is the time when multiple processes use a single address space, which is the thread.
Struct mm_struct {struct vm_area_struct * mmap; / / point to VMA linked list struct rb_root mm_rb; / / point to red_ blacktree struct vm_area_struct * mmap_cache; / / find the nearest virtual interval unsigned long (* get_unmapped_area) (struct file * filp,unsigned long addr,unsigned long len,unsigned long pgoof,unsigned long flags) Void (* unmap_area) (struct mm_struct * mm,unsigned long addr); unsigned long mmap_base; unsigned long task_size; / / the size of the virtual address space of the process that owns the structure unsigned long cached_hole_size; unsigned long free_area_cache; pgd_t * pgd; / / points to the page global catalog atomic_t mm_users / / how many users are there in the user space atomic_t mm_count; / / A pair of "struct mm_struct" has how many references to int map_count; / / the number of virtual intervals struct rw_semaphore mmap_sem; spinlock_t page_table_lock; / / protection task page table and mm- > rss struct list_head mmlist / / linked list of all active mm mm_counter_t _ file_rss; mm_counter_t _ anon_rss; unsigned long hiwter_rss; unsigned long hiwater_vm; unsigned long total_vm,locked_vm,shared_vm,exec_vm; usingned long stack_vm,reserved_vm,def_flags,nr_ptes; unsingned long start_code,end_code,start_data,end_data / / start start_code of the code segment, end end_code, start start_data of the data segment, end end_data unsigned long start_brk,brk,start_stack; / / start_brk and brk record information about the heap. Start_brk is the initialization of the user's virtual address space, brk is the end address of the current heap, and start_stack is the start address of the stack. / / start arg_start of parameter segment, end arg_end, start env_start of environment segment, and end env_end unsigned long saved_ auxv [AT _ VECTOR_SIZE] Struct linux_binfmt * binfmt; cpumask_t cpu_vm_mask; mm_counter_t context; unsigned int faultst unsigned int token_priority; unsigned int last_interval; unsigned long flags; struct core_state * core_state;}
Each virtual memory area allocated is managed by a vm_area_struct data structure, including the start and end addresses of the virtual memory, as well as the access rights to the memory, which is usually named vma;vm_area_struct data structure as follows:
Struct vm_area_struct {/ * The first cache line has the info for VMA tree walking. The first cache line has the information of VMA tree movement * / unsigned long vm_start; / * Our start address within vm_mm. * / unsigned long vm_end; / * The first byte after our end address within vm_mm. * / / * linked list of VM areas per task, sorted by address the list of links in the VM area of each task, sorted by address * / struct vm_area_struct * vm_next, * vm_prev; struct rb_node vm_rb; / * the largest memory gap (in bytes) on the left side of this VMA. Between this VMA and vma- > vm_prev, or between one of our lower VMA in VMA rbtree and its-> vm_prev. This helps get_unmapped_area find free space of the right size. * / unsigned long rb_subtree_gap; / * Second cache line starts here. The second cache line starts here * / struct mm_struct * vm_mm; / * address space*/ pgprot_t vm_page_prot; / * access to this VMA * / unsigned long vm_flags; / * Flags, see mm.h. * / / * for areas with address space (address apace) and backup storage (backing store), link to address_space- > i_mmap interval tree, or link to vma in the address_space- > i_mmap_nonlinear list. * / union {struct {struct rb_node rb; unsigned long rb_subtree_last;} linear; struct list_head nonlinear;} shared; / * after the COW of one of the file pages, the MAP_PRIVATE vma of the file can be in the i_mmap tree and the anon_vma list. MAP_SHARED vma can only be located in an i_mmap tree. Anonymous MAP_PRIVATE, stack or brk vma (with NULL files) can only be in the anon_vma list. * / struct list_head anon_vma_chain; / * Serialized by mmap_sem & * page_table_lock serialized by mmap_sem and * page_table_lock * / struct anon_vma * anon_vma; / * Serialized by page_table_lock serialized by page_table_lock * / / * function pointer used to process this structure * / const struct vm_operations_struct * vm_ops / * backup storage (backing store) information: * / unsigned long vm_pgoff; / * offset in PAGE_SIZE (in vm_file), * not * PAGE_CACHE_SIZE*/ struct file * vm_file; / * We map to a file (can be NULL) * / void * vm_private_data; / * is vm_pte (shared memory) * / # ifndef CONFIG_MMU struct vm_region * vm_region / * NOMMU mapping region * / # endif # ifdef CONFIG_NUMA struct mempolicy * vm_policy; / * NUMA policy for VMA * / # endif}; small experiment
Insmod test.ko pid_mem=3253 displays individual vma areas
Cat / proc/3253/maps displays each vma area
Take a look at the comparison between the two ways:
On how to understand the memory management of the Linux process is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.