From patchwork Tue Apr 1 02:10:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vishal Moola (Oracle)" X-Patchwork-Id: 14034296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D93FC3600C for ; Tue, 1 Apr 2025 02:11:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7676B280003; Mon, 31 Mar 2025 22:11:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F091280001; Mon, 31 Mar 2025 22:11:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56947280003; Mon, 31 Mar 2025 22:11:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 359A0280001 for ; Mon, 31 Mar 2025 22:11:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 13DE61406C9 for ; Tue, 1 Apr 2025 02:11:14 +0000 (UTC) X-FDA: 83283847668.21.4CE5F19 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf17.hostedemail.com (Postfix) with ESMTP id 54E704000F for ; Tue, 1 Apr 2025 02:11:12 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jt67ThJo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743473472; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=AOPlZ2IqgG3J5fbHUI0LVdUbG8WW7Z0L1XqmSy1WgQ4=; b=dMD65k3iFMdtBzJhg/PRitTwOWIr1URdqfc89fxgVZoPHc6JkVg0ua5gW4ITySQGxbJHxy TjWk0bqVJLs0+yqKK34TROEmZRUmy9hioU6b55nKs1Y46moief310i2ohTF+QT58PBVIda fGIhgKgKHf6DPy++ZtzLOtoccFxqeMA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jt67ThJo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743473472; a=rsa-sha256; cv=none; b=PNS3SF60Htywys8ZlbVtIVNrDWwKsAgYxTLBbntBH5H/ruVHi88w3k63S5sKvN21LcitF+ QktrORx8BoznHXXlFMGpSHtOmy1Uk1qUqLQHBGtcLhe2//HJ3jaB/UjbJLgEgghB1jDcjg 7Vn8itIy9bwS6XfrLy+Tj6SkDEM+onw= Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-301d6cbbd5bso8158548a91.3 for ; Mon, 31 Mar 2025 19:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743473470; x=1744078270; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AOPlZ2IqgG3J5fbHUI0LVdUbG8WW7Z0L1XqmSy1WgQ4=; b=jt67ThJoyG+yDPSnPFe69i2W5GmCVUkGPjliUcoiLydZw+awvp9C58TxXNocXGiOdE OtGJlETEqZyuMALHH2FujD76oPPDc8Wbav/dLOaMk4mdHe6kGh6W8OGnmbyn3ph0msJl U7cwxipHIjYtY6OUoMxAnm2tPWJF9iIc9AWBHFLucHjMdLZ5OfpNJyf3muddGosnFlXR BWsUySPklkUerzfz9+CPUzy9PsHDUIJ7ZxwFIqV8LRL8BiW2QJJ5mfnGCtwxkP1LRfJE y2I0iFHIArideLnWNyovEvCC7LQK4HGbdLt0Gnb1Q+BlrsjcVn6CaOG1FIRxjqrZToTk C3Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743473470; x=1744078270; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AOPlZ2IqgG3J5fbHUI0LVdUbG8WW7Z0L1XqmSy1WgQ4=; b=vz5Bggknvh4zY8kckVp07AwRDflg4nO9NqvbRxp6XFbQDuVQZSGdy73oTPnvfCKJ3p WG3ff6p3E40u4/1EWQ0xXSEWdj7tVUOrpKc4U3N51U+6hNFFcopXAwYawj0Jp1oz7fJB AeaiS2WQTWiRDwDUilxE0w4CJfWlSswkLKHF6viCyFzdTYLNDAY+6vguTV/lokTEJ1dj hAE/dmpkiSUUmE4Z6nI082U1m9K7HMGMvX+Rh5v8qLU1QSmxAGqyh8e4Pl7cKgZvMl3N ZYaW6hQKXqyQEL6ElWmh1tb8z2cCmwkgrncG8DrjuluEUc4ImFd+sDAeq60T8eFfJ0iF AsCQ== X-Gm-Message-State: AOJu0YwXcIbEaP9MNVGHdPLIIOKfx38X0E1uwWoyZAP4kvi1okzx5lbH fozksll3ESDvFuVWqDjOxDFY85cdGi5nIeGzUVJxrqa8fND1J1c6Nz9OILi+ X-Gm-Gg: ASbGnct+vjg6S0/w5lnD86fsCqr+dfodgqEIGNbdfcXsoj6rahXMVR4A81AZ3u+lMh8 8FPLdzxH9ivXWICXoUTyEF+q/tDfmdMhN3DK+pjcrLluBBNFA9B9NowRmb1qxh5cyyvDXhBZfZM 5tC2Ez+U6nsCwm3u85QiatgVxLJ5FlNjDEMmfkGp+29GcAA8b714YN0gq5VvRpp3Zw3MUyWk6pD WhbHart0qTgJLVl4vVwfBhlW3ruLRb4olvLNvbApdRFUoL7pnutAcHK8e2PobyA7tSe5czvNv+G O4qWVdhGmP6m0VeOiECuWJ934/1xqVQfAPfUfn20LotLziOuXM9qoRqz8nE8kzFbWKZmO35GkPo vPP0= X-Google-Smtp-Source: AGHT+IG4QRQF0niFAjvGK1I2zj7C/puZbed3eaweHgTfDfneLiZqbuZlRtu2w3kkRDe9KfHhjPrYSg== X-Received: by 2002:a17:90b:2650:b0:301:1c11:aa83 with SMTP id 98e67ed59e1d1-305321640acmr18888329a91.28.1743473470275; Mon, 31 Mar 2025 19:11:10 -0700 (PDT) Received: from fedora.. (c-67-164-59-41.hsd1.ca.comcast.net. [67.164.59.41]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-30516d3ce04sm8074118a91.9.2025.03.31.19.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Mar 2025 19:11:09 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, muchun.song@linux.dev, "Vishal Moola (Oracle)" , Miaohe Lin , Oscar Salvador Subject: [PATCH] mm/compaction: Fix bug in hugetlb handling pathway Date: Mon, 31 Mar 2025 19:10:24 -0700 Message-ID: <20250401021025.637333-1-vishal.moola@gmail.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 54E704000F X-Stat-Signature: b5s63qmzow3gq6kgn4po9x3748fqqcf6 X-Rspam-User: X-HE-Tag: 1743473472-568473 X-HE-Meta: U2FsdGVkX1/kywANRiZh+HoNZONheRHY00YrezU1Yuv+rwX80r+wdm8p7fHBJuYonThvPRlb+hugA8QYXr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7AmVSnRVQ/Ay9ywSfxhAySIvwZbAStAiDO8YhRIt8PmazOGAY73bZgtlr7He/d36po8HbNORlwOXdU58OmJ/C7g6IvRG24S40/KdsLJp7XUfuaJsWOQ/V/czUAwSCpO052gsw3hSmuQZMVS8ooSA3mh60qOtjBikXX07YaUA4P58w5rNDq9rY2PiHaCJEdxizSgJNMKE7+9oIDHqHgFPkRxxXrKIb4nyhZodydXJHwoiNBCNvhf5Ky76Z9TC6qt8ZmjFLsOwu3TUHK4fW3HevheHgbMkQsrCJXyeq7chE7y8RHCcxEYmMZkmYaovIMPwep8IXv0WB45ov8SoeyBHrzRf0kQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.103063, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The compaction code doesn't take references on pages until we're certain we should attempt to handle it. In the hugetlb case, isolate_or_dissolve_huge_page() may return -EBUSY without taking a reference to the folio associated with our pfn. If our folio's refcount drops to 0, compound_nr() becomes unpredictable, making low_pfn and nr_scanned unreliable. The user-visible effect is minimal - this should rarely happen (if ever). Fix this by storing the folio statistics earlier on the stack (just like the THP and Buddy cases). Also revert commit 66fe1cf7f581 ("mm: compaction: use helper compound_nr in isolate_migratepages_block") to make backporting easier. Fixes: 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages") Cc: Miaohe Lin Cc: Oscar Salvador Signed-off-by: Vishal Moola (Oracle) Acked-by: Oscar Salvador --- mm/compaction.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 139f00c0308a..ca71fd3c3181 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -981,13 +981,13 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } if (PageHuge(page)) { + const unsigned int order = compound_order(page); /* * skip hugetlbfs if we are not compacting for pages * bigger than its order. THPs and other compound pages * are handled below. */ if (!cc->alloc_contig) { - const unsigned int order = compound_order(page); if (order <= MAX_PAGE_ORDER) { low_pfn += (1UL << order) - 1; @@ -1011,8 +1011,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, /* Do not report -EBUSY down the chain */ if (ret == -EBUSY) ret = 0; - low_pfn += compound_nr(page) - 1; - nr_scanned += compound_nr(page) - 1; + low_pfn += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; goto isolate_fail; }