From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 483043B2FC7 for ; Tue, 28 Apr 2026 11:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376508; cv=none; b=Qj0Tblf/Fvj/MKcfEtWwhv9lMC5Uqc1EyBpCJz2b063UGNhqGVFMPeZBv6wxQwaMj37xu6QSs+TYeQS3Hu+fPlhGj7RLNj8rZ7ZUKyHxLRJRpMxFCBUcGclbfads8T8mNflI+wdN+BPj/2d8JdMcpYtHEuf/QVcqRsJQ54fCBEk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777376508; c=relaxed/simple; bh=1kQi2Bq6YbgrGHQe5sfXvF/k3I43Vkqs8GVRuEhF3vM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f91FRrsTFLqB6NbiKh5NmAP3z3er/WifjmbEyJnDol125Zr5hIM08ms5VvjHX5V3miy2lKq8nADBjz4ariSpTc5QeiNzwmva4wwqYlhtvKPYPcGBqIua+THIuQoVt/+y24621LxtxRHgxP9PKy9XM3k5CypuBQ0syc33ArW51tU= 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=LFsjYaN3; arc=none smtp.client-ip=209.85.216.53 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="LFsjYaN3" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-35d965648a2so10137672a91.0 for ; Tue, 28 Apr 2026 04:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777376507; x=1777981307; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NLsCRxiSk9JCczyCTSC3xk7yAKwnu18iR/LzsMMrkH0=; b=LFsjYaN3uuwvin4X3WXgiJPCtM3ATuUJ6DfNbXO1nTamHdazLG+prMV4/ANYJCLt5E UNSK3FfuT+T2b8KgoKeGLIWIV/N/c/QpGSi2ReHr1wVMXWie/FMQIKKpHxOeSZQJySlf mpF0LbjMTsymFvI3WQ7me2AXNjHkx2D+7RXose03hyUKvpmCRM9LgfInH8FWymuMEmyE l+fhaSdW1HMGA6jQTpnpHyw523+90TgzZY9HM45ZiQEOYL7TBB600E1U4wWYutyGAZRc 9eFtjJW4BZDG3/29PQvZEi69ZbTCYm/OWyjcfmTQu5vqtZIXmLhYgcz0FCcV5meNNED9 qNOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777376507; x=1777981307; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NLsCRxiSk9JCczyCTSC3xk7yAKwnu18iR/LzsMMrkH0=; b=oheDGXXxql9QwavwNJmyerHY6iQ5NQjex88VSMoM3BsQkCspUyARm7RsF2WiasC+MT w15rBk/G7MNYRpElw6lQSGfEALIkdhkSuGxl4mLu5qrbYcy7AxYurQu769MLy/GmCTIb qcDi3DYThb9v0SF8P0DvQdcnOJAfsm4HWEVCos1x08t9T1uSLR38h1uHiOa/LCkR/I74 CNgruG6Lz31GVr9vXBjm88U80I/Gy6zr0aboFEu8/EmlLUsoWfbjXOYqeGItbxbXIt67 da7PS2GdGzEd8QMCj4vFbc0G1MLIKRom6jhocKwXMo/1RpE3I1/1eFdSsxz3t+vTjtHq H27A== X-Forwarded-Encrypted: i=1; AFNElJ+cJZ+hIdyJM2m5aMN2XhnsssRUYPXJtXHBV5d69RW660lBmsZcp4D2eizRLzo83mThRFbhAk7/0DEZcXc=@vger.kernel.org X-Gm-Message-State: AOJu0YyH2rKA1Pf8qtBrvQON357EWrztIBUBgLhh6nat0d6C67tjknly OdLCscMehX7qsrlu6zVUGXL5hdBLkjGRmFbIQmF1QiPCo3r/xg4U7muskRrcn8yEUPP7J1EI X-Gm-Gg: AeBDietatLBLvAOu+8PBpTFj9iMCzKQS5qpa3G/XUeDzIzYmj1+E4ZG3RSEIV1sCurE 9orPCi5OHrwgYs7kieFghFpwLvUHaOvqt+h1VPD0VvLfLAOk6l1AsFEceljVQgqW96uzZI6zfPI orJVJ5v/teNhBfUAkW7nlMfTjuGfXJtffZRi7R+6PAcjAJO/1S4pl90tvNu2nnPE1Qb60QUW/dm +oglJnrBhsPqXOc6LVdBkFdDpCP5pgi3H0FVLUmB3PPxvQSxH4OsT92WdExiJTRS0nub3YSy3XQ tQ7U3o35UpQyUd9j41IH5VBTAe9HhJxSnDGSJuE9400yHIf6SYpS0Rr8V+OHs9DskFjAJyUmStr baDwyFPfOevajnHQqGtqqNAGYn2gC0A6vF7GtQH7gweWbY+q0AqRsLOrMAgix3XbeKEmf1H0MKV Dh3Q7XbjturWd6FVYtIz+A4QNCI1snh1FKgqgwBtkASWutNkOqLmXfVxStTQvAAyefWNIg+ohe X-Received: by 2002:a17:90b:1d50:b0:35a:1762:92fc with SMTP id 98e67ed59e1d1-3649205ab5emr2794234a91.26.1777376506660; Tue, 28 Apr 2026 04:41:46 -0700 (PDT) Received: from KRHW1CJW23.bytedance.net ([2001:c10:ff04:0:1000::8]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36490924f01sm1785721a91.1.2026.04.28.04.41.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Apr 2026 04:41:46 -0700 (PDT) From: Zhao Li To: Lance Yang Cc: Zhao Li , Oscar Salvador , Andrew Morton , Muchun Song , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/hugetlb: fix subpool accounting after cgroup charge failure Date: Tue, 28 Apr 2026 19:41:39 +0800 Message-ID: <20260428114138.92159-2-enderaoelyther@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260428113059.79001-1-lance.yang@linux.dev> References: <20260427145247.84157-2-enderaoelyther@gmail.com> <20260428030712.66256-2-enderaoelyther@gmail.com> <20260428113059.79001-1-lance.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Tue, Apr 28, 2026 at 07:30:59PM +0800, Lance Yang wrote: > IIUC, there are three cases: > [...] > 2) gbl_chg > 0 && spool->max_hpages != -1 > [...] > If hugepage_subpool_put_pages() returns 0 here, it restored one > reservation in spool->rsv_hpages, so we also need to increment > h->resv_huge_pages. Thanks for working through the three cases - that's a clean breakdown and matches what v2 was trying to do. We ran into trouble on case 2 specifically: the h->resv_huge_pages++ on the put-returned-0 path looked right in isolation but turns out to be unsafe once you put it next to concurrent hugetlb_unreserve_pages() or free_huge_folio(). Two reachable orderings break it: * free_huge_folio() with HPageRestoreReserve set already does h->resv_huge_pages++ on its own. v2's bump on the gbl_chg > 0 cleanup double-counts against that. * hugetlb_unreserve_pages() does hugetlb_acct_memory(h, -X) which subtracts from h->resv_huge_pages and may also return surplus backing. v2's bump then leaves rsv_hpages backed by no h->resv_huge_pages - a phantom reservation that the next subpool_get_pages() consumes without real backing. v3 ended up going a different way: the gbl_chg > 0 cleanup is now restricted to (max_hpages != -1, min_hpages == -1). In that configuration hugepage_subpool_put_pages()'s min-restoration branch is dead, so a direct used_hpages-- under spool->lock is the exact inverse of the speculative bump - no put_pages(), no h->resv_huge_pages++, no concurrent-races to reason about. Your case 3 (max_hpages == -1) is unchanged: cleanup is a no-op, because get_pages() didn't touch any subpool field. Mounts with min_hpages != -1 are left at v1 behaviour for now. That quadrant has an inherited race that also exists at hugetlb_reserve_pages()'s out_put_pages cleanup; a coordinated fix belongs in a separate RFC rather than this stable backport. v3: https://lore.kernel.org/linux-mm/20260428113037.88766-2-enderaoelyther@gmail.com/ Thanks for the review. -- Zhao Li