From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795987125; b=SsEmB5U1XuRoo3+SZ3uqwEQeW9mN4+zvQ81GAdEbyvPjC88AYNt3ZwC9/do5BvNt3JMl 7I0u3M2/b2jVFm5Rlo9wm/Zkc7dXCS2DCacbqaXuqa5TorKAGbwKIzlsypV3LlT0Is/Ub GM0VeTmIP5xfaRzspWqvon6IaG2cCHN166IF+tON5ZTPUdsbkKaA/8m9RjZ26O5Lfuhej CW/NKa5Mvn6iAUAVus4h7CMHjj7/ISk0ziiS5h93OVqOAZVWaps8yDz1fK8NPGy4ML1v8 b9ycSG6/fdftaUraEoqmOyEbYZMD+0797QKtWUznEXzJc52pUbT+8f/xP+2JhCoUI9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795987125; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=Af3H043Ri7wee26lHvPweWcGOkeCJl1HJHO357kYSSY=; b=3GPW9JMiDhrOUrFJyJCRcOnYzx21iujX6H8pgGUU6lI32R4yVEwVONnA/XfT/cXK8Ydy lc1mpIFQMpSLXyaQNHZ8lWnqkBPGhgDKkhT91y9SOm4/Qd4ZTpu91WF30lwKug0PONF9a dlyN8k5zpXpwTuIS51NBUgp13Dhd26tB5EBjEQKfrUhf2jynzu/76ga/fHYClJlkRchL8 5A5qkVYW9TnD/uIH+4ZyTwzP84vR3wfWfvw8zxHUZDP3AT8aA9iOt3Fm5EDqe9/KugVDm XliA7+ikGTxrjIf3AIniqKaW+4X20adBJ6THjtM9R7vx/NiRlV7Ud30nw9xA3vB2tDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=meBGgZKa; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A380606A31C; Sun, 29 Nov 2026 21:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=meBGgZKa Received: by smtp.kernel.org (Postfix) with ESMTPSA id 523061F00899; Sun, 29 Nov 2026 21:18:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1795987124; bh=Af3H043Ri7wee26lHvPweWcGOkeCJl1HJHO357kYSSY=; h=Date:To:From:In-Reply-To:References:Subject; b=meBGgZKaav7MehSsEF0hT4lihyHFniHVKxIDKejpabb6JUpmehTqh+KAS6GzbsCJy 5x5A/tflAabE7eRgm3GbUOJTHIyI1NT7H2ekU95VsGQk1UIj1rgv/XyUFwJjZtZV4L F+xzdWa6mDcncT+tEp9vBwIVBOMATvzRqDM5mkY0= Date: Sun, 29 Nov 2026 13:18:43 -0800 To: mm-commits@vger.kernel.org,yuzhao@google.com,yuanchu@google.com, weixugc@google.com,stable@vger.kernel.org,shakeel.butt@linux.dev, ridong.chen@linux.dev,qi.zheng@linux.dev,mhocko@kernel.org, kasong@tencent.com,hannes@cmpxchg.org,david@kernel.org,baoquan.he@linux.dev, baolin.wang@linux.alibaba.com,baohua@kernel.org,axelrasmussen@google.com, mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261129143759.96221-3-baohua@kernel.org> References: <20261129143759.96221-3-baohua@kernel.org> Subject: + mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch added to mm-new branch Message-Id: <20261129211844.523061F00899@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/mglru: test PG_lru before taking a folio reference has been added to the -mm mm-new branch. Its filename is mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Chris Mason Subject: mm/mglru: test PG_lru before taking a folio reference Date: Sun, 29 Nov 2026 22:37:58 +0800 With MGLRU, reclaim that races with compaction for a folio can deadlock on the lruvec->lru_lock that it already holds. isolate_folio() runs under the lru_lock. It takes a reference, and drops it again if another isolator has already cleared PG_lru. That folio_put() must not be the last one, since the free path takes the lru_lock if PG_lru is set. But compaction can release the lru_lock while the folio is still on the list with PG_lru clear. If the folio is truncated or unmapped meanwhile, the two isolators hold the only references: isolate_migratepages_block() evict_folios() ============================ ============== folio_get_nontail_page() folio_test_clear_lru() goto isolate_abort lruvec_unlock_irqrestore() lruvec_lock_irq() isolate_folio() folio_try_get() folio_test_clear_lru() fails folio_set_lru() folio_put() folio_put() __page_cache_release() folio_lruvec_lock_irqsave() The fix used here is to leave a folio alone if PG_lru is already clear, before a reference is taken, as isolate_lru_folios() does. An isolator that clears PG_lru after that test has to take the lru_lock before it drops its own reference. [kasong@tencent.com: Improved the comment] Link: https://patch.msgid.link/20261129143759.96221-3-baohua@kernel.org Fixes: ac35a4902374 ("mm: multi-gen LRU: minimal implementation") Signed-off-by: Chris Mason Signed-off-by: Barry Song (Xiaomi) Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Kairui Song Signed-off-by: Andrew Morton Cc: Johannes Weiner Cc: Michal Hocko Cc: Qi Zheng Cc: Shakeel Butt Cc: Axel Rasmussen Cc: Yuanchu Xie Cc: Wei Xu Cc: Baoquan He Cc: Baolin Wang Cc: Ridong Chen Cc: Yu Zhao Cc: mm/vmscan.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/mm/vmscan.c~mm-mglru-test-pg_lru-before-taking-a-folio-reference +++ a/mm/vmscan.c @@ -4802,6 +4802,15 @@ static bool isolate_folio(struct lruvec { bool success; + /* + * If PG_lru is set, the folio_put() below can't be the last one and + * free the folio: whoever clears the flag keeps its reference until + * it sets the flag again or takes the folio off the list, and it has + * to take the lru_lock we hold before it can do either. + */ + if (!folio_test_lru(folio)) + return false; + /* raced with release_pages() */ if (!folio_try_get(folio)) return false; _ Patches currently in -mm which might be from mason@kernel.org are mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch