diff options
authorZhou Guanghui <>2021-03-12 21:08:33 -0800
committerLinus Torvalds <>2021-03-13 11:27:31 -0800
commite1baddf8475b06cc56f4bafecf9a32a124343d9f (patch)
parentbe6c8982e4ab9a41907555f601b711a7e2a17d4c (diff)
mm/memcg: set memcg when splitting page
As described in the split_page() comment, for the non-compound high order page, the sub-pages must be freed individually. If the memcg of the first page is valid, the tail pages cannot be uncharged when be freed. For example, when alloc_pages_exact is used to allocate 1MB continuous physical memory, 2MB is charged(kmemcg is enabled and __GFP_ACCOUNT is set). When make_alloc_exact free the unused 1MB and free_pages_exact free the applied 1MB, actually, only 4KB(one page) is uncharged. Therefore, the memcg of the tail page needs to be set when splitting a page. Michel: There are at least two explicit users of __GFP_ACCOUNT with alloc_exact_pages added recently. See 7efe8ef274024 ("KVM: arm64: Allocate stage-2 pgd pages with GFP_KERNEL_ACCOUNT") and c419621873713 ("KVM: s390: Add memcg accounting to KVM allocations"), so this is not just a theoretical issue. Link: Signed-off-by: Zhou Guanghui <> Acked-by: Johannes Weiner <> Reviewed-by: Zi Yan <> Reviewed-by: Shakeel Butt <> Acked-by: Michal Hocko <> Cc: Hanjun Guo <> Cc: Hugh Dickins <> Cc: Kefeng Wang <> Cc: "Kirill A. Shutemov" <> Cc: Nicholas Piggin <> Cc: Rui Xiang <> Cc: Tianhong Ding <> Cc: Weilong Chen <> Cc: <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
1 files changed, 1 insertions, 0 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3cd1c0ce4d06..cfc72873961d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3314,6 +3314,7 @@ void split_page(struct page *page, unsigned int order)
for (i = 1; i < (1 << order); i++)
set_page_refcounted(page + i);
split_page_owner(page, 1 << order);
+ split_page_memcg(page, 1 << order);