Skip to content

Commit 79aa925

Browse files
mjkravetztorvalds
authored andcommitted
hugetlb_cgroup: fix reservation accounting
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]>
1 parent 46b1ee3 commit 79aa925

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
@@ -648,6 +648,8 @@ static long region_del(struct resv_map *resv, long f, long t)
648648
}
649649

650650
del += t - f;
651+
hugetlb_cgroup_uncharge_file_region(
652+
resv, rg, t - f);
651653

652654
/* New entry for end of split region */
653655
nrg->from = t;
@@ -660,9 +662,6 @@ static long region_del(struct resv_map *resv, long f, long t)
660662
/* Original entry is trimmed */
661663
rg->to = f;
662664

663-
hugetlb_cgroup_uncharge_file_region(
664-
resv, rg, nrg->to - nrg->from);
665-
666665
list_add(&nrg->link, &rg->link);
667666
nrg = NULL;
668667
break;
@@ -678,17 +677,17 @@ static long region_del(struct resv_map *resv, long f, long t)
678677
}
679678

680679
if (f <= rg->from) { /* Trim beginning of region */
681-
del += t - rg->from;
682-
rg->from = t;
683-
684680
hugetlb_cgroup_uncharge_file_region(resv, rg,
685681
t - rg->from);
686-
} else { /* Trim end of region */
687-
del += rg->to - f;
688-
rg->to = f;
689682

683+
del += t - rg->from;
684+
rg->from = t;
685+
} else { /* Trim end of region */
690686
hugetlb_cgroup_uncharge_file_region(resv, rg,
691687
rg->to - f);
688+
689+
del += rg->to - f;
690+
rg->to = f;
692691
}
693692
}
694693

@@ -2443,6 +2442,9 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
24432442

24442443
rsv_adjust = hugepage_subpool_put_pages(spool, 1);
24452444
hugetlb_acct_memory(h, -rsv_adjust);
2445+
if (deferred_reserve)
2446+
hugetlb_cgroup_uncharge_page_rsvd(hstate_index(h),
2447+
pages_per_huge_page(h), page);
24462448
}
24472449
return page;
24482450

0 commit comments

Comments
 (0)