Skip to content

Commit 2aad4ed

Browse files
Alexei Starovoitovakpm00
authored andcommitted
mm: rename try_alloc_pages() to alloc_pages_nolock()
The "try_" prefix is confusing, since it made people believe that try_alloc_pages() is analogous to spin_trylock() and NULL return means EAGAIN. This is not the case. If it returns NULL there is no reason to call it again. It will most likely return NULL again. Hence rename it to alloc_pages_nolock() to make it symmetrical to free_pages_nolock() and document that NULL means ENOMEM. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Acked-by: Johannes Weiner <[email protected]> Reviewed-by: Shakeel Butt <[email protected]> Acked-by: Harry Yoo <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Kumar Kartikeya Dwivedi <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Steven Rostedt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5fc4b77 commit 2aad4ed

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

include/linux/gfp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ static inline bool gfpflags_allow_spinning(const gfp_t gfp_flags)
4545
* !__GFP_DIRECT_RECLAIM -> direct claim is not allowed.
4646
* !__GFP_KSWAPD_RECLAIM -> it's not safe to wake up kswapd.
4747
* All GFP_* flags including GFP_NOWAIT use one or both flags.
48-
* try_alloc_pages() is the only API that doesn't specify either flag.
48+
* alloc_pages_nolock() is the only API that doesn't specify either flag.
4949
*
5050
* This is stronger than GFP_NOWAIT or GFP_ATOMIC because
5151
* those are guaranteed to never block on a sleeping lock.
5252
* Here we are enforcing that the allocation doesn't ever spin
5353
* on any locks (i.e. only trylocks). There is no high level
54-
* GFP_$FOO flag for this use in try_alloc_pages() as the
54+
* GFP_$FOO flag for this use in alloc_pages_nolock() as the
5555
* regular page allocator doesn't fully support this
5656
* allocation mode.
5757
*/
@@ -354,8 +354,8 @@ static inline struct page *alloc_page_vma_noprof(gfp_t gfp,
354354
}
355355
#define alloc_page_vma(...) alloc_hooks(alloc_page_vma_noprof(__VA_ARGS__))
356356

357-
struct page *try_alloc_pages_noprof(int nid, unsigned int order);
358-
#define try_alloc_pages(...) alloc_hooks(try_alloc_pages_noprof(__VA_ARGS__))
357+
struct page *alloc_pages_nolock_noprof(int nid, unsigned int order);
358+
#define alloc_pages_nolock(...) alloc_hooks(alloc_pages_nolock_noprof(__VA_ARGS__))
359359

360360
extern unsigned long get_free_pages_noprof(gfp_t gfp_mask, unsigned int order);
361361
#define __get_free_pages(...) alloc_hooks(get_free_pages_noprof(__VA_ARGS__))

kernel/bpf/syscall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static bool can_alloc_pages(void)
578578
static struct page *__bpf_alloc_page(int nid)
579579
{
580580
if (!can_alloc_pages())
581-
return try_alloc_pages(nid, 0);
581+
return alloc_pages_nolock(nid, 0);
582582

583583
return alloc_pages_node(nid,
584584
GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT

mm/page_alloc.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5070,7 +5070,7 @@ EXPORT_SYMBOL(__free_pages);
50705070

50715071
/*
50725072
* Can be called while holding raw_spin_lock or from IRQ and NMI for any
5073-
* page type (not only those that came from try_alloc_pages)
5073+
* page type (not only those that came from alloc_pages_nolock)
50745074
*/
50755075
void free_pages_nolock(struct page *page, unsigned int order)
50765076
{
@@ -7311,20 +7311,21 @@ static bool __free_unaccepted(struct page *page)
73117311
#endif /* CONFIG_UNACCEPTED_MEMORY */
73127312

73137313
/**
7314-
* try_alloc_pages - opportunistic reentrant allocation from any context
7314+
* alloc_pages_nolock - opportunistic reentrant allocation from any context
73157315
* @nid: node to allocate from
73167316
* @order: allocation order size
73177317
*
73187318
* Allocates pages of a given order from the given node. This is safe to
73197319
* call from any context (from atomic, NMI, and also reentrant
7320-
* allocator -> tracepoint -> try_alloc_pages_noprof).
7320+
* allocator -> tracepoint -> alloc_pages_nolock_noprof).
73217321
* Allocation is best effort and to be expected to fail easily so nobody should
73227322
* rely on the success. Failures are not reported via warn_alloc().
73237323
* See always fail conditions below.
73247324
*
7325-
* Return: allocated page or NULL on failure.
7325+
* Return: allocated page or NULL on failure. NULL does not mean EBUSY or EAGAIN.
7326+
* It means ENOMEM. There is no reason to call it again and expect !NULL.
73267327
*/
7327-
struct page *try_alloc_pages_noprof(int nid, unsigned int order)
7328+
struct page *alloc_pages_nolock_noprof(int nid, unsigned int order)
73287329
{
73297330
/*
73307331
* Do not specify __GFP_DIRECT_RECLAIM, since direct claim is not allowed.
@@ -7333,7 +7334,7 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
73337334
*
73347335
* These two are the conditions for gfpflags_allow_spinning() being true.
73357336
*
7336-
* Specify __GFP_NOWARN since failing try_alloc_pages() is not a reason
7337+
* Specify __GFP_NOWARN since failing alloc_pages_nolock() is not a reason
73377338
* to warn. Also warn would trigger printk() which is unsafe from
73387339
* various contexts. We cannot use printk_deferred_enter() to mitigate,
73397340
* since the running context is unknown.
@@ -7343,7 +7344,7 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
73437344
* BPF use cases.
73447345
*
73457346
* Though __GFP_NOMEMALLOC is not checked in the code path below,
7346-
* specify it here to highlight that try_alloc_pages()
7347+
* specify it here to highlight that alloc_pages_nolock()
73477348
* doesn't want to deplete reserves.
73487349
*/
73497350
gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC

mm/page_owner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void __reset_page_owner(struct page *page, unsigned short order)
302302
/*
303303
* Do not specify GFP_NOWAIT to make gfpflags_allow_spinning() == false
304304
* to prevent issues in stack_depot_save().
305-
* This is similar to try_alloc_pages() gfp flags, but only used
305+
* This is similar to alloc_pages_nolock() gfp flags, but only used
306306
* to signal stack_depot to avoid spin_locks.
307307
*/
308308
handle = save_stack(__GFP_NOWARN);

0 commit comments

Comments
 (0)