From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 3FFF9381B1F for ; Mon, 27 Apr 2026 14:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777301578; cv=none; b=uL3u5g8HnDy7alTntOUDEnTRO5+9v6ERpUYtuSaTej5Ix/K5hk8THcKd6V0S3GBtBtCZZ/9u/i913PCQEt2K8O8ucCEcUwNqTWmQnxyV5JyVLWXCl2QIv7o2DD2okpipZ3P+AkbAlN44g7ajmM/UVB7KdqDigydR/AY8VAoHQFg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777301578; c=relaxed/simple; bh=JqR97hFXqtUZGFl32ImWXO8rxF4mSVDN+LfSDr4k950=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uWrTdtj8t1KrZbXYtHwo/Pi+NsOEqOSA/nB6ot9790qHD0h3n67f9dogAOGpMoCB770/gKnNP1GmBQq06ElVQWx3wVohyA+6IqXimlWoXu/9pOVr2R+1Yprv02K9lohK1iyxuF1H/i4a1PM1Xk5TBGL+GaZSOo2rIpniMXsA9Cs= 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=KyXiQDRt; arc=none smtp.client-ip=209.85.210.176 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="KyXiQDRt" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-82f6b592fc7so4611435b3a.3 for ; Mon, 27 Apr 2026 07:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777301576; x=1777906376; 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=jC1NRZz+kwp3j5wZmm2yj+4VVo1PzPLnch+E5Q6Y4MM=; b=KyXiQDRt4qxJptHMgK97hNg8aJqdIUzwmvsXPkdZcVw1IEAOTEXh+6xTIO9K1OaPVP 7IRvEWKymV65gSynmCdJMaooenxaNhuj9RhvB1pxSNq8ZoQuc5FDnDxlKd81xkQyU70R OhEdCemeHc/SVL2eSuH1lJyC1lcpdsABJl4hO+f4cIbX9mESdgpk2GBnCW8q0OIkq34T 9dAyARdd+c6o13YVBgcCUN3JvooI7AgASqIkIiEVs8cny0tUBDAWFkSHkxDKKtJwxQoj Kv04oRyKRSZpBhXRDwckURscVDXXLs2xhILaxR70J3MQ55SGMYX7S7T4EOjQrt4Ls0ud 4WDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777301576; x=1777906376; 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=jC1NRZz+kwp3j5wZmm2yj+4VVo1PzPLnch+E5Q6Y4MM=; b=lm5lLF7qew4eCRe6NC3GVP0lU7ZiodVpCtqqaSFbECrt+k4cD4zDct1QX8Ng3z24q6 RMUnpUYSVA8ITd/F9uoQEJbKCyaQwnwqDsDdQFls/nRA7drbJruo1opeiSOiA0QuEH/w 3+CNWXlfu6IN1Y3yRPeZ9TMHlF/AbkwBTIMhx5wpA2J+Hqbk4uxJVjpVRXIBO27NUOZc 432WAyhxMGxT8laLPncx8usyGMzHm/+sKO0JOCSq1CjiybG3Ox4UF/F1hJgDqOpYUK6d 4CX4D5eD+4g+3aYISYxnfQAYAoz2qFAauuWTKYKWeJbMX0bqqPJ+RD0+xagxVYVcKVlM UQ9A== X-Forwarded-Encrypted: i=1; AFNElJ+n5+QF3NhM0Ti4nNIt+VsWfvb00j8PfBnVLj/BxwUS13z93SfrAa5oexMqqkHvwXaRH2go5NNVqppiVvQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp6dC91mOmnidwLE7LGzPiUIzNAJ7qpJ8TzWQdAhrh8QTnFaYb zRlC/MTtaI2k6n4MJ0JwjGW7bOSVOfsMkTWqvWt7XdSYuGWjUbaGZhN9 X-Gm-Gg: AeBDieuMxzsa2j2FgJP/G8JTdKIh5PZNMSsQUL+2hF6rN8KlFOW8zNoKpyRWSynrGah XgFNRC3AjHewRjq7MnksoL/rcqf4cHk4xuMaUbkGorJj3+taNq+QFKXGumpHuNqP39nPlOPejgq K7/I9t75M3PvP8/b6Oq7ra0bWIJ+u2LMUL+xmhr4XizZiZsFgE0UedULkFgUlPvEByfaZooz1J9 diRRacHnxjbO4cVs+rB2TJez6K9n1nnJkhwbZY8vPZcXyH2HZMx2ymEGYptXw9pDUadHFVkPIUQ 9V/TLAIn0WU1nQ9pYAx1irPqOt8zwX7/gTsRZx96SpCLONPH1KYIaCrh1KD3hCllKwZgJF3Zd2e t8InZXUjlE7XqKu7hCjjX4q/E0QJVLp+bm1zo8aE2uIjIcWlwCF8jeIMlingiN2759tpHU/IBGW X+K9wrHuPQIzcPC04s0i0QCl1FJG6h3GfV/FSXf04IbZ52uySniZOJ4X7ojM+iGpyj584T3l8k3 g== X-Received: by 2002:a05:6a00:a241:b0:822:6830:5900 with SMTP id d2e1a72fcca58-82f8c7eee25mr42954392b3a.6.1777301576381; Mon, 27 Apr 2026 07:52:56 -0700 (PDT) Received: from KRHW1CJW23.bytedance.net ([139.177.225.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebbf0e5sm33009112b3a.28.2026.04.27.07.52.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 27 Apr 2026 07:52:56 -0700 (PDT) From: Catherine To: Andrew Morton Cc: Muchun Song , Oscar Salvador , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Catherine Subject: [PATCH] mm/hugetlb: fix subpool accounting after cgroup charge failure Date: Mon, 27 Apr 2026 22:52:48 +0800 Message-ID: <20260427145247.84157-2-enderaoelyther@gmail.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit alloc_hugetlb_folio() calls hugepage_subpool_get_pages() when map_chg is set. For subpools with max_hpages, that increments used_hpages even when the returned gbl_chg is positive. If a later hugetlb cgroup charge fails, the cleanup currently calls hugepage_subpool_put_pages() only for !gbl_chg. The gbl_chg > 0 path therefore leaks one used_hpages charge per failure. Always undo the subpool charge after a successful subpool get. Keep the global reservation accounting under !gbl_chg, because only that path consumed a reservation from the subpool. Signed-off-by: Catherine --- mm/hugetlb.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f24bf49be..b3ad024a0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3026,12 +3026,14 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, h_cg); out_subpool_put: /* - * put page to subpool iff the quota of subpool's rsv_hpages is used - * during hugepage_subpool_get_pages. + * map_chg means hugepage_subpool_get_pages() succeeded above. + * Always undo the subpool quota charge; only drop global reservation + * accounting if the subpool consumed a reservation. */ - if (map_chg && !gbl_chg) { + if (map_chg) { gbl_reserve = hugepage_subpool_put_pages(spool, 1); - hugetlb_acct_memory(h, -gbl_reserve); + if (!gbl_chg) + hugetlb_acct_memory(h, -gbl_reserve); } -- 2.50.1 (Apple Git-155)