Releasing Memory

The kernel provides the free_bootmem function to free memory. It requires two parameters — the start address and the size of the area to be freed. The name of the equivalent function on NUMA systems is not surprisingly free_bootmem_node; it expects an additional parameter to define the appropriate node.

<bootmem.h>

void free_bootmem(unsigned long addr, unsigned long size); void free_bootmem_node(pg_data_t *pgdat, unsigned long addr, unsigned long size);

Both versions delegate their work to_free_bootmem_core. Only whole pages can be freed because the bootmem allocator does not keep any information about page divisions. The kernel uses

_free_bootmem_core to first calculate the pages whose contents are fully held in the area to be freed.

Pages whose contents are only held in part in this area are ignored. The corresponding entries in the page bitmap are set to 0 to conclude page freeing.

This procedure conceals the risk that a page is not freed if parts of its contents are returned in successive requests. If the first half of a page and at some time later the second half of the same page are freed, the allocator has no way of knowing that the entire page is no longer in use and can therefore be freed. The page simply remains ''in use,'' although this is not the case. Nevertheless, this is not a big problem because free_bootmem is very rarely used. Most memory areas allocated during system initialization are intended for basic data structures that are needed throughout kernel run time and are therefore never relinquished.

Continue reading here: Disabling the Bootmem Allocator

Was this article helpful?

0 0