【问题标题】:which kmalloc flag should be used应该使用哪个 kmalloc 标志
【发布时间】:2011-03-07 05:27:28
【问题描述】:

我一直在到处寻找解释何时使用kmalloc 的每个标志的文档。我找到了this reference,它公平地解释了何时使用某些标志,但我在gfp.h 头文件中找不到其他标志,如GFP_HIGHUSER_PAGECACHEGFP_HIGHUSER_MOVABLE 和其他标志...有人可以告诉我什么时候使用使用这些其他标志?

【问题讨论】:

    标签: c linux linux-kernel embedded-linux kmalloc


    【解决方案1】:

    您想要Understanding the Linux Virtual Memory Manager (pdf)获取免费页面 (GFP) 标志部分。它适用于 2.4 内核,但仍应适用。

    原帖:

    来自2.6.32 gfp.h

       /*
        * Action modifiers - doesn't change the zoning
        *
        * __GFP_REPEAT: Try hard to allocate the memory, but the allocation attempt
        * _might_ fail.  This depends upon the particular VM implementation.
        *
        * __GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
        * cannot handle allocation failures.
        *
        * __GFP_NORETRY: The VM implementation must not retry indefinitely.
        *
        * __GFP_MOVABLE: Flag that this page will be movable by the page migration
        * mechanism or reclaimed
        */    
        #define __GFP_WAIT      ((__force gfp_t)0x10u)  /* Can wait and reschedule? */
        #define __GFP_          ((__force gfp_t)0x20u)  /* Should access emergency pools? */
        #define __GFP_IO        ((__force gfp_t)0x40u)  /* Can start physical IO? */
        #define __GFP_FS        ((__force gfp_t)0x80u)  /* Can call down to low-level FS? */
        #define __GFP_COLD      ((__force gfp_t)0x100u) /* Cache-cold page required */
        #define __GFP_NOWARN    ((__force gfp_t)0x200u) /* Suppress page allocation failure warning */
        #define __GFP_REPEAT    ((__force gfp_t)0x400u) /* See above */
        #define __GFP_NOFAIL    ((__force gfp_t)0x800u) /* See above */
        #define __GFP_NORETRY   ((__force gfp_t)0x1000u)/* See above */
        #define __GFP_COMP      ((__force gfp_t)0x4000u)/* Add compound page metadata */
        #define __GFP_ZERO      ((__force gfp_t)0x8000u)/* Return zeroed page on success */
        #define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u) /* Don't use emergency reserves */
        #define __GFP_HARDWALL   ((__force gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */
        #define __GFP_THISNODE  ((__force gfp_t)0x40000u)/* No fallback, no policies */
        #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u) /* Page is reclaimable */
    

    另外,来自kernel archives

    为了使代码更易于阅读,一组 添加了三个 GFP 标志,称为 GFP_PAGECACHE、GFP_NOFS_PAGECACHE 和 GFP_HIGHUSER_PAGECACHE。

    查看该页面上的差异源会显示您询问的标志是现有标志的组合:

     #define GFP_HIGHUSER_MOVABLE   (__GFP_WAIT | __GFP_IO | __GFP_FS | \
                     __GFP_HARDWALL | __GFP_HIGHMEM | \
                     __GFP_MOVABLE)
    +#define GFP_NOFS_PAGECACHE (__GFP_WAIT | __GFP_IO | __GFP_MOVABLE)
    +#define GFP_USER_PAGECACHE (__GFP_WAIT | __GFP_IO | __GFP_FS | \
    +                __GFP_HARDWALL | __GFP_MOVABLE)
    +#define GFP_HIGHUSER_PAGECACHE (__GFP_WAIT | __GFP_IO | __GFP_FS | \
    +                __GFP_HARDWALL | __GFP_HIGHMEM | \
    +                __GFP_MOVABLE)
    
     #ifdef CONFIG_NUMA
     #define GFP_THISNODE   (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY)
    

    【讨论】:

    • 是的,我看过这个文件......但我正在寻找的是一份详细描述标志的文档...... :)
    • 好的,编辑了额外的参考资料——应该是你需要的所有细节(以及更多)。
    猜你喜欢
    • 2016-08-04
    • 1970-01-01
    • 2017-08-08
    • 2021-09-17
    • 2019-06-02
    • 1970-01-01
    • 2012-07-29
    • 2017-02-17
    相关资源
    最近更新 更多