[Linux Memory] Partner System Learning Note (i)--concept

Source: Internet
Author: User

1, the role of the partner system:
The partner system is primarily designed for efficient use of physical memory, minimizing the generation of memory fragments

2, the concept of the partner system:
Memory in the system is always 22 grouped, and two memory blocks in each group are called partners

3, the principle of the partner system:
Partner system is relative to the struct zone, the free memory of each zone is divided into up to 11 arrays, such as the first array to manage the memory of the 2^0 page, all of these 2^0 pages are connected to the two-way list of the LRU domain of the struct page, and the second array manages the 2^ 1 pages of memory, all of these 2^0 pages are connected to the two-way list of the LRU domain of the struct page, and so on, ... When you want to request memory for a 4k (that is, the 2^0 page), you request it directly from the first array, and if the first array has no free memory, the 2^1 page of the second array is decomposed into two 2^0 pages for application.

4, related data structure of the partner system
The partner system is relative to the struct zone, and the struct free_area in the struct zone is used to describe the free memory block of the management Area partner system.

  struct Zone {      ...           ...          struct Free_area    Free_area[max_order];      ...      ...  }    struct Free_area {      struct list_head    free_list[migrate_types];      unsigned long       nr_free;   The total number of free memory blocks in the Free_area, in units of page size}; #define Max_order 11#define migrate_types 5


5. To prevent memory fragmentation Related:
User-space programs do not run into memory fragmentation issues because their memory is mapped through page tables, regardless of how the free pages are allocated in physical memory, the application
The memory you see is always continuous. However, for the kernel, memory fragmentation is often encountered because most of the physical memory is linearly mapped to kernel space.
The kernel divides the page into the following three types
Non-removable pages: there is a fixed position in memory and cannot be moved to another location.
Recyclable pages: cannot be moved directly, but their memory can be recycled. The KSWAPD daemon periodically recycles the memory of the recoverable pages.
Mobile Pages: Pages can be moved at will, the page of the user space application belongs to this type, belongs to the page table map

#define MIGRATE_UNMOVABLE     0  #define migrate_reclaimable   1  #define Migrate_movable       2  # Define Migrate_pcptypes 3/* The number of types on the      PCP lists */  #define MIGRATE_RESERVE       3  #define MIG Rate_isolate       4/* can ' t allocate from here */  #define MIGRATE_TYPES         5  


Migrate_pcptypes is Per_cpu_pageset, which is the number of migration types used to represent the list of links in the data structure for each CPU page box cache
Migrate_reserve can be allocated from Migrate_reserve when none of the top three lists are available to satisfy the allocated memory block
Migrate_isolate is used to move physical memory pages across NUMA nodes, and on large systems it is beneficial to move physical memory pages closer to the CPU that is most frequently used on that page
Migrate_types represents the number of migration types

When there are no free blocks in the linked list for a specified migration type, the list of other migration types is searched in the order defined below

static int Fallbacks[migrate_types][migrate_types-1] = {      [migrate_unmovable]   = {migrate_reclaimable, MIGRATE _movable,   Migrate_reserve},      [migrate_reclaimable] = {migrate_unmovable,   migrate_movable,   MIGRATE _reserve},      [migrate_movable]     = {migrate_reclaimable, migrate_unmovable, Migrate_reserve},      [Migrate_ Reserve]     = {migrate_reserve,     migrate_reserve,   Migrate_reserve},/* never used */  


6,debug Related:
The current state information about the partner system can be obtained in/proc/buddyinfo.

[Linux Memory] Partner System Learning Note (i)--concept

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.