Skip to content

Commit 7f8f18d

Browse files
committed
mm, bpf: Use memcg in try_alloc_pages().
JIRA: https://issues.redhat.com/browse/RHEL-78202 commit e8d78db Author: Alexei Starovoitov <ast@kernel.org> Date: Fri Feb 21 18:44:26 2025 -0800 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> Signed-off-by: Gregory Bell <grbell@redhat.com>
1 parent 1fc07c3 commit 7f8f18d

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
@@ -7176,7 +7176,8 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
71767176
* specify it here to highlight that try_alloc_pages()
71777177
* doesn't want to deplete reserves.
71787178
*/
7179-
gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC;
7179+
gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC
7180+
| __GFP_ACCOUNT;
71807181
unsigned int alloc_flags = ALLOC_TRYLOCK;
71817182
struct alloc_context ac = { };
71827183
struct page *page;
@@ -7220,6 +7221,11 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order)
72207221

72217222
/* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */
72227223

7224+
if (memcg_kmem_online() && page &&
7225+
unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) {
7226+
free_pages_nolock(page, order);
7227+
page = NULL;
7228+
}
72237229
trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype);
72247230
kmsan_alloc_page(page, order, alloc_gfp);
72257231
return page;

0 commit comments

Comments
 (0)