Where does “Freeing unused kernel memory” come from?

拥有回忆 提交于 2021-01-29 09:45:56

问题


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?


回答1:


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:

/*
 * 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");
}

The rest of that text is from free_reserved_area() in mm/page_alloc.c:

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

(Code excerpts from v5.2)



来源:https://stackoverflow.com/questions/57096112/where-does-freeing-unused-kernel-memory-come-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!