memorylinux-kernelkmalloc

What's the "right" way to use GFP_ZERO in latest kernels?


I found that on linux 3.0+ GFP_ZERO is no longer defined in headers.

All I found in gfp.h was,

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

I've checked those "exported" bit masks, on one uses GFP_ZERO.

And the author says Do not use this directly, so, how should I get zeroed page,

Is kmalloc + memset the only option I have now?


Solution

  • I think the expected way to zero is kzalloc():

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

    but obviously alloc + memset works too.

    Update

    Sample diff from CFQ showing the expected updates:

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

    See also this: https://stackoverflow.com/a/12095263/2908724