Article directory
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;
In the previous blog, the memblock_add
memblock_remove
memblock_alloc
function , and this blog started to introduce the memblock_free
memory allocation function;
1. Analysis of memblock_free function
memblock_free
The function of the function is to release memory and delete a memory block from the "reserved memory area";
memblock_free
Function parameter description:
phys_addr_t base
The parameter indicates the starting ;phys_addr_t size
The parameter indicates the size ;
In the memblock_free
function ,
call the kmemleak_free_part_phys
function to calculate the end address of the physical memory area to be deleted,
Finally, the memblock_remove_range
function is , and the execution continues backward;
memblock_free
The function is defined in the linux-4.12\mm\memblock.c #710 location of the Linux kernel source code ;
int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size)
{
phys_addr_t end = base + size - 1;
memblock_dbg(" memblock_free: [%pa-%pa] %pF\n",
&base, &end, (void *)_RET_IP_);
kmemleak_free_part_phys(base, size);
return memblock_remove_range(&memblock.reserved, base, size);
}
Source code path: linux-4.12\mm\memblock.c #710
2. Analysis of memblock_remove_range function
Refer to [Linux Kernel Memory Management] memblock allocator programming interface ③ (memblock_remove function | memblock_remove_range function) 2. Memblock_remove_range function analysis blog chapter, in this blog chapter, the execution process and source code of this function are analyzed in detail;