Skip to content

Commit 00bafa5

Browse files
rpptJonathan Corbet
authored andcommitted
docs/core-api: memory-allocation: describe reclaim behaviour
Changelog of commit dcda9b0 ("mm, tree wide: replace __GFP_REPEAT by __GFP_RETRY_MAYFAIL with more useful semantic") has very nice description of GFP flags that affect reclaim behaviour of the page allocator. It would be pity to keep this description buried in the log so let's expose it in the Documentation/ as well. Cc: Michal Hocko <[email protected]> Acked-by: Michal Hocko <[email protected]> Signed-off-by: Mike Rapoport <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 2ed1761 commit 00bafa5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Documentation/core-api/memory-allocation.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,50 @@ driver for a device with such restrictions, avoid using these flags.
8484
And even with hardware with restrictions it is preferable to use
8585
`dma_alloc*` APIs.
8686

87+
GFP flags and reclaim behavior
88+
------------------------------
89+
Memory allocations may trigger direct or background reclaim and it is
90+
useful to understand how hard the page allocator will try to satisfy that
91+
or another request.
92+
93+
* ``GFP_KERNEL & ~__GFP_RECLAIM`` - optimistic allocation without _any_
94+
attempt to free memory at all. The most light weight mode which even
95+
doesn't kick the background reclaim. Should be used carefully because it
96+
might deplete the memory and the next user might hit the more aggressive
97+
reclaim.
98+
99+
* ``GFP_KERNEL & ~__GFP_DIRECT_RECLAIM`` (or ``GFP_NOWAIT``)- optimistic
100+
allocation without any attempt to free memory from the current
101+
context but can wake kswapd to reclaim memory if the zone is below
102+
the low watermark. Can be used from either atomic contexts or when
103+
the request is a performance optimization and there is another
104+
fallback for a slow path.
105+
106+
* ``(GFP_KERNEL|__GFP_HIGH) & ~__GFP_DIRECT_RECLAIM`` (aka ``GFP_ATOMIC``) -
107+
non sleeping allocation with an expensive fallback so it can access
108+
some portion of memory reserves. Usually used from interrupt/bottom-half
109+
context with an expensive slow path fallback.
110+
111+
* ``GFP_KERNEL`` - both background and direct reclaim are allowed and the
112+
**default** page allocator behavior is used. That means that not costly
113+
allocation requests are basically no-fail but there is no guarantee of
114+
that behavior so failures have to be checked properly by callers
115+
(e.g. OOM killer victim is allowed to fail currently).
116+
117+
* ``GFP_KERNEL | __GFP_NORETRY`` - overrides the default allocator behavior
118+
and all allocation requests fail early rather than cause disruptive
119+
reclaim (one round of reclaim in this implementation). The OOM killer
120+
is not invoked.
121+
122+
* ``GFP_KERNEL | __GFP_RETRY_MAYFAIL`` - overrides the default allocator
123+
behavior and all allocation requests try really hard. The request
124+
will fail if the reclaim cannot make any progress. The OOM killer
125+
won't be triggered.
126+
127+
* ``GFP_KERNEL | __GFP_NOFAIL`` - overrides the default allocator behavior
128+
and all allocation requests will loop endlessly until they succeed.
129+
This might be really dangerous especially for larger orders.
130+
87131
Selecting memory allocator
88132
==========================
89133

0 commit comments

Comments
 (0)