Article directory
1. memblock distributor programming interface
The memblock allocator provides the following programming interfaces:
① Add memory: memblock_add
function, add the memory block area to the memblock.memory
member , that is, insert a piece of available physical memory;
② Delete memory: memblock_remove
function, delete the memory block area;
③ Allocate memory: memblock_alloc
function, apply for memory allocation;
④ Release memory: memblock_free
function, release the memory allocated before;
Two, memblock_add function prototype analysis
memblock_add
function, add the memory block area to the memblock.memory
member , that is, insert a piece of available physical memory;
memblock_add
The function prototype is as follows:
int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
phys_addr_t base
The parameter indicates the "starting address" of the "memory block" to be added;
phys_addr_t size
The parameter indicates the "size" of the "memory block" to be added;
In the memblock_add
function , call the memblock_add_range
function to add the memory block memblock.memory
to ;
memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0);
Three, memblock_add function source code
memblock_add
The function is defined in the linux-4.12\mm\memblock.c #603 location of the Linux kernel source code ;
int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
{
phys_addr_t end = base + size - 1;
memblock_dbg("memblock_add: [%pa-%pa] %pF\n",
&base, &end, (void *)_RET_IP_);
return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0);
}
Source code path: linux-4.12\mm\memblock.c #603