I often see Freeing unused kernel memory: xxxK (......)
from dmesg
, but I can never find this log from kernel source code with the help of grep/rg.
Where does it come from?
I often see Freeing unused kernel memory: xxxK (......)
from dmesg
, but I can never find this log from kernel source code with the help of grep/rg.
Where does it come from?
From my answer here:
Some functions in the kernel source code are marked with __init
because they run only once during initialization. This instructs the compiler to mark a function in a special way. The linker collects all such functions and puts them at the end of the final binary file.
Example method signature:
static int __init clk_disable_unused(void)
{
// some code
}
When the kernel starts, this code runs only once during initialization. After it runs, the kernel can free this memory to reuse it and you will see the kernel message:
Freeing unused kernel memory: 108k freed
That line of text does not exist as a single, complete string, hence your failure to grep it.
This all gets rolling when free_initmem() in init/main.c calls free_initmem_default().
The line in question originates from free_initmem_default() in include/linux/mm.h:
The rest of that text is from free_reserved_area() in mm/page_alloc.c:
(Code excerpts from v5.2)