【问题标题】:What's the "right" way to use GFP_ZERO in latest kernels?在最新内核中使用 GFP_ZERO 的“正确”方法是什么?
【发布时间】:2013-11-14 00:26:46
【问题描述】:

我发现在 linux 3.0+ 上 GFP_ZERO 不再在 headers 中定义。

我在 gfp.h 中发现的只是,

/* Plain integer GFP bitmasks. Do not use this directly. */
...
#define ___GFP_ZERO     0x8000u

我已经检查了那些“导出”的位掩码,其中一个使用 GFP_ZERO

而且作者说Do not use this directly,那么,我应该如何将页面归零,

kmalloc + memset 是我现在唯一的选择吗?

【问题讨论】:

    标签: memory linux-kernel kmalloc


    【解决方案1】:

    我认为预期的归零方法是 kzalloc():

    https://www.kernel.org/doc/htmldocs/kernel-api/API-kzalloc.html

    但显然 alloc + memset 也可以。

    更新

    来自CFQ 的示例差异显示了预期的更新:

    -   cfqd = kmalloc_node(sizeof(*cfqd), GFP_KERNEL | __GFP_ZERO, q->node);
    +   cfqd = kzalloc_node(sizeof(*cfqd), GFP_KERNEL, q->node);
    

    另请参阅:https://stackoverflow.com/a/12095263/2908724

    【讨论】:

    • 哇!从来不知道这个;-P
    猜你喜欢
    • 2021-08-31
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多