Linux memory Management (i) Memory organization

Source: Internet
Author: User
Tags closing tag

Memory management is the most complex and important part of the kernel. It is characterized by the need for collaboration between the processor and the kernel.

First, the memory is divided into nodes, represented as pg_data_t in the kernel, and each node divided into memory domain.

All of the data structures or code below have been reduced to varying degrees, on the one hand, to preserve the relevant code, to remove Twigs CE, and to be aesthetically pleasing.

The data structure of the node is

<mmzone.h>
typedefstructPglist_data {structzone Node_zones[max_nr_zones]; */* Memory node contains an array of memory fields * /structzonelist node_zonelists[max_zonelists];/* Specifies a list of alternate nodes and their memory domains * /intnr_zones/* Number of memory domains */#ifdef config_flat_node_mem_mapstructPage *Node_mem_map;/*node_mem_map is a pointer to an array of page instances that contains the page for all memory domains in the endpoint * /#endif structBootmem_data *bdata;/*bdata specifies an instance of the data structure used for the bootstrap allocator */#ifdef Config_memory_hotplug#endifunsignedLongNODE_START_PFN;/* The logical number of the first page frame in a node */unsignedLongNode_present_pages;/*total number of physical memory pages, not including memory holes*/unsignedLongNode_spanned_pages;/*total length of physical memory pages, including holes*/ intnode_id;/* Junction id*/
struct Pglist_data *pgdata_next; /* Pointer to next memory node * /} pg_data_t;

The memory field is represented by an enumeration, as follows

<mmzone.h>enumZone_type {#ifdef CONFIG_ZONE_DMAZONE_DMA,/*ZONE_DMA represents the DMA region. On IA-32 machines, the general limit is 0~16m. */#endif     Zone_normal,/*zone_normal represents a normal memory domain that can be mapped directly to a kernel segment. On the x86 machine for 16m~896m. */#ifdef CONFIG_HIGHMEMZone_highmem,/*  Zone_highmem marks the physical memory beyond the kernel segment. If the memory is 4G on the x86 machine, then the 896M~4G is the high-end memory. */#endifzone_movable,/ *  zone_movable represents a memory domain that is part of a pseudo-memory domain and is primarily used to prevent memory fragmentation.  *  /max_nr_zones/*max_nr_zones acts as the closing tag. The iteration used for the memory domain. */};

The structure of the memory domain is described as follows:

<mmzone.h>
structZone {
/*
*pages_min, Pages_low, Pages_high is a watermark, used for the calculation of surface swap out
*pages_high indicates that the state of the memory domain is ideal if there are more free pages in the memory domain than this value
*pages_low indicates that if a free page in the memory domain falls below this value, the kernel begins to swap the page out to the hard disk
*pages_min indicates that if the free pages in the memory domain are below this value, there are very few free pages. This is a very stressful time to recycle your pages.
* /unsignedLongpages_min, Pages_low, Pages_high;
/*
*lowmen_reserve represents the number of pages reserved for each memory domain for critical memory allocations that cannot fail
* /unsignedLongLowmem_reserve[max_nr_zones]; structPer_cpu_pageset Pageset[nr_cpus];/* hot and cold frame list per CPU * /spinlock_tLock;/* Spin lock * /    structFree_area free_area[max_order];/* Data structure for the partner system * /spinlock_t Lru_lock; /* Spin lock * /structlist_head active_list;/* Collection of active pages, page instance * /structlist_head inactive_list;/* Collection of inactive pages, page instance */unsignedLongnr_scan_active;/* Specifies the number of active pages to scan when reclaiming memory */unsignedLongnr_scan_inactive;/* Specifies the number of inactive pages that need to be scanned when memory is reclaimed */unsignedLongpages_scanned;/*Specifies how many pages have not been successfully scanned since the last one has been pulled out of a page*/unsignedLongFlags/*current state of the memory domain*/atomic_long_t Vm_stat[nr_vm_zone_stat_items]; */* Statistics of memory * / structPglist_data *zone_pgdat;/* Specify pg_data_t instance * //*ZONE_START_PFN = = zone_start_paddr >> page_shift*/unsignedLongZONE_START_PFN/* Index of the first page frame of the memory domain * /};

Data structures for page frames:

structpage {unsignedLongFlags/*markup for page frames*/atomic_t _count;/*Use count*/Union {atomic_t _mapcount;/* The page table item count mapped in the memory management subsystem to indicate whether the page has been mapped, and also to limit the reverse mapping search * /unsignedintInUse/*for Slub Allocator: Number of objects*/    }; Union {struct{unsignedLong Private; /* By mapping Private, opaque data */structAddress_space *mapping; /* The address space where the mapping is located */        }; structKmem_cache *slab;/*Pointer to Slub*/        structPage *first_page;/*End of composite page, point to homepage*/    };        Union {pgoff_t Index; /*the offset within the map*/        void*freelist;/*slub:freelist req. Slab Lock*/    }; structList_head LRU; /* For maintaining the page on a variety of different feeding * *#ifDefined (want_page_virtual)void*Virtual; /* for pages in high-end memory. Store the virtual address of the page */#endif/* Want_page_virtual */};

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.