c - 应该使用哪个 kmalloc 标志

标签 c linux linux-kernel embedded-linux kmalloc

我一直在到处寻找一个文档,解释何时使用 kmalloc 的每个标志。我发现this reference这很好地解释了何时使用某些标志,但我找不到其他标志,例如 GFP_HIGHUSER_PAGECACHEGFP_HIGHUSER_MOVABLE 以及 gfp.h 中的其他标志> 头文件...有人可以告诉我何时使用这些其他标志吗?

最佳答案

您想要 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 :

To make code easier to read, a set of three GFP flags are added called GFP_PAGECACHE, GFP_NOFS_PAGECACHE and 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)

关于c - 应该使用哪个 kmalloc 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5216173/

相关文章:

Python 操作系统错误 : [Errno 2] No such file or directory ERROR

c++ - PTRACE_SYSCALL 和 orig_eax

linux - 如何使用Grub Legacy从CDROM引导uppylinux

linux-kernel - 如何从 ARM v7 上的 Linux 内核空间刷新 L1 和 L2 缓存中的地址范围?

c - fseek 在打开的文件指针上失败

c - 如何生成 n 个线程?

c - 在这种情况下,循环顺序如何影响 C 中的位操作?

c - 使用 libcurl 检索到的 header 信息来确定文件名

linux - bash命令强制关闭USB驱动器上的文件

linux - 如何从 Linux 内核模块的 sysfs 属性文件中读取字符串?