Linux learning 2 memory management important data structures
Source: Internet
Author: User
Linux learning 2 memory management an important data structure-general Linux technology-Linux programming and kernel information. The following is a detailed description. Here we only list several troublesome Data Structures
Struct list_head {
Struct list_head * next, * prev;
} // Linux two-way link queue, which is used in multiple places below. The source code is listed here.
Linux uses page-based memory management to describe pages with a Data Structure page. In the kernel, there is a global volume mem-map pointing to an array of pages. The entire array describes the entire physical memory. Note the 32-bit address line. The memory size is the power of 2 to 32. Because the page size is 4 K, that is, 2 to the power of 12. Each 4 K page has a page. In this case, the 32 power of 2 has a 20 power page of 2, and the mem-map points to an array of 20 power of 2. Obviously, the physical address of the page must be a multiple of 4 K, because the size is 4 K, then this array has a corresponding, the array subscript is followed by 12 0 (2 hexadecimal) corresponding to the physical address of the page, they are equal in numbers. Therefore, there is no need to store the physical address of the page data structure. Page data structure definition location include/linux/mm. h
Struct page {
Struct list_head list; // use it to enter the bidirectional chain queue in the following data structure free_area_struct Structure
Struct address_space * mapping;
Unsigned long index;
Struct page * next_hash; // its own pointer, which can be linked to a linked list
Atomic t count;
Unsigned long flags;
Struct list_head lru;
Unsigned long age;
Wait_queue_head_t wait;
Struct page ** pprev_hash;
Struct buffer_head * buffers;
Void * virtual
Struct zone_struct * zone;
}
(I will make up the description of each item)
It is certainly not enough to describe the memory by using the page data structure. For the entire memory, we have divided the concept of a management area, where each management area manages several pages. We do not care about the use of this, but we know what it is. The data structure is zone_struct defined in include/linux/mmzone. h.
Typedef struct free_area_struct {
Struct list_head free_list; // bidirectional link queue used in linux
Unsigned int * map;
} Free_area_t;
Typedef struct zone_struct {
Spinlock_t lock;
Unsigned long offset; // indicates the starting page number of the management area in the mem-map array.
Unsigned long free pages;
Unsigned long inactive_clean_pages;
Unsigned long inactive_dirty_pages;
Unsigned pages_min, pages_low, pages_high;
Struct list_head inactive_clean_list;
Free_area_t free_area [MAX_ORDER]; // a group of "Idle interval" queues, defined in free_area_t
Char * name;
Unsigned long size;
Struct pglist_data * zone_pgdat; // point to the storage node to which it belongs, and the following data structure
Unsigned long zone_start_paddr;
Unsigned long zone_start_mapnr;
Struct page * zone_mem_map;
} Zone_t;
We know that the memory status is not "equal". For example, the Static Memory ram on the primary memory and graphics card is not "equal". Therefore, our page management mechanism has been modified, the management area is not the most advanced concept in memory management. The aforementioned page array mem-map is not global, but belongs to a specific node. On zone_struct, there is a data structure pglist_data that represents the storage node, defined in include/linux/mmzone. h Medium
Typedef struct pglist_data {
Zone_t node_zones [MAX_NR_ZONES]; // The maximum number of three page management zones for this node. The value of MAX_NR_ZONE is 3. in linux, there are three management zones, or two ZONE_DMA, ZONE_NORMAL, ZONE_HIGHMEM.
Zonelist_t node_zonelist [NR_GFPINDEX]; // For details, see the following data structure.
Struct page * node_mem_map; // point to the page array of the storage Node
Unsigned long * valid_addr_bitmap;
Struct bootmem_data * bdata;
Unsigned long node_start_paddr;
Unsigned long node_start_mapnr;
Unsigned long node_size;
Int node_id;
Struct pglistdata * node_next; // used to form a single-chain queue
} Pg_data_t;
Typedef struct zonelist_struct {
Zone_t * zones [MAX_NR_ZONES + 1]; // pointer array, pointing to each specific page management area
Int gfp_mask;
} Zonelist_t;
These are all used for physical space management. Virtual space management is described by the following data structure (I first converted the virtual space into virtual memory, and the more I see it, the more confused, the more I mean, in linux, 4G memory is divided into two parts. The address 1G memory is called the system space. All processes share the memory. The following 3G is the virtual space, and each process occupies 3G of the virtual space, in the process's own opinion, but in fact, it is far from using so much memory), vm_area_struct data structure, defined in include/linux/mm. h
Struct vm_area_struct {
Struct mm_struct * vm_mm; // The following describes
Unsigned long vm_start;
Unsigned long vm_end; // start and end determine the virtual storage space. In my opinion, it should be the subscript of the mem-map table, where start contains, end does not include, at the same time, the interval division is not only address continuity, but also the consistency of permissions.
Struct vm_area_struct * vm_next; // link the virtual memory intervals of the same process to the virtual memory address
Pgrot t_vm_page_prot;
Unsigned long vm_flags; // permission for storing the interval
Short vm_avl_height;
Struct vm_area_struct * vm_avl_left;
Struct vm_area_struct * vm_avl_ri.pdf; // used to generate avl trees and improve search efficiency
Struct vm_operations_struct * vm_ops; // The following description
Unsigned long vm_pgoff;
Struct file * vm_file;
Unsigned long vm_raend;
Void * vm_private_data; // these attributes are used to record the relationship between pages and files.
}
Defined in include/linux/mm. h
Struct vm_operations_struct {
Void (* open) (struct vm_area_struct * area );
Void (* close) (struct vm_area_struct * area );
Struct page * (* nopage) (struct vm_area_struct * area, unsigned long address, int write_access );
} // Open, close, and nopage are used to open, close, and create an inprint for a virtual storage space.
Defined in include/linux/sched. h
Struct mm_struct {
Struct vm_area_struct * mmap; // create a single-chain queue of the virtual storage space
Struct vm_area_struct * mmap_avl; // creates an AVL Tree of the virtual storage space.
Struct vm_area_struct * mmap_cache; // the last time you used the VM space, because the memory access is always local, the hit rate is 35%.
Pgd_t * pgd; // point to the process page Directory
Atomic_t mm_users;
Atomic_t mm_count;
Int map_count;
Struct semaphore mmap_sem; // used for mutually exclusive access between processes
Spinlock_t page_table_lock;
Struct list_head mmlist;
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;
Unsigned long swap_address;
Mm_context_t context;
}
In the operating system, there is a concept of a process control block (PCB). Specifically, the data structure in linux is task_struct, which has an internal mm_struct pointer, mm_struct is the abstraction of the entire user space.
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