Obviously we only support order <= 1 __GFP_NOFAIL allocation and if someone wants larger memory, they should consider using kvmalloc() instead. Suggested-by: David Hildenbrand <david@xxxxxxxxxx> Suggested-by: Michal Hocko <mhocko@xxxxxxxx> Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx> --- include/linux/gfp_types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index 4a1fa7706b0c..65db9349f905 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -253,7 +253,8 @@ enum { * used only when there is no reasonable failure policy) but it is * definitely preferable to use the flag rather than opencode endless * loop around allocator. - * Using this flag for costly allocations is _highly_ discouraged. + * Allocating pages from the buddy with __GFP_NOFAIL and order > 1 is + * not supported. Please consider using kvmalloc() instead. */ #define __GFP_IO ((__force gfp_t)___GFP_IO) #define __GFP_FS ((__force gfp_t)___GFP_FS) -- 2.34.1 > > > --- > > Â mm/page_alloc.c | 50 ++++++++++++++++++++++++------------------------- > > Â 1 file changed, 25 insertions(+), 25 deletions(-) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index c81ee5662cc7..e790b4227322 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -3033,12 +3033,6 @@ struct page *rmqueue(struct zone *preferred_zone, > > Â { > > Â Â Â struct page *page; > > > > - Â Â /* > > - Â Â Â * We most definitely don't want callers attempting to > > - Â Â Â * allocate greater than order-1 page units with __GFP_NOFAIL. > > - Â Â Â */ > > - Â Â WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1)); > > - > > Â Â Â if (likely(pcp_allowed_order(order))) { > > Â Â Â Â Â Â Â page = rmqueue_pcplist(preferred_zone, zone, order, > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â migratetype, alloc_flags); > > @@ -4175,6 +4169,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > > Â { > > Â Â Â bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM; > > Â Â Â bool can_compact = gfp_compaction_allowed(gfp_mask); > > + Â Â bool nofail = gfp_mask & __GFP_NOFAIL; > > Â Â Â const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER; > > Â Â Â struct page *page = NULL; > > Â Â Â unsigned int alloc_flags; > > @@ -4187,6 +4182,25 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > > Â Â Â unsigned int zonelist_iter_cookie; > > Â Â Â int reserve_flags; > > > > + Â Â if (unlikely(nofail)) { > > + Â Â Â Â Â Â /* > > + Â Â Â Â Â Â Â * We most definitely don't want callers attempting to > > + Â Â Â Â Â Â Â * allocate greater than order-1 page units with __GFP_NOFAIL. > > + Â Â Â Â Â Â Â */ > > + Â Â Â Â Â Â WARN_ON_ONCE(order > 1); > > + Â Â Â Â Â Â /* > > + Â Â Â Â Â Â Â * Also we don't support __GFP_NOFAIL without __GFP_DIRECT_RECLAIM, > > + Â Â Â Â Â Â Â * otherwise, we may result in lockup. > > + Â Â Â Â Â Â Â */ > > + Â Â Â Â Â Â WARN_ON_ONCE(!can_direct_reclaim); > > + Â Â Â Â Â Â /* > > + Â Â Â Â Â Â Â * PF_MEMALLOC request from this context is rather bizarre > > + Â Â Â Â Â Â Â * because we cannot reclaim anything and only can loop waiting > > + Â Â Â Â Â Â Â * for somebody to do a work for us. > > + Â Â Â Â Â Â Â */ > > + Â Â Â Â Â Â WARN_ON_ONCE(current->flags & PF_MEMALLOC); > > + Â Â } > > + > > Â restart: > > Â Â Â compaction_retries = 0; > > Â Â Â no_progress_loops = 0; > > @@ -4404,29 +4418,15 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > > Â Â Â Â * Make sure that __GFP_NOFAIL request doesn't leak out and make sure > > Â Â Â Â * we always retry > > Â Â Â Â */ > > - Â Â if (gfp_mask & __GFP_NOFAIL) { > > + Â Â if (unlikely(nofail)) { > > Â Â Â Â Â Â Â /* > > - Â Â Â Â Â Â Â * All existing users of the __GFP_NOFAIL are blockable, so warn > > - Â Â Â Â Â Â Â * of any new users that actually require GFP_NOWAIT > > + Â Â Â Â Â Â Â * Lacking direct_reclaim we can't do anything to reclaim memory, > > + Â Â Â Â Â Â Â * we disregard these unreasonable nofail requests and still > > + Â Â Â Â Â Â Â * return NULL > > Â Â Â Â Â Â Â Â */ > > - Â Â Â Â Â Â if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) > > + Â Â Â Â Â Â if (!can_direct_reclaim) > > Â Â Â Â Â Â Â Â Â Â Â goto fail; > > > > - Â Â Â Â Â Â /* > > - Â Â Â Â Â Â Â * PF_MEMALLOC request from this context is rather bizarre > > - Â Â Â Â Â Â Â * because we cannot reclaim anything and only can loop waiting > > - Â Â Â Â Â Â Â * for somebody to do a work for us > > - Â Â Â Â Â Â Â */ > > - Â Â Â Â Â Â WARN_ON_ONCE_GFP(current->flags & PF_MEMALLOC, gfp_mask); > > - > > - Â Â Â Â Â Â /* > > - Â Â Â Â Â Â Â * non failing costly orders are a hard requirement which we > > - Â Â Â Â Â Â Â * are not prepared for much so let's warn about these users > > - Â Â Â Â Â Â Â * so that we can identify them and convert them to something > > - Â Â Â Â Â Â Â * else. > > - Â Â Â Â Â Â Â */ > > - Â Â Â Â Â Â WARN_ON_ONCE_GFP(costly_order, gfp_mask); > > - > > Â Â Â Â Â Â Â /* > > Â Â Â Â Â Â Â Â * Help non-failing allocations by giving some access to memory > > Â Â Â Â Â Â Â Â * reserves normally used for high priority non-blocking > > -- > > 2.34.1 > > -- > Michal Hocko > SUSE Labs Thanks Barry