Skip to content

Commit e8d78db

Browse files
author
Alexei Starovoitov
committed
mm, bpf: Use memcg in try_alloc_pages().
Unconditionally use __GFP_ACCOUNT in try_alloc_pages(). The caller is responsible to setup memcg correctly. All BPF memory accounting is memcg based. Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Shakeel Butt <shakeel.butt@linux.dev> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/r/20250222024427.30294-6-alexei.starovoitov@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 01d3722 commit e8d78db

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mm/page_alloc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7190,7 +7190,8 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
71907190
* specify it here to highlight that try_alloc_pages()
71917191
* doesn't want to deplete reserves.
71927192
*/
7193-
gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC;
7193+
gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC
7194+
| __GFP_ACCOUNT;
71947195
unsigned int alloc_flags = ALLOC_TRYLOCK;
71957196
struct alloc_context ac = { };
71967197
struct page *page;
@@ -7234,6 +7235,11 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
72347235

72357236
/* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */
72367237

7238+
if (memcg_kmem_online() && page &&
7239+
unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) {
7240+
free_pages_nolock(page, order);
7241+
page = NULL;
7242+
}
72377243
trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype);
72387244
kmsan_alloc_page(page, order, alloc_gfp);
72397245
return page;

0 commit comments

Comments
 (0)