It mainly completes primary storage. secondary storage. and virtual storage. this includes the ing between disk files and virtual memory and the ing between virtual memory and memory. to ensure consistency between virtual storage and process scheduling. linux uses a series of data structures and a hardware cache (TLB) to implement address ING. mm_strut is used to describe... it mainly completes primary storage. secondary storage. and virtual storage. this includes the ing between disk files and virtual memory and the ing between virtual memory and memory. to ensure consistency between virtual storage and process scheduling. linux uses a series of data structures and a hardware cache (TLB) to implement address ING.
Mm_strut is used to describe the process cache.
Struct mm_struct
{
Struct vm_area_struct * mmap;/* list of VMAs */
Struct vm_area_struct * mmap_avl;/* tree of VMAs */
Struct vm_area_struct * mmap_cache;/* last find_vma result */
Pgd_t * pgd;
Atomic_t count;
Int map_count;/* number of VMAs */
Struct semaphore mmap_sem;
Spinlock_t page_table_lock;
Unsigned long context;
Unsigned long start_code, end_code, start_data, end_data;
Unsigned long start_brk, brk, start_stack;
Unsigned long arg_start, arg_end, env_start, env_end;
Unsigned long rss, total_vm, locked_vm;
Unsigned long def_flags;
Unsigned long cpu_vm_mask;
Unsigned long swap_cnt;/* number of pages to swap on next pass */
Unsigned long swap_address;
/*
* This is an architecture-specific pointer: the portable
* Part of Linux does not know about any segments.
*/
Void * segments;
};
It describes the page directory of a process and context information about the process. and data. code. stack revelation end address. there is also the number of virtual storage. and linked list pointers for scheduling and storage. he has a relatively high degree of participation
A high-level vm_area-struct is the virtual address area that describes the process. it forms a phase chain table. drop by virtual address. in this way, when the kernel needs to perform a given operation on a given process page. the customer finds this item from the bidirectional list. in the world think about page processing. for example. page error. page replacement, etc.
Its specific structure is as follows:
Struct vm_area_struct {
Struct mm_struct * vm_mm;/* VM area parameters */
Unsigned long vm_start;
Unsigned long vm_end;
/* Linked list of VM areas per task, sorted by address */
Struct vm_area_struct * vm_next;
Pgprot_t vm_page_prot;
Unsigned short vm_flags;
/* AVL tree of VM areas per task, sorted by address */
Short vm_avl_height;
Struct vm_area_struct * vm_avl_left;
Struct vm_area_struct * vm_avl_right;
/* For areas with inode, the list inode-> I _mmap, for shm areas,
* The list of attaches, otherwise unused.
*/
Struct vm_area_struct * vm_next_share;
Struct vm_area_struct ** vm_pprev_share;
Struct vm_operations_struct * vm_ops;
Unsigned long vm_offset;
Struct file * vm_file;
Unsigned long vm_pte;/* shared mem */
};
The page structure is a data structure that describes a physical page. it is not a real physical page. it only describes the content and framework of a physical page. mark the logic page ;. the flag field defines the operations on this page. the chain field defines a double linked list. page. it is easy to find. for the convenience of using the actual physical memory
The specific structure is as follows:
Typedef struct page {
/* These must be first (free area handling )*/
Struct page * next;
Struct page * prev;
Struct inode * inode;
Unsigned long offset;
Struct page * next_hash;
Atomic_t count;
Unsigned long flags;/* atomic flags, some possibly updated asynchronously */
Wait_queue_head_t wait;
Struct page ** pprev_hash;
Struct buffer_head * buffers;
Int owner;/* temporary debugging check */
} Mem_map_t;
All page structures will be transferred to an array named mem_map.
When a process is running, its code segment and data segment will be transferred to the memory. if it uses a shared library. the shared customer's content will also be carved into memory. when the process is running. the system first allocates a vm_area_struct to the process. connect the processes to the virtual memory connection mark. this is based on the information in the executable process image. the data segment and the customer execution code are not configured with memory. the newly allocated memory must be linked to the existing memory of the process before it can be applied. in this case, a page fault occurs during the party. the system uses the page mechanism to avoid excessive use of physical memory. but when the virtual memory accessed by the process is not in the current physical memory, the system will transfer the required page to the memory. modify the page table of the process at the same time. indicates whether a virtual page is in physical memory.
Therefore, the system uses a complex data structure to track virtual addresses of processes. task_struct contains a pointer to the mm_struct structure. the mm_struct of the process contains the page directory pointer pgd of the process executable image. it also contains several pointers to vm_area_struct. each vm_area_struct contains the virtual address area of a process.
A process has multiple vm_area_stuct structures. in linux, process allocation is required frequently .. or adjust vm_area_struct. in this way, the search efficiency of vm_area_stuct is improved. images are very helpful to the system. therefore, all vm_area_struct is used to form a balanced binary tree structure with high search efficiency.
I personally think that in the Linux kernel, the data structure is the most complex. if this part is taken down, the entire kernel will be clearer.
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