mm/page_alloc: ensure try_alloc_pages() plays well with unaccepted memory
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Tue, 6 May 2025 11:25:08 +0000 (14:25 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 12 May 2025 00:26:07 +0000 (17:26 -0700)
commit23fa022a07555a9cd2dcfe827c769a89c4c2e21e
treecd907fc4082c11408862647b48c6573ac15d69f9
parentd55582d6c947a195ed48a1893ba23d2f077bf224
mm/page_alloc: ensure try_alloc_pages() plays well with unaccepted memory

try_alloc_pages() will not attempt to allocate memory if the system has
*any* unaccepted memory.  Memory is accepted as needed and can remain in
the system indefinitely, causing the interface to always fail.

Rather than immediately giving up, attempt to use already accepted memory
on free lists.

Pass 'alloc_flags' to cond_accept_memory() and do not accept new memory
for ALLOC_TRYLOCK requests.

Found via code inspection - only BPF uses this at present and the
runtime effects are unclear.

Link: https://lkml.kernel.org/r/20250506112509.905147-2-kirill.shutemov@linux.intel.com
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation")
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/page_alloc.c