[Linux kernel memory management] memblock allocator programming interface ⑤ ( memblock_free function | memblock_remove_range function )


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;


In the previous blog, the memblock_add memblock_remove memblock_alloc function , and this blog started to introduce the memblock_freememory allocation function;





1. Analysis of memblock_free function



memblock_freeThe function of the function is to release memory and delete a memory block from the "reserved memory area";


memblock_freeFunction parameter description:

  • phys_addr_t baseThe parameter indicates the starting ;
  • phys_addr_t sizeThe parameter indicates the size ;

In the memblock_freefunction ,

call the kmemleak_free_part_physfunction to calculate the end address of the physical memory area to be deleted,

Finally, the memblock_remove_rangefunction is , and the execution continues backward;


memblock_freeThe 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;

Guess you like

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