[Linux Memory]linux Memory Learning (iii)--Memory management Basics

Source: Internet
Author: User

1,linux Kernel Memory Management

The memory establishment of ARM architecture is

In the Kernel/arch/arm/kernel/setup.c file ~

Linux kernel design and implementation--memory management

In the Linux kernel, the kernel takes the physical page as the basic unit of memory management, the smallest address unit of the processor is the byte, and from the virtual memory point of view, the page is the smallest unit.
A struct page structure is used in the kernel to represent each physical page, and each physical page in the system has such a structure. All page descriptors exist in the Mem_map array, and each page descriptor (struct page) is 32 bytes long.

[CPP]View Plaincopy
  1. typedef struct Page {
  2. struct List_head list;
  3. struct Address_space *mapping;
  4. unsigned long index;
  5. struct page *next_hash;
  6. atomic_t count;
  7. unsigned long flags;
  8. struct List_head LRU;
  9. unsigned long age;
  10. wait_queue_head_t wait;
  11. struct page **pprev_hash;
  12. struct Buffer_head * buffers;
  13. void *virtual;
  14. struct zone_struct *zone;
  15. } mem_map_t;

Linux provides the Page_zone () function to receive the address of a page descriptor as its argument, reads the highest bit of the flags field in the descriptor, and then determines the address of the corresponding management area descriptor by looking at the zone_table array
All page descriptors are stored in the global Mem_map array, and the subscript of the array is the page box number (PFN) page descriptor that is mapped to the page box
Virt_to_page (addr): Line address addr corresponding page descriptor address
Pfn_to_page (PFN): Page box number PFN corresponding page descriptor address
PAGE_TO_PFN (PG): Page box number of the page descriptor that corresponds to page PFN

The kernel pages are divided into different zones, and there are four main areas of Linux
ZONE_DMA used to perform DMA-related operations
Zone_normal pages that can be mapped normally
Zone_highem High-end memory

Zone_dma,zone_normal,zone_highem are broken down by physical pages.
Each zone uses a struct zone struct to represent

? Linux provides the Page_zone () function to receive the address of a page descriptor as its argument, reads the highest bit of the flags field in the descriptor, and then determines the address of the corresponding management area descriptor by looking at the zone_table array

The difference between the Kmalloc () function and the Vmalloc () function:
The memory allocated by the Kmalloc () function is physically contiguous, whereas the memory allocated by the Vmalloc () function is only a continuous virtual address, and normal kernel programming usually uses the Kmalloc (), which is primarily in performance consideration because Vmalloc () Converting a physically discontinuous page into a contiguous page on a virtual address space must be specifically set up for page table entries, and Vmalloc () is used only when large chunks of memory are needed, typically when the module is dynamically inserted into the kernel. Many other hardware devices require a contiguous page of physical addresses, because many hardware devices exist outside of the memory Management Unit (MMU). In addition, the Vmalloc () function may sleep and cannot be used in the middle end, while Kmalloc plus gfp_atomic can be used in places where sleep is not possible.

Reserved page-Frame pool
When processing interrupts or executing code within the critical section, the code can not be blocked when requesting memory, if the current memory is not enough memory, then the direct return failure, in order to minimize the number of failures, the kernel for the Atomic memory allocation request to retain a page frame pool, the bottom is 128K, Maximum 65536KB (minimum value reserved for key allocation)

2,uma and Numa

UMA: Consistent memory access, each processor in the system accessing each memory area is the same block

NUMA: Non-uniform memory access, each CPU in the system has its own local memory, each processor is connected by bus to support local coarse access to other CPUs

(N) The memory model in Uma

On NUMA, the memory is divided into nodes, each node is associated to a processor, each node is organized in the form of a single-linked list, the UMA has only one node, the node is represented by struct pg_data_t struct, each node is divided into memory area, and the region is represented by the struct struct zone. Zones are Zone_dma,zone_normal,zone_gighmem, and each memory area is associated with an array that manages the physical pages that belong to that memory area, and is represented by the struct page struct for each physical page.

3, Memory domain watermark

The memory watermark is represented by the pages_min,pages_high,pages_low in the struct zone struct, if the free page is more than Pages_high, the state of the memory domain is ideal, and the number of memory pages is less than Pages_low. The kernel begins to swap the page out to the hard disk,

4, hot and cold pages

The Pageset member in the struct zone struct is used to implement the hot and cold dispenser, and the kernel says that the page is hot means that the page has been loaded into the CPU cache, the cold page is not in the cache, and each CPU has its own hot and cold pages group.

[Linux Memory]linux Memory Learning (iii)--Memory management Basics

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.