linux - "Freeing unused kernel memory"从哪里来?

标签 linux linux-kernel dmesg

我经常在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/

相关文章:

linux - wget .listing 文件,有没有办法指定它的名称

linux - 使 oldconfig 覆盖 .config 中的值

linux - 自定义内核模块集成

c - 在另一个文件夹中创建 1000 个文件夹并将文件放在最后一个文件夹中的最快方法

如果没有文件,linux shell脚本从stdin读取

c - 如何检查给定文件夹是否为挂载点

linux - 如果设备是 ext4,如何将 block 号映射到 vm.block_dump=1 产生的 dmesg 输出中的文件名?

linux - ubuntu 内核在 OOPS 上挂起而没有在 dmesg 或/var/log/kern.log 中显示堆栈跟踪

c - Linux 内核模块 : printk message not where I expect to be in the buffer log

c - 如何获取自己的进程名称