【问题标题】:Where are struct page* initialized in Linux?Linux 中的 struct page* 在哪里初始化?
【发布时间】:2021-07-22 14:41:30
【问题描述】:

我们知道,struct page 在 Linux 中与一个 4KB 物理页面相关联并映射到一个 pfn。这构成了 Linux 中内存分配的主干。 struct pageinclude\linux\mm_types.h 中进行了描述,其中包含有关页面的各种信息。我想知道,struct page 在引导期间何时分配,谁初始化这些struct page 结构以及在哪里(在 linux 中)?

我能够从这个答案 -https://stackoverflow.com/a/63893944/13286624 中了解页面的存储位置,但我无法找到这些结构是如何分配和初始化的。

【问题讨论】:

    标签: linux memory memory-management linux-kernel operating-system


    【解决方案1】:

    您应该查看include/linux/gfp.h 文件。它有一堆alloc_page 类型的函数。从那里,使用cscope 或您最喜欢的 IDE,您可以看到调用这些函数的每个函数,并让您了解这些函数的使用方式。

    【讨论】:

    • 感谢您的回答,但这不是我的疑问。当我们使用 alloc_page* 时,我们只是找到一个空闲的结构页面 (get_page_from_freelist),对其进行一些处理并返回它。我的意思是问,struct page 指针首先分配/填充在哪里(可能在引导期间)。
    • 是的,我不知道答案,但除非其他人知道,否则可能需要我的建议,使用cscope 调查谁调用了这些分配函数并查看您是否可以跟踪下面是“启动”调用。祝你好运
    • 您也可以在 Linux 内核邮件列表中询问。他们会更了解像这样的 Linux 内核内部,并且更有可能为您提供您正在寻找的答案。如果您发现了,请在此处发布作为帮助他人的答案(请务必在您的答案中链接电子邮件互动)。
    【解决方案2】:

    也许试试mm_init,由/init/main.c/ 中的start_kernel()/arch/x86/mm/init_64.c 中相应的mem_init 调用:

    void __init mem_init(void)
    1286 {
    1287     pci_iommu_alloc();
    1288 
    1289     /* clear_bss() already clear the empty_zero_page */
    1290 
    1291     /* this will put all memory onto the freelists */
    1292     memblock_free_all();
    1293     after_bootmem = 1;
    1294     x86_init.hyper.init_after_bootmem();
    1295 
    1296     /*
    1297      * Must be done after boot memory is put on freelist, because here we
    1298      * might set fields in deferred struct pages that have not yet been
    1299      * initialized, and memblock_free_all() initializes all the reserved
    1300      * deferred pages for us.
    1301      */
    1302     register_page_bootmem_info();
    

    【讨论】:

      猜你喜欢
      • 2020-10-09
      • 1970-01-01
      • 2017-04-18
      • 2014-04-27
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 2023-02-04
      • 1970-01-01
      相关资源
      最近更新 更多