[Linux kernel memory management] Partition partner allocator ③ (alternate memory area list | ZONELIST_FALLBACK enumeration | zoneref structure | alternate memory area borrowing physical page rules)





1. List of spare memory areas



If the preferred memory node or memory region cannot satisfy the memory allocation request,

It is necessary to borrow physical pages from the "spare memory area" for memory allocation, and this operation needs to comply with the following algorithm rules;


The "memory node pglist_data" is described by a structure, which is defined in the linux-4.12\include\linux\mmzone.h #601 location in the Linux kernel source code;

pglist_data The struct zone node_zones[MAX_NR_ZONES]member struct zonelist node_zonelists[MAX_ZONELISTS]member is a list of spare memory areas ;

typedef struct pglist_data {
    
    
	struct zone node_zones[MAX_NR_ZONES];
	struct zonelist node_zonelists[MAX_ZONELISTS];
}pg_data_t;

Source code path: linux-4.12\include\linux\mmzone.h #601

insert image description here





2. ZONELIST_FALLBACK, ZONELIST_NOFALLBACK enumeration



In the UMA system, there are 1 11 spare area list, the internal spare areasare sorted according to the area type, from high to low;

For example: the UMA system has "normal area", "DMA area", then the spare area list is as follows {normal area, DMA area};


In each memory node of the UMA system, there are 2 22 spare memory area lists,

  • a list of spare memory regions containing all memory nodes,
  • Another one contains a list of spare areas for the current memory node;

ZONELIST_FALLBACKThe enumeration contains a list of spare memory regions for all memory nodes;

ZONELIST_NOFALLBACKenum contains a list of spare areas for the current memory node;

enum {
    
    
	ZONELIST_FALLBACK,	/* zonelist with fallback */
#ifdef CONFIG_NUMA
	/*
	 * The NUMA zonelists are doubled because we need zonelists that
	 * restrict the allocations to a single node for __GFP_THISNODE.
	 */
	ZONELIST_NOFALLBACK,	/* zonelist without fallback (__GFP_THISNODE) */
#endif
	MAX_ZONELISTS
};

Source code path: linux-4.12\include\linux\mmzone.h #545

insert image description here





Three, zoneref structure



struct zone *zonemember points to the memory area data structure;

int zone_idxmember points to the type of the memory area;

/*
 * This struct contains information about a zone in a zonelist. It is stored
 * here to avoid dereferences into large structures and lookups of tables
 */
struct zoneref {
    
    
	struct zone *zone;	/* Pointer to actual zone */
	int zone_idx;		/* zone_idx(zoneref->zone) */
};

Source code path: linux-4.12\include\linux\mmzone.h #561

insert image description here





Fourth, the spare memory area borrowing physical page rules



Borrow physical pages from "alternate memory area" rules:

① Borrowing physical pages from the same type area: The specified type area of ​​the memory node can borrow physical pages from the same type area of ​​another memory node ,

Such as: memory node AAA common area from memoryBBBorrowing physical pages from the normal area of ​​B ;


② High type borrows low type area: High area type borrows physical pages from low area type,

For example: the common area borrows physical pages from the DMA area;


Note: Low-type areas cannot borrow physical pages from high- type areas ; such as: DMA areas cannot borrow physical pages from normal areas;

Guess you like

Origin blog.csdn.net/han1202012/article/details/124342397