From: Jinjiang Tu Date: Tue, 25 Feb 2025 14:19:33 +0000 (+0800) Subject: mm/hugetlb: fix set_max_huge_pages() when there are surplus pages X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=554d249d50d208d999c1c63ec49f556e7eaf1a8d;p=users%2Fjedix%2Flinux-maple.git mm/hugetlb: fix set_max_huge_pages() when there are surplus pages In set_max_huge_pages(), min_count should mean the acquired persistent huge pages, but it contains surplus huge pages. It will lead to failing to free free huge pages for a node. Steps to reproduce: 1) create 5 huge pages in Node 0 2) run a program to use all the huge pages 3) create 5 huge pages in Node 1 4) echo 0 > nr_hugepages for Node 1 to free the huge pages The result: Node 0 Node 1 Total 5 5 Free 0 5 Surp 5 5 With this patch, step 4) destroys the 5 huge pages in Node 1 The result with this patch: Node 0 Node 1 Total 5 0 Free 0 0 Surp 5 0 Link: https://lkml.kernel.org/r/20250225141933.3852667-1-tujinjiang@huawei.com Fixes: 9a30523066cd ("hugetlb: add per node hstate attributes") Signed-off-by: Jinjiang Tu Cc: Andi Kleen Cc: David Hildenbrand Cc: Lee Schermerhorn Cc: Mel Gorman Cc: Muchun Song Cc: Oscar Salvador Signed-off-by: Andrew Morton --- diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9faa1034704f..c4b7e5b26bed 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3933,7 +3933,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, * and won't grow the pool anywhere else. Not until one of the * sysctls are changed, or the surplus pages go out of use. */ - min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages; + min_count = h->resv_huge_pages + persistent_huge_pages(h) - h->free_huge_pages; min_count = max(count, min_count); try_to_free_low(h, min_count, nodes_allowed);