Skip to content

Commit 17d7542

Browse files
Barry Songakpm00
authored andcommitted
mm: document __GFP_NOFAIL must be blockable
Non-blocking allocation with __GFP_NOFAIL is not supported and may still result in NULL pointers (if we don't return NULL, we result in busy-loop within non-sleepable contexts): static inline struct page * __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, struct alloc_context *ac) { ... /* * Make sure that __GFP_NOFAIL request doesn't leak out and make sure * we always retry */ if (gfp_mask & __GFP_NOFAIL) { /* * All existing users of the __GFP_NOFAIL are blockable, so warn * of any new users that actually require GFP_NOWAIT */ if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) goto fail; ... } ... fail: warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: return page; } Highlight this in the documentation of __GFP_NOFAIL so that non-mm subsystems can reject any illegal usage of __GFP_NOFAIL with GFP_ATOMIC, GFP_NOWAIT, etc. Link: https://lkml.kernel.org/r/20240830202823.21478-3-21cnbao@gmail.com Signed-off-by: Barry Song <v-songbaohua@oppo.com> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Davidlohr Bueso <dave@stgolabs.net> Acked-by: David Hildenbrand <david@redhat.com> Cc: Christoph Lameter <cl@linux.com> Cc: David Rientjes <rientjes@google.com> Cc: "Eugenio Pérez" <eperezma@redhat.com> Cc: Hailong.Liu <hailong.liu@oppo.com> Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Kees Cook <kees@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Maxime Coquelin <maxime.coquelin@redhat.com> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Xie Yongji <xieyongji@bytedance.com> Cc: Yafang Shao <laoar.shao@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 955abe0 commit 17d7542

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

include/linux/gfp_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ enum {
215215
* the caller still has to check for failures) while costly requests try to be
216216
* not disruptive and back off even without invoking the OOM killer.
217217
* The following three modifiers might be used to override some of these
218-
* implicit rules.
218+
* implicit rules. Please note that all of them must be used along with
219+
* %__GFP_DIRECT_RECLAIM flag.
219220
*
220221
* %__GFP_NORETRY: The VM implementation will try only very lightweight
221222
* memory direct reclaim to get some memory under memory pressure (thus
@@ -246,6 +247,8 @@ enum {
246247
* cannot handle allocation failures. The allocation could block
247248
* indefinitely but will never return with failure. Testing for
248249
* failure is pointless.
250+
* It _must_ be blockable and used together with __GFP_DIRECT_RECLAIM.
251+
* It should _never_ be used in non-sleepable contexts.
249252
* New users should be evaluated carefully (and the flag should be
250253
* used only when there is no reasonable failure policy) but it is
251254
* definitely preferable to use the flag rather than opencode endless

0 commit comments

Comments
 (0)