[Linux kernel memory management] memblock allocator programming interface ① (Introduction to memblock allocator programming interface | memblock_add function prototype analysis | memblock_add function source code)





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.memorymember , 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_addfunction, add the memory block area to the memblock.memorymember , that is, insert a piece of available physical memory;

memblock_addThe function prototype is as follows:

int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)

phys_addr_t baseThe parameter indicates the "starting address" of the "memory block" to be added;

phys_addr_t sizeThe parameter indicates the "size" of the "memory block" to be added;


In the memblock_addfunction , call the memblock_add_rangefunction to add the memory block memblock.memoryto ;

memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0);




Three, memblock_add function source code



memblock_addThe 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

insert image description here

Guess you like

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