Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Some of the constants shown are used only in rare situations, so I won’t discuss them. The meanings of
the most important constants are as follows:


❑ __GFP_WAITindicates that the memory request may be interrupted; that is, the scheduler is free
to select another process during the request, or the request can be interrupted by a more impor-
tant event. The allocator is also permitted to wait for an event on a queue (and to put the process
to sleep) before memory is returned.
❑ __GFP_HIGHis set if the request is very important, that is, when the kernel urgently needs mem-
ory. This flag is always used when failure to allocate memory would have massive consequences
for the kernel resulting in a threat to system stability or even a system crash.

Despite the similarity in name,__GFP_HIGHhas nothing to do with__GFP_HIGHMEM
and must not be confused with it.

❑ __GFP_IOspecifies that the kernel can perform I/O operations during an attempt to find fresh
memory. In real terms, this means that if the kernel begins to swap out pages during memory
allocation, the selected pages may be written to hard disk only if this flag is set.
❑ __GFP_FSallows the kernel to perform VFS operations. This must be prevented in kernel layers
linked with the VFS layer because interactions of this kind could cause endless recursive calls.
❑ __GFP_COLDis set if allocation of a ‘‘cold‘‘ page that isnotresident in the CPU cache is required.
❑ __GFP_NOWARNsuppresses a kernel failure warning if allocation fails. There are very few occa-
sions when this flag is useful.
❑ __GFP_REPEATautomatically retries a failed allocation but stops after a few attempts.
__GFP_NOFAILretries the failed allocation until it succeeds.
❑ __GFP_ZEROreturns a page filled with zero bytes if allocation succeeds.
❑ __GFP_HARDWALLis meaningful on NUMA systems only. It limits memory allocation to the nodes
associated with the CPUs assigned to a process. The flag is meaningless if a process is allowed to
run on all CPUs (this is the default). It only has an explicit effect if the CPUs on which a process
may run are limited.
❑ __GFP_THISNODEalso only makes sense on NUMA systems. If the bit is set, then fallback to other
nodes is not permitted, and memory is guaranteed to be allocated on either the current node or
on an explicitly specified node.
❑ __GFP_RECLAIMABLEand__GFP_MOVABLEare required by the page mobility mechanism.
As their names indicate, they mark that the allocated memory will be reclaimable or mov-
able, respectively. This influences from which sublist of the freelist the page or pages will
be taken.

As the flags are used in combination and hardly ever on their own, the kernel classifies them into groups
containing appropriate flags for a variety of standard situations. If at all possible, one of the follow-
ing groups should always be used for memory allocation outside of memory management itself. (This
requirement is reinforced by the fact that the names of the predefined groups do not begin with a double
underscore — the usual convention for internal data and definitions in the kernel sources.)

Free download pdf