Chapter3:MemoryManagement
<gfp.h>
#define GFP_ATOMIC (__GFP_HIGH)
#define GFP_NOIO (__GFP_WAIT)
#define GFP_NOFS (__GFP_WAIT | __GFP_IO)
#define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS)
#define GFP_USER (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
#define GFP_HIGHUSER (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL | \
__GFP_HIGHMEM)
#define GFP_HIGHUSER_MOVABLE (__GFP_WAIT | __GFP_IO | __GFP_FS | \
__GFP_HARDWALL | __GFP_HIGHMEM | \
__GFP_MOVABLE)
#define GFP_DMA __GFP_DMA
#define GFP_DMA32 __GFP_DMA32
❑ The meaning of the first three combinations is clear.GFP_ATOMICis used for atomic allocations
that may not be interrupted on any account and may also draw on the ‘‘emergency reserves‘‘ of
memory.GFP_NOIOandGFP_NOFSexplicitly exclude I/O operations and access to the VFS layer,
respectively, but may be interrupted because__GFP_WAITis set.
❑ GFP_KERNELandGFP_USERare the default settings for kernel and user allocations, respectively.
Their failure is not an immediate threat to system stability.GFP_KERNELis far and away the most
frequently used flag in the kernel sources.
❑ GFP_HIGHUSERis an extension ofGFP_USERthat is also used on behalf of userspace. It also permits
the use of high-memory areas that can no longer be mapped directly. There is no disadvantage
to using highmem pages because the address space of user processes is always organized by
means of nonlinear page table assignments.GFP_HIGHUSER_MOVABLEis similar toGFP_HIGHUSER
in purpose, but allocations will besatisfied from the virtual zoneZONE_MOVABLE.
❑ GFP_DMAis used for DMA allocations and is currently a simple synonym for__GFP_DMA;
GFP_DMA32is likewise a synonym for__GFP_GMA32.
AllocationMacros
Through the use of flags, zone modifiers, and the various allocation functions, the kernel offers a very
flexible system of memory reservation. Nevertheless,all interface functions can be traced back to a single
base function (alloc_pages_node).
alloc_pageand__get_free_pagethat reserve a single page are defined with the help of macros, as is
alloc_pages.
<gfp.h>
#define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
...
#define __get_free_page(gfp_mask) \
__get_free_pages((gfp_mask),0)
<mm.h>
#define __get_dma_pages(gfp_mask, order) \
__get_free_pages((gfp_mask) | GFP_DMA,(order))
Neither is the implementation ofget_zeroed_pageparticularly difficult.alloc_pagesused with the
__GFP_ZEROflag reserves a page already filled with null bytes — only the address of the memory area
associated with the page need be returned.