我经常在dmesg
中看到释放未使用的内核内存:xxxK (......)
,但我永远无法从内核源代码中找到这个日志grep/rg 的帮助。
它从哪里来?
最佳答案
该行文本不作为单个完整字符串存在,因此您无法对其进行 grep。
当 init/main.c 中的 free_initmem() 调用 free_initmem_default() 时,这一切都会开始。
相关行源自 include/linux/mm.h 中的 free_initmem_default():
/*
* Default method to free all the __init memory into the buddy system.
* The freed pages will be poisoned with pattern "poison" if it's within
* range [0, UCHAR_MAX].
* Return pages freed into the buddy system.
*/
static inline unsigned long free_initmem_default(int poison)
{
extern char __init_begin[], __init_end[];
return free_reserved_area(&__init_begin, &__init_end,
poison, "unused kernel");
}
该文本的其余部分来自 mm/page_alloc.c 中的 free_reserved_area():
unsigned long free_reserved_area(void *start, void *end, int poison, const char *s)
{
void *pos;
unsigned long pages = 0;
...
if (pages && s)
pr_info("Freeing %s memory: %ldK\n",
s, pages << (PAGE_SHIFT - 10));
return pages;
}
(代码摘录自 v5.2)
关于linux - "Freeing unused kernel memory"从哪里来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57096112/