Skip to content

Commit 99ba8d4

Browse files
committed
hugetlb_cgroup: fix reservation accounting
jira NONE_AUTOMATION Rebuild_History Non-Buildable kernel-rt-4.18.0-348.20.1.rt7.150.el8_5 commit-author Mike Kravetz <[email protected]> commit 79aa925 Michal Privoznik was using "free page reporting" in QEMU/virtio-balloon with hugetlbfs and hit the warning below. QEMU with free page hinting uses fallocate(FALLOC_FL_PUNCH_HOLE) to discard pages that are reported as free by a VM. The reporting granularity is in pageblock granularity. So when the guest reports 2M chunks, we fallocate(FALLOC_FL_PUNCH_HOLE) one huge page in QEMU. WARNING: CPU: 7 PID: 6636 at mm/page_counter.c:57 page_counter_uncharge+0x4b/0x50 Modules linked in: ... CPU: 7 PID: 6636 Comm: qemu-system-x86 Not tainted 5.9.0 #137 Hardware name: Gigabyte Technology Co., Ltd. X570 AORUS PRO/X570 AORUS PRO, BIOS F21 07/31/2020 RIP: 0010:page_counter_uncharge+0x4b/0x50 ... Call Trace: hugetlb_cgroup_uncharge_file_region+0x4b/0x80 region_del+0x1d3/0x300 hugetlb_unreserve_pages+0x39/0xb0 remove_inode_hugepages+0x1a8/0x3d0 hugetlbfs_fallocate+0x3c4/0x5c0 vfs_fallocate+0x146/0x290 __x64_sys_fallocate+0x3e/0x70 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Investigation of the issue uncovered bugs in hugetlb cgroup reservation accounting. This patch addresses the found issues. Fixes: 075a61d ("hugetlb_cgroup: add accounting for shared mappings") Reported-by: Michal Privoznik <[email protected]> Co-developed-by: David Hildenbrand <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Signed-off-by: Mike Kravetz <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Tested-by: Michal Privoznik <[email protected]> Reviewed-by: Mina Almasry <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Cc: <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: "Aneesh Kumar K . V" <[email protected]> Cc: Tejun Heo <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]> (cherry picked from commit 79aa925) Signed-off-by: Jonathan Maple <[email protected]>
1 parent bd0b87b commit 99ba8d4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

mm/hugetlb.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ static long region_del(struct resv_map *resv, long f, long t)
643643
}
644644

645645
del += t - f;
646+
hugetlb_cgroup_uncharge_file_region(
647+
resv, rg, t - f);
646648

647649
/* New entry for end of split region */
648650
nrg->from = t;
@@ -655,9 +657,6 @@ static long region_del(struct resv_map *resv, long f, long t)
655657
/* Original entry is trimmed */
656658
rg->to = f;
657659

658-
hugetlb_cgroup_uncharge_file_region(
659-
resv, rg, nrg->to - nrg->from);
660-
661660
list_add(&nrg->link, &rg->link);
662661
nrg = NULL;
663662
break;
@@ -673,17 +672,17 @@ static long region_del(struct resv_map *resv, long f, long t)
673672
}
674673

675674
if (f <= rg->from) { /* Trim beginning of region */
676-
del += t - rg->from;
677-
rg->from = t;
678-
679675
hugetlb_cgroup_uncharge_file_region(resv, rg,
680676
t - rg->from);
681-
} else { /* Trim end of region */
682-
del += rg->to - f;
683-
rg->to = f;
684677

678+
del += t - rg->from;
679+
rg->from = t;
680+
} else { /* Trim end of region */
685681
hugetlb_cgroup_uncharge_file_region(resv, rg,
686682
rg->to - f);
683+
684+
del += rg->to - f;
685+
rg->to = f;
687686
}
688687
}
689688

@@ -2364,6 +2363,9 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
23642363

23652364
rsv_adjust = hugepage_subpool_put_pages(spool, 1);
23662365
hugetlb_acct_memory(h, -rsv_adjust);
2366+
if (deferred_reserve)
2367+
hugetlb_cgroup_uncharge_page_rsvd(hstate_index(h),
2368+
pages_per_huge_page(h), page);
23672369
}
23682370
return page;
23692371

0 commit comments

Comments
 (0)