From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E13D3E2778 for ; Fri, 15 May 2026 20:29:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778876951; cv=none; b=myjsYei8Fa5Jf871lqh+Frww5mBFkikBh59kfFUOenmsjP3mgQyomob7U8q4edTGZYaWAQxgPDfq192u1v9CdWYj2xrOd2XjIWguX8YaOyoEJrwREaNAS67iyFPDa2PMaYxUmxGGWDZUlP8YmkXXw/PdgJn2pAowB9fwPa/fuc0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778876951; c=relaxed/simple; bh=QO6Y6YhH1LVeqeFD6+YWOTp74M9wQObDTIqOFlYfkdA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=n1JI9Kozy6RgwoKXQWRmGlbrdwjcnwRm0x58t9rvKpdMQ1C1wJKn7E9UngHJytgt89h/7lRs2VQnQDX5uPrGyqwD7todJeyxMSsLKzjdD4knW4fFelDURaFinenEk1xDk9JTYnNAPdbdp8OsbUQIFyrM7/1/CRyBDOqeaidhYm8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Id9Gsgf4; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Id9Gsgf4" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-488b0046078so1858075e9.1 for ; Fri, 15 May 2026 13:29:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778876946; x=1779481746; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hB4x7rO0kWraX/2vch0MYRJ2VJ/csAYjyg45Hf0A9bM=; b=Id9Gsgf4xo+DkOyIjRCfrGHsdNgvHrYDSYMtsR14oMjssim8kmGWVwlxZZ3Fi0re5t jTituTfduv4P1yCCC0z7vY74+XrNaFE/8nsuMYZOEZNpnyeS4/gVGmiLzuMSmPMQeR5W /5JfWvsRK/f7ue0bKMyv0l2FDEVuRDs0QyKSan8pqdQfLVVxIhJXPF0Y5kR58b1WpX/r MVvG0ZdbfZxe8jKJb9qLRgIPC3WuECBmK0BE2JP8b6MkH+z78JupJig+lfrmIDVg2GDI tuACxCCa8HFbmvr/4pOMJudMTYKzNRbdGk3deTCHArknmqcbA3CaNJxI+fLjBKLCgU3r xNIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778876946; x=1779481746; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hB4x7rO0kWraX/2vch0MYRJ2VJ/csAYjyg45Hf0A9bM=; b=rNW0B/t+d2rK8SBDqLxos8KjBqnMRqgFq4mCZkbwJGuA7jg+qsHwdlDyvxpvHokvVY q8pljrIwDVF07XPySRRo4/+hrdaCBREZQ0C1SKNJsDTe9jM3GW1ujx/ffwWAl1eaf69d R/HG6YaeLAY7TYQUPgAoh3p2pjwhuohOeMwM/c+BnldCn+vYONP8tlyNPrHz0I9yXUPe G3gXEHaKDC7ESKJcygECAyf6Gy28M03Oj4Hbc4MxB+0/TtEfWNnXHgNvaTijHL6CcC7o qPGNjpsun3F1YKR5lRXHABmxHQ+H05RlMhZvXugUTVfNHpEhe0YDB4ZN+7t0cQpyw8qa cs/Q== X-Forwarded-Encrypted: i=1; AFNElJ84j/X6g0Cy8sOi43zI2UY8BRXXxVq7cbWev1gyExejFd52XupOdyXu96hHDicbBhmGdL+gnrQSi/tlxu8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4jkIq9qTBsh+fWLRPAtOU6Auw4FUKotFcdXoxcfNyWfuyexVR J/0iyKo+vnEF4hf/Khout+GfMgqw9yFpDUNKMlyS/NCIWIFDkPp9t7Dd X-Gm-Gg: Acq92OFORKLlAucLxsb7MesSj0+uoCTwtNNiJonGm0Xl5OsEnDfQCgazNcKnO+xzinF N2+BHecGtzPPENXSmJc6o2K+HgkvEqV0c0v4AG8QOsnZeXoDjauoYWei/Rvo20NUsR8hn2ntMQM OtuRIjbtGeTWmREElG6SBubZuB/kQxU8jSMBSW30ZUMJc/v3iFeal5M8XJnwpnyR8b6oXi59nyK PXc5h1bRZVIws/PKwRRT0QGmhAckYT/YwfjBdpcdAZu0TaoJQK5zJ129xTHOkWajMUcy2wE6Thq dGvB7f0uIfQVq0NGBm1grETHzb09lZdYjGMuDUj/oRStCRz4P68F2OjFmVESihBhDJtI2p0ReNZ cNGI7NsN8A0u/4VVj1GKgX3IMkN9wUs41eMjUxj8sMsqxuRvXjxSolNZ+pOeQ8dPPRAn2Dj8U/5 qxql5GQ/HLwPE018gAqu3JPE+hiDtkMJ3Nog/qk5MhxXdacAreoaEt96HquzZ40h4iE2inOIlqI oCSAQ/Mj3SeQijdHyFieQ== X-Received: by 2002:a05:600c:a406:b0:48f:e230:1d12 with SMTP id 5b1f17b1804b1-48fe6329913mr66632025e9.31.1778876945902; Fri, 15 May 2026 13:29:05 -0700 (PDT) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45da0fe0f72sm18422463f8f.25.2026.05.15.13.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 13:29:05 -0700 (PDT) From: David Carlier To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: muchun.song@linux.dev, osalvador@suse.de, david@kernel.org, joshua.hahnjy@gmail.com, mawupeng1@huawei.com, stable@vger.kernel.org, linux-kernel@vger.kernel.org, David Carlier Subject: [PATCH] mm/hugetlb: restore subpool used_hpages on alloc_hugetlb_folio error Date: Fri, 15 May 2026 21:29:02 +0100 Message-ID: <20260515202902.461539-1-devnexen@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit a833a693a490 added a !gbl_chg guard around the hugepage_subpool_put_pages() call in alloc_hugetlb_folio()'s out_subpool_put path so a failed allocation wouldn't drive h->resv_huge_pages negative. But hugepage_subpool_get_pages() increments spool->used_hpages whenever max_hpages != -1, regardless of whether the request was satisfied from subpool reserves or needs global pages. When gbl_chg > 0 and a later step fails (cgroup charge, dequeue, buddy alloc), used_hpages is never put back. Each such failure leaks one count; eventually used_hpages reaches max_hpages and the subpool refuses every further allocation even though no pages are held. Commit 1d3f9bb4c8af fixed the same defect in hugetlb_reserve_pages(); apply the equivalent restore here, guarded by spool and max_hpages. Fixes: a833a693a490 ("mm: hugetlb: fix incorrect fallback for subpool") Signed-off-by: David Carlier Cc: Joshua Hahn Cc: Wupeng Ma Cc: Oscar Salvador Cc: Muchun Song Cc: David Hildenbrand Cc: --- mm/hugetlb.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index cfb7cb2e9806..9614330889de 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3010,9 +3010,22 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, * put page to subpool iff the quota of subpool's rsv_hpages is used * during hugepage_subpool_get_pages. */ - if (map_chg && !gbl_chg) { - gbl_reserve = hugepage_subpool_put_pages(spool, 1); - hugetlb_acct_memory(h, -gbl_reserve); + if (map_chg) { + /* + * Put used_hpages back for the global portion of the request that + * was never actually consumed; restore the subpool-reservation + * portion via hugepage_subpool_put_pages() so rsv_hpages is rebuilt. + */ + if (!gbl_chg) { + gbl_reserve = hugepage_subpool_put_pages(spool, 1); + hugetlb_acct_memory(h, -gbl_reserve); + } else if (spool && spool->max_hpages != -1) { + unsigned long flags; + + spin_lock_irqsave(&spool->lock, flags); + spool->used_hpages -= 1; + unlock_or_release_subpool(spool, flags); + } } -- 2.53.0