From nobody Mon Sep 28 04:55:37 2026 Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EE13463B60 for ; Wed, 26 Aug 2026 16:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761274; cv=none; b=chu5gsAO+hKSAIoHHDBnOXiXu6qBVswYaUfCEc7drYayFuMxhbjyBYcWAGri9fpd6wukVgVG52yT44nIvt7N7xuWGnf9QcUoA2JLdObYvxUc+dkOrW6GBw25HeSZW9S6XfM6o9NAc1h3ReMbwA0+R3b0xbWVFQXXKO3+B/XwpRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761274; c=relaxed/simple; bh=QQgHgspM1/eGjoz2/XWrLFkLlJAF5sIRawerbKeJyJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aokL7dxlFRyz7LoY+bHFiAEqjwkJU3aaBSC7BJGQBGKAcKgqdk/mCVzLsFo1vdBb9VCj97e+3WnVe5p2fhIpMuKYbZN09MS2kyCmNHokLllz8kp5TQPQxipzSqX86zOjIhc32kZBWWuVbjbgPcJftj5qBPDxQSS8hcP+E5cUbvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name; spf=pass smtp.mailfrom=shutemov.name; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b=bi+kc7S0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=H4drzaP7; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shutemov.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b="bi+kc7S0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="H4drzaP7" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 30B081400197; Wed, 26 Aug 2026 12:21:09 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Wed, 26 Aug 2026 12:21:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1787761269; x= 1787847669; bh=Bv2FLl1ikHMiScnydjr4vJ1LmDfldI8n6iuNGCnTKZw=; b=b i+kc7S0ld/EJOGlID7nHa2apNgtC69ZYY4g3eOsBEQl5Ce7G/p+BG70IJxyccwER xIxYoj/GeOzAQ/QwNGH/A8Up7QN1YoXXZTpR1hho1ZGyVF/jDN1mUjWshGPY7Afb foBsbqmBenqWmJvnug5fGv/ZXenhtW/j/vldCSqq8Ybsv97Nqk/HUibjrwrpUhCu byo9JSmgzenmZW8NOmI5GwHZB3uP6wc8+Bp8XsLhtgNLME08Wu2ry24uLqMqjOL3 cOqfp36UHTWya5mNoJTswJ9Ah9Lguj4T/9MKcZL7iGM8Bi6XnBQnRU1PUPyURFpm i+XbOv9AE+Cb06F3AfuwA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1787761269; x=1787847669; bh=B v2FLl1ikHMiScnydjr4vJ1LmDfldI8n6iuNGCnTKZw=; b=H4drzaP7J4XHlzvKC 2h/dA0kWrlACAxqOyCDE5FwFYfxKRCivUfdy8c4skJCxNvsGKSxNFGYEK0AxU2xv x191DX0yjQDTfg+WjxR3d2lnHvz87miO++1WcsadjLzKfyJ45qA0rpjpoLDpKQSK d5F4IfqjBWHJcNyMmGE/0Yjsvk4S0LOff0UhUVgioZ/iBgso23ERHivlTHMmbzTM O7YOBG+Yhaws0DUsh9rK3HG9RD5xBLJakLrRaYRqnFjsHRGTMK6i+xlAgFFZF6dA LdrOdmHnGd34esDwjvi4rTnZdmdZCJaOfjd28Iopbr+DYRckSQ2vuuBDI8abSGtd n5I2Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGBpY7kNoX77sZdPDdL91xDvRNv92b/+8WOYmCGA6aQH9Q102aXniwcYcn+2R3bEj uCi/l1igqxgbq+7uoWVnSfVnmmWrLGz8UPAjIXOdULdKf7WqwDtIartGLCCo68+ug+tCv7 Ph9+mj9AZr2Dj3uoVsu8zcjpqcESEL6Qo+qhix3q57KDkOugB1EyJGuvn3/JCvR9j1Dad7 o+mC30PVOUmdi3WxO4xeazK74tOpUh5phSdSI4XIlRDA8FYZNVwP9p7PMSP1kYV7SphUR1 NVW71rOnvC5bor+jWHffeUW4ibVwJbIPbYc8TjXE3UYxed4i2ZOZ49wwSEox1MjCbLFsSu YPKLkIkQUnFzSfmoRy09Yk+6QAiQBNOL3kgRmFbcNEP+pkMk0/HwajWkkbMvDEzbG7ih8j 9VmjLPs0GHvU90MMBTO4IgmRP25L9euMYxF42Qnlcb5IJB4Yj4FWrmjvmydrOhYwH4txfP N0sGRbfkIRMlAotV03Pf6h+qHYq5kx1wkP9qeFqLirkNozh7KFRsFG0POuQgSn7ocDa1Tr TmxNd75KRYhV/7XI82QPUB5FHfaJr/hNTvoz7JcqS8jlcKPr2c1v9a5pAB6LVmnBUD8ljB fRa/pR5DZ0LmzlPvoYi11c5SXpBp1O9ry12oYVB9BFPnFUKCOwYend85kwgw X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 26 Aug 2026 12:21:08 -0400 (EDT) From: Kiryl Shutsemau To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org, usama.arif@linux.dev Cc: lance.yang@linux.dev, ziy@nvidia.com, hughd@google.com, baolin.wang@linux.alibaba.com, baohua@kernel.org, liam@infradead.org, nico.pache@linux.dev, dev.jain@arm.com, ryan.roberts@arm.com, balbirs@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kiryl Shutsemau (Meta)" Subject: [PATCH 1/5] mm/huge_memory: do not touch frozen folios in deferred_split_isolate() Date: Wed, 26 Aug 2026 17:20:57 +0100 Message-ID: <20260826162101.1314941-2-kirill@shutemov.name> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826162101.1314941-1-kirill@shutemov.name> References: <20260826162101.1314941-1-kirill@shutemov.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Kiryl Shutsemau (Meta)" deferred_split_isolate() probes each queued folio with folio_try_get(). folio_try_get() failure is treated as a lost race with folio_put(): clear PG_partially_mapped, correct MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, take the folio off the queue. The folio_put() race is the most common case for !folio_try_get(), but it is not the only option. Another scenario is folio_ref_freeze(). A zero refcount in such cases does not mean the folio is going away. It means "don't touch me" and current deferred_split_isolate() doesn't respect it. It can lead to unqueueing folios from the deferred list for no reason: CPU 0 CPU 1 --------------------------- ------------------------------ freeze a mapped folio deferred_split_scan() folio_ref_freeze() folio_try_get() fails folio_clear_partially_mapped() NR_ANON_PARTIALLY_MAPPED-- folio off the queue give up, put it back folio_ref_unfreeze() The folio is still partially mapped, but it is no longer a split candidate. Nothing queues it again until part of it is unmapped once more. Skip the folio instead: whoever freezes the folio, owns it and owner is responsible for its fate. It also covers the folio_put() case: __folio_put() unqueues the folio via folio_unqueue_deferred_split(). Reported-by: Lance Yang Link: https://lore.kernel.org/all/20260824131224.73344-1-lance.yang@linux.d= ev/ Assisted-by: Claude-Code:claude-opus-5 Signed-off-by: Kiryl Shutsemau (Meta) Reviewed-by: Johannes Weiner Reviewed-by: Zi Yan --- mm/huge_memory.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ced400f72d43..6281ed993243 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4590,22 +4590,11 @@ static enum lru_status deferred_split_isolate(struc= t list_head *item, struct folio *folio =3D container_of(item, struct folio, _deferred_list); struct list_head *freeable =3D cb_arg; =20 - if (folio_try_get(folio)) { - list_lru_isolate_move(lru, item, freeable); - return LRU_REMOVED; - } + /* Lost race to folio_put() or the folio is under folio_ref_freeze() */ + if (!folio_try_get(folio)) + return LRU_SKIP; =20 - /* - * We lost race with folio_put(). Read folio state before the - * isolate: folio_unqueue_deferred_split() checks list_empty() - * locklessly, so once removed the folio can be freed any time. - */ - if (folio_test_partially_mapped(folio)) { - folio_clear_partially_mapped(folio); - mod_mthp_stat(folio_order(folio), - MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1); - } - list_lru_isolate(lru, item); + list_lru_isolate_move(lru, item, freeable); return LRU_REMOVED; } =20 --=20 2.54.0 From nobody Mon Sep 28 04:55:37 2026 Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86F8345DF43 for ; Wed, 26 Aug 2026 16:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761277; cv=none; b=Wp0cW+3qoWj5Qshu6gFH3UDbNWkqGDYdBopWJSJw5MQkkc6WqZv9bFlppiqdaWoq1fbm811IVXBENyVOURHi0XlkJkIhvBo3IxhH/CXpKkkSsriCYtrlrcSt/IbYvzlYMEA5v5iZIL1L1dqplyfHv1NUcEF21kuck3lq7OK4MlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761277; c=relaxed/simple; bh=8l+SG+0GSoAWxIK2FePeoZd140FIivvIxWQd8CZzXR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HWhur/7aULN99YDb1B5vmhFmnJNNQr42dfJa1rAQkXVZ+L4YMVswLYxUlNvxkcdl7IHn96NWKzmKE9cFiPJMBth7XfPrqDGgUzjQRXpvLeha2EEiJ01st3mLbYHc0R0zsamklmCf8yjONizK3Dh8q0u/xGK3nK3+mO8Xy+6vqAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name; spf=pass smtp.mailfrom=shutemov.name; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b=JJCT6qtw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gBuq2dbD; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shutemov.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b="JJCT6qtw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gBuq2dbD" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 0774BEC0113; Wed, 26 Aug 2026 12:21:11 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Wed, 26 Aug 2026 12:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1787761271; x= 1787847671; bh=PZqn9LaepqaNPDOa8Shpk8ydDkhLYpgCWjChGLGqhJo=; b=J JCT6qtw1TNo+6ZXJEUgoeGsTvCjHGxQqp1NcbZMgFYTLMf/Ryj5Hz7icUY3Pr/sc +7xVeds8ASJjsQjE9FcSIIboIFBK1fcUH+ztxFTpVN+WGMclCAPu9EgPhAZk04Nn QyJD7Pdma5BReYyxUOCmG8y/TrFz4uo9oOP2M5M50rTYdLS2eJEdkmrrJVq6N4jj HpBp6dZnxXI2PSe19rDVa530BLt4FlGOZukEfNJWOQoj5KWg4ySCC5bBQd7BOgad z4O8phZsYRu+e4eqsFYBMDOqVVJ39gXLG6vNJjd+L2KfMxLmkyOEKIdAhboQkPM/ t2RI71aBc3lvc7Trz8omA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1787761271; x=1787847671; bh=P Zqn9LaepqaNPDOa8Shpk8ydDkhLYpgCWjChGLGqhJo=; b=gBuq2dbDYWOj+PqoS 5YnH1V7B2iONpL3uJRh34zzuEmsIeJ3nN5s96n7f4n7t03BhgGANMlpwuOyzLCUd BWUPg7cQdp65S5pDGR5moiuMNQbI8lvDyLQvizWzPtuV4yxQJzPYCUYNGXwMatCz 6PC0g4/c/iUVwIw9UrosYun0yt3dTs05mfNnH7L5l/mDKSv5NBUU9YB2cP9ENbhy 86/U+d0uUq86s9v/FiiiIHUVPSFSPmFBZYU0u7qVIZBxiWahCG66G3aOdtG2xpIp brIyM39rjo9oXv6C5QZuKg+ggJuXmUm/etuV08zKxNR7FPvwdzkxXG2E2zc+aYam 2eA5Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEpX8HBQysEAMlAbdyKFX4BLzWtS7+Qo1RjxAJeMJnS381384CQaxM92QA8W5J6jo 7r0RHbsPcTs1IpTXqcOu2ofgimA8w2hMK3OeOMvPUWs2NDJNBlDL/23E29uU3eWq90a8Ny uayj7GqONoh0NEQ91mQ/H+TE3rTPuVZ+wfrdHbeyaEyRe40ZIUYJyXTHqnubEDskXnqfPu FIQsvLmT+4mxeisAsg0TmWv4Y7l9NdKef8tTMihpDmjKvNxij8lw310+ofBfGEkzSLqnuN AyozbfZUQr702Kz+RkXguKuGQfBCnKcQhC5EFdpLjS6L6jWqh1sGvO+4Vl+gX27JPRP8s5 lSLckIYbxH/PtXTLtZPr2I496n1Z+5615svwkDFxhaNmgGpzGejMidUwbOUxLRdGuc2rZg w7EVq4D+yvMbxQ0bVxFYShdTuEeXaZWypH5RocS+FySPsN9RG8ZDbzvlUocKn67qn9YbT5 m67TyzmbU49Yi0FJGi35Qm+jJUodzTwAIvcGJ25Find/PYmX3P1CefFAlt3ZqvUQWexH84 GlGmeFWqYBMh43kqHoCd/fKRbITSkrbofIDfxV6HWHoS9gj+zSqQXSaqCKI329GRnYyGjV uuBti6l727veyF9VwljNVqtrv0A+Lea3+P/SoIQNmbyiZYUvBbW0UmRyQ0sw X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 26 Aug 2026 12:21:10 -0400 (EDT) From: Kiryl Shutsemau To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org, usama.arif@linux.dev Cc: lance.yang@linux.dev, ziy@nvidia.com, hughd@google.com, baolin.wang@linux.alibaba.com, baohua@kernel.org, liam@infradead.org, nico.pache@linux.dev, dev.jain@arm.com, ryan.roberts@arm.com, balbirs@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kiryl Shutsemau (Meta)" Subject: [PATCH 2/5] mm/huge_memory: dequeue the deferred split after the split freeze Date: Wed, 26 Aug 2026 17:20:58 +0100 Message-ID: <20260826162101.1314941-3-kirill@shutemov.name> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826162101.1314941-1-kirill@shutemov.name> References: <20260826162101.1314941-1-kirill@shutemov.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Kiryl Shutsemau (Meta)" __folio_freeze_and_split_unmapped() takes the deferred split list_lru lock across the freeze. It is only there to stop deferred_split_scan() from touching the folio under split. With deferred_split_isolate() fixed, the workaround can be dropped. Unqueue the folio after folio_ref_freeze(), the way __folio_migrate_mapping() does: folio_unqueue_deferred_split() needs a zero refcount and a memcg still set, and both hold there. If the split is called from deferred_split_scan(), the unqueue is a no-op -- the folio is already removed from the list. But PG_partially_mapped is still set, so it has to be cleared here or MTHP_STAT_NR_ANON_PARTIALLY_MAPPED never comes back down. Assisted-by: Claude-Code:claude-opus-5 Signed-off-by: Kiryl Shutsemau (Meta) Acked-by: David Hildenbrand (Arm) Reviewed-by: Johannes Weiner Reviewed-by: Zi Yan --- mm/huge_memory.c | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 6281ed993243..c84e8cbc986d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3931,41 +3931,27 @@ static int __folio_freeze_and_split_unmapped(struct= folio *folio, unsigned int n struct folio *end_folio =3D folio_next(folio); struct folio *new_folio, *next; int old_order =3D folio_order(folio); - struct list_lru_one *lru; - bool dequeue_deferred; int ret =3D 0; =20 VM_WARN_ON_ONCE(!mapping && end); - /* - * If this folio can be on the deferred split queue, lock out - * the shrinker before freezing the ref. If the shrinker sees - * a 0-ref folio, it assumes it beat folio_put() to the list - * lock and must clean up the LRU state - the same dequeue we - * will do below as part of the split. - */ - dequeue_deferred =3D folio_test_anon(folio) && old_order > 1; - if (dequeue_deferred) { - struct mem_cgroup *memcg; =20 - rcu_read_lock(); - memcg =3D folio_memcg(folio); - lru =3D list_lru_lock(&deferred_split_lru, - folio_nid(folio), &memcg); - } if (folio_ref_freeze(folio, folio_cache_ref_count(folio) + 1)) { struct swap_cluster_info *ci =3D NULL; struct lruvec *lruvec; =20 - if (dequeue_deferred) { - __list_lru_del(&deferred_split_lru, lru, - &folio->_deferred_list, folio_nid(folio)); - if (folio_test_partially_mapped(folio)) { - folio_clear_partially_mapped(folio); - mod_mthp_stat(old_order, - MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1); - } - list_lru_unlock(lru); - rcu_read_unlock(); + /* Take off the deferred split queue while frozen and memcg set */ + folio_unqueue_deferred_split(folio); + + /* + * deferred_split_scan() takes the folio off the queue before it + * splits it, so the unqueue above finds an empty list and + * leaves PG_partially_mapped set. + * Clear it here: the flag does not survive the split. + */ + if (folio_test_partially_mapped(folio)) { + folio_clear_partially_mapped(folio); + mod_mthp_stat(old_order, + MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1); } =20 if (mapping) { @@ -4067,10 +4053,6 @@ static int __folio_freeze_and_split_unmapped(struct = folio *folio, unsigned int n if (ci) swap_cluster_unlock(ci); } else { - if (dequeue_deferred) { - list_lru_unlock(lru); - rcu_read_unlock(); - } return -EAGAIN; } =20 --=20 2.54.0 From nobody Mon Sep 28 04:55:37 2026 Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF6AE448D03 for ; Wed, 26 Aug 2026 16:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761278; cv=none; b=thoJ4Sa7Pkmzzp0ZNimCDcqUQsJuJcACHKbkXHtbnJ/c0Xb3FIN5B5HHg9FtJ23JZBTog2kz7e6IZdmzLLZzlx60SUpVpoP2ZU/Eq3WpQDxRZfOpzB2Dn3TZD0PCTZomDRwwF6k/LIjZI37fElLokPPLOtNboPIpOguCDvknMfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761278; c=relaxed/simple; bh=UxtP3UPza9uNecaw1yFqAlFi2i84AUvFpnDYRucvx+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K4StO5sshbzf3BQqakhMqCJ1gd9Ishk6ljElUyi7RRWzE5nw8KdD9tPvZvtM0dRR2NUD7q07Y/U4P2vRJdJVedZlltGTD6h1r+ov81jY+TuHD0d3u3NrHOi0s5POUbzpdOswBahNryoQ+iuXL2qV8d93KALj/A7V/jJJ/tLHceQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name; spf=pass smtp.mailfrom=shutemov.name; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b=hX5xXl7b; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=e4I4TC4D; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shutemov.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b="hX5xXl7b"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="e4I4TC4D" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 09DA3EC0038; Wed, 26 Aug 2026 12:21:13 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 26 Aug 2026 12:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1787761273; x= 1787847673; bh=HbFogDQUqiCSfuewrPmwAWRl8NqcTYitqpsCtwQzicU=; b=h X5xXl7beBITHeeUvkfehphJkJjs7Eu+u9g3iPbV43qXhJ98ZN9gCFY8KSCXktfc4 YVl3E312cabApWB/k/A9YPY+1tcNBEoqqfrPcR7xl5CT5pp/JADjncWSXhV3WE1r OlE8o8/+/dbsWyz8rLJXIe8c3qTH9qTVfg78J8re22Tp3bbTeAGhrY0ZNO0lMEmJ G2Nd12jg64ooxJ3FTDIAHKJESPsuwvWjrdm45M+NBmpR7Q7sjooKWeYowPWp85hb 1/ZM1CfhNlYfOg8TkSJ0IAtEwudugAoxQb53rvJczdOHNeQjN02pIDF7w2Mz7K8w 2qX+eCL0UPAtjarrIs/Yw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1787761273; x=1787847673; bh=H bFogDQUqiCSfuewrPmwAWRl8NqcTYitqpsCtwQzicU=; b=e4I4TC4Dg6vSUTOON pIYNd3s5ogbZDyJ74DSfdMmNgsgwY6iIbcOvaIoQhFu/yueD+qa+WgjHvg8wlJJe zfiT/1TMFNDt+qiYxx7PcTs7X3hdWALAqvdgGkqdgOBhRQX0jtZV0UtmBcX55+AT g2+05U014BubHX4wCuM89F5o56EMLcE0BtuS4WU4l/xMy11fN5jkXR79aUTpLXuA K0XAOKiuqWqN85OaP5FGvkscMXqhUDZf6X7zsQgqL+aJCac9Mze1Im7gW/VINhAP cqL+BdqsTX5iBibZLLw/F/VGYxxeqbjceIlzPzfmE6oKWvwvJTWBBMS1ZXTSg7z1 406UQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEpX8HBQysEAMlAbdyKFX4BLzWtS7+Qo1RjxAJeMJnS381384CQaxM92QA8W5J6jo 7r0RHbsPcTs1IpTXqcOu2ofgimA8w2hMK3OeOMvPUWs2NDJNBlDL/23E29uU3eWq90a8Ny uayj7GqONoh0NEQ91mQ/H+TE3rTPuVZ+wfrdHbeyaEyRe40ZIUYJyXTHqnubEDskXnqfPu FIQsvLmT+4mxeisAsg0TmWv4Y7l9NdKef8tTMihpDmjKvNxij8lw310+ofBfGEkzSLqnuN AyozbfZUQr702Kz+RkXguKuGQfBCnKcQhC5EFdpLjS6L6jWqh1sGvO+4Vl+gX27JPRP8CC ZugFusXp6cdUu6aFxt4ihsFEeQsHpfMqFD2WIyBRpBjs6vrkwLZjumNr704QfNAegyDXmb bgnCWGCyShfc6lI47NAlmD6PpdSizmJYpB5q0a47cWEcF3kilhPKSlsjtHoo9AJr3IDvFd 1sCkNxb2bff5/nwxJwcRaywBnBLxIAIZ81NuUz38JVQtnxO4LoZvAAok+FmHFucDeP8dIy N6NNUe64csqK7I4cW7OnfmkW0SdkkRFZdnZAMaUGoxKcPHERVQ9iQyylfckgeVEPUG7KYi wzTYPjg7q9hDjaxJEJ2uw1hx6/Lk+6DXyOhwd0C+szYvJz2/t8qGBrLU4rZw X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 26 Aug 2026 12:21:11 -0400 (EDT) From: Kiryl Shutsemau To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org, usama.arif@linux.dev Cc: lance.yang@linux.dev, ziy@nvidia.com, hughd@google.com, baolin.wang@linux.alibaba.com, baohua@kernel.org, liam@infradead.org, nico.pache@linux.dev, dev.jain@arm.com, ryan.roberts@arm.com, balbirs@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kiryl Shutsemau (Meta)" Subject: [PATCH 3/5] mm/huge_memory: reduce indent level in __folio_freeze_and_split_unmapped() Date: Wed, 26 Aug 2026 17:20:59 +0100 Message-ID: <20260826162101.1314941-4-kirill@shutemov.name> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826162101.1314941-1-kirill@shutemov.name> References: <20260826162101.1314941-1-kirill@shutemov.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Kiryl Shutsemau (Meta)" Trivial cleanup: short-circuit the function if folio_ref_freeze() fails. It save an indent level for the whole function. No functional change intended. Signed-off-by: Kiryl Shutsemau (Meta) --- mm/huge_memory.c | 233 +++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 118 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c84e8cbc986d..36e90756e83b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3930,132 +3930,129 @@ static int __folio_freeze_and_split_unmapped(stru= ct folio *folio, unsigned int n { struct folio *end_folio =3D folio_next(folio); struct folio *new_folio, *next; + struct swap_cluster_info *ci =3D NULL; int old_order =3D folio_order(folio); + struct lruvec *lruvec; int ret =3D 0; =20 VM_WARN_ON_ONCE(!mapping && end); =20 - if (folio_ref_freeze(folio, folio_cache_ref_count(folio) + 1)) { - struct swap_cluster_info *ci =3D NULL; - struct lruvec *lruvec; - - /* Take off the deferred split queue while frozen and memcg set */ - folio_unqueue_deferred_split(folio); - - /* - * deferred_split_scan() takes the folio off the queue before it - * splits it, so the unqueue above finds an empty list and - * leaves PG_partially_mapped set. - * Clear it here: the flag does not survive the split. - */ - if (folio_test_partially_mapped(folio)) { - folio_clear_partially_mapped(folio); - mod_mthp_stat(old_order, - MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1); - } - - if (mapping) { - int nr =3D folio_nr_pages(folio); - - if (folio_test_pmd_mappable(folio) && - new_order < HPAGE_PMD_ORDER) { - if (folio_test_swapbacked(folio)) { - lruvec_stat_mod_folio(folio, - NR_SHMEM_THPS, -nr); - } else { - lruvec_stat_mod_folio(folio, - NR_FILE_THPS, -nr); - } - } - } - - if (folio_test_swapcache(folio)) { - if (mapping) { - VM_WARN_ON_ONCE_FOLIO(mapping, folio); - return -EINVAL; - } - - ci =3D swap_cluster_get_and_lock(folio); - } - - /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ - if (do_lru) - lruvec =3D folio_lruvec_lock(folio); - - ret =3D __split_unmapped_folio(folio, new_order, split_at, xas, - mapping, split_type); - - /* - * Unfreeze after-split folios and put them back to the right - * list. @folio should be kept frozon until page cache - * entries are updated with all the other after-split folios - * to prevent others seeing stale page cache entries. - * As a result, new_folio starts from the next folio of - * @folio. - */ - for (new_folio =3D folio_next(folio); new_folio !=3D end_folio; - new_folio =3D next) { - unsigned long nr_pages =3D folio_nr_pages(new_folio); - - next =3D folio_next(new_folio); - - zone_device_private_split_cb(folio, new_folio); - - folio_ref_unfreeze(new_folio, - folio_cache_ref_count(new_folio) + 1); - - if (do_lru) - lru_add_split_folio(folio, new_folio, lruvec, list); - - /* - * Anonymous folio with swap cache. - * NOTE: shmem in swap cache is not supported yet. - */ - if (ci) { - __swap_cache_replace_folio(ci, folio, new_folio); - continue; - } - - /* Anonymous folio without swap cache */ - if (!mapping) - continue; - - /* Add the new folio to the page cache. */ - if (new_folio->index < end) { - __xa_store(&mapping->i_pages, new_folio->index, - new_folio, 0); - continue; - } - - VM_WARN_ON_ONCE(!nr_shmem_dropped); - /* Drop folio beyond EOF: ->index >=3D end */ - if (shmem_mapping(mapping) && nr_shmem_dropped) - *nr_shmem_dropped +=3D nr_pages; - else if (folio_test_clear_dirty(new_folio)) - folio_account_cleaned( - new_folio, inode_to_wb(mapping->host)); - __filemap_remove_folio(new_folio, NULL); - folio_put_refs(new_folio, nr_pages); - } - - zone_device_private_split_cb(folio, NULL); - /* - * Unfreeze @folio only after all page cache entries, which - * used to point to it, have been updated with new folios. - * Otherwise, a parallel folio_try_get() can grab @folio - * and its caller can see stale page cache entries. - */ - folio_ref_unfreeze(folio, folio_cache_ref_count(folio) + 1); - - if (do_lru) - lruvec_unlock(lruvec); - - if (ci) - swap_cluster_unlock(ci); - } else { + if (!folio_ref_freeze(folio, folio_cache_ref_count(folio) + 1)) return -EAGAIN; + + /* Take off the deferred split queue while frozen and memcg set */ + folio_unqueue_deferred_split(folio); + + /* + * deferred_split_scan() takes the folio off the queue before it + * splits it, so the unqueue above finds an empty list and + * leaves PG_partially_mapped set. + * Clear it here: the flag does not survive the split. + */ + if (folio_test_partially_mapped(folio)) { + folio_clear_partially_mapped(folio); + mod_mthp_stat(old_order, + MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1); } =20 + if (mapping) { + int nr =3D folio_nr_pages(folio); + + if (folio_test_pmd_mappable(folio) && + new_order < HPAGE_PMD_ORDER) { + if (folio_test_swapbacked(folio)) { + lruvec_stat_mod_folio(folio, + NR_SHMEM_THPS, -nr); + } else { + lruvec_stat_mod_folio(folio, + NR_FILE_THPS, -nr); + } + } + } + + if (folio_test_swapcache(folio)) { + if (mapping) { + VM_WARN_ON_ONCE_FOLIO(mapping, folio); + return -EINVAL; + } + + ci =3D swap_cluster_get_and_lock(folio); + } + + /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ + if (do_lru) + lruvec =3D folio_lruvec_lock(folio); + + ret =3D __split_unmapped_folio(folio, new_order, split_at, xas, + mapping, split_type); + + /* + * Unfreeze after-split folios and put them back to the right + * list. @folio should be kept frozon until page cache + * entries are updated with all the other after-split folios + * to prevent others seeing stale page cache entries. + * As a result, new_folio starts from the next folio of + * @folio. + */ + for (new_folio =3D folio_next(folio); new_folio !=3D end_folio; + new_folio =3D next) { + unsigned long nr_pages =3D folio_nr_pages(new_folio); + + next =3D folio_next(new_folio); + + zone_device_private_split_cb(folio, new_folio); + + folio_ref_unfreeze(new_folio, + folio_cache_ref_count(new_folio) + 1); + + if (do_lru) + lru_add_split_folio(folio, new_folio, lruvec, list); + + /* + * Anonymous folio with swap cache. + * NOTE: shmem in swap cache is not supported yet. + */ + if (ci) { + __swap_cache_replace_folio(ci, folio, new_folio); + continue; + } + + /* Anonymous folio without swap cache */ + if (!mapping) + continue; + + /* Add the new folio to the page cache. */ + if (new_folio->index < end) { + __xa_store(&mapping->i_pages, new_folio->index, + new_folio, 0); + continue; + } + + VM_WARN_ON_ONCE(!nr_shmem_dropped); + /* Drop folio beyond EOF: ->index >=3D end */ + if (shmem_mapping(mapping) && nr_shmem_dropped) + *nr_shmem_dropped +=3D nr_pages; + else if (folio_test_clear_dirty(new_folio)) + folio_account_cleaned(new_folio, inode_to_wb(mapping->host)); + __filemap_remove_folio(new_folio, NULL); + folio_put_refs(new_folio, nr_pages); + } + + zone_device_private_split_cb(folio, NULL); + /* + * Unfreeze @folio only after all page cache entries, which + * used to point to it, have been updated with new folios. + * Otherwise, a parallel folio_try_get() can grab @folio + * and its caller can see stale page cache entries. + */ + folio_ref_unfreeze(folio, folio_cache_ref_count(folio) + 1); + + if (do_lru) + lruvec_unlock(lruvec); + + if (ci) + swap_cluster_unlock(ci); + return ret; } =20 --=20 2.54.0 From nobody Mon Sep 28 04:55:37 2026 Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92596466AE1 for ; Wed, 26 Aug 2026 16:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761280; cv=none; b=fz0NvI4n6zkPc6EFTt/y9hNbKZwfzoB9q8Lp4KbHI5YBiIA4LUwToZSRNS6otCwY+XDgYo1x6aY2ZJ2MasfklMcof6qrmiHi5EwJavm1TVzVfayTUZjhh90Ya0Qz0eFMp/9HpuKeCgCttWo/YByRquSB0y9O2RgBcN4J35Xz364= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761280; c=relaxed/simple; bh=aAKaYoxGYzSGqNBHvJ3crn2OekC+cZ2GVuoy5Ya3xxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C8PoP9LWu8n+Hs9JAFqEGFwSFPMjAnGZ+8PNYYaWDr0/WAm/tfviwRR8r9koxOEyk7jcjbv3w/sofzXFrXBCaSenxOpgs7wI2KUVHRz+9pOf1/Hk70vgxY6MXPW/iG+xLX2wULG1aunoPn+cMAfDmE1mV22fUEv02EmBljycpGU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name; spf=pass smtp.mailfrom=shutemov.name; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b=BmeRnk7i; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ejWpx6J7; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shutemov.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b="BmeRnk7i"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ejWpx6J7" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 285D6EC0187; Wed, 26 Aug 2026 12:21:15 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Wed, 26 Aug 2026 12:21:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1787761275; x= 1787847675; bh=cmrzZhAHwmnHLQBSELYH9/LSX3qgrbPWDwY3dINu6j4=; b=B meRnk7i4/XI6KegV4BZEImI59VLKXw56YnzEOvGO60CiHc/uZ0nK3d0FeV+gneIS AsCJEzxlGtqIIcTRb7JtFZr3lVwMHVVBia1aKLipF8rLPxtE/BZJ2llc+Di39fjH 0SHDWJAUpha2tPTqv2kzT+fjhHmituWvXa/WGvus10su3zy5A4tbPrlJg88NJM4+ Tet64WCgoSq6V/Hj3p7D3TLaFQGCcGB4rNTYR5mu2gfklqjI8llvcxyC1VCs2Fwq KFD8cACcyFcUN6y2XeOv5owWiG99hFtFx0hPhHUYrZ8wkUQEo+WgX3zBWSbEj/ZH Ico32Q6IDdm34t7qqqw9g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1787761275; x=1787847675; bh=c mrzZhAHwmnHLQBSELYH9/LSX3qgrbPWDwY3dINu6j4=; b=ejWpx6J74tHAufMpj 7XLoWM3bhhjP5VDG2DonuLOvsVTDCUfHiM/TQELLPmrRCauui2mq5meecCjvHMh7 pBdBOJxVQ8TdgZtvg9CXHL3uGyAx5X3YFtfPvfYP0S/BfP9LgBOSuAen6ofCvKrn xuAHMDxyrqQ2/EItGd2LQmeUC+VfGj/aDMlu0IDpiBnsilATuA43TbgfFV4smQgi nGToQ+RhfUXiUafrBnjp1leXQc1PSnSLF4+5t0QLzdMdGeo5G91GbmShShb0V/hx koLzVpMyxIHh4e+RzgelFvN5aBnyjfv0aPFBapbKyQ1+7ystv/k4f9pzuygnn+bh cF+bg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGQoFXZs8CLrQvTbejM+lWkhdLg/uROFwJkkdATYglJQ9SHaTyPScF7WW0mNphch1 eVR3IrwuHAkanmpAerNXc7LEOghrHwcryVnAmLgLIPaL4GXTh6Gf9eXsnQZjwVJHef9Nrs XjK6EHbPUOVKLW/G8KjWjJxHy1OYo963c/G1BhHZSIx7ZY3LwB604TzNS8Xq6Jr9ckMbkE MjqIIDZQsE7p6THO4ictYaMIpGXnlY0dQOoSn2w6WTw6bO0i0q9IvWAu8XF2rUmKLTGyRX Jqh48bYKYtZOalk45de8iFcxpRok1lQ08CY/mb9f5H5y4UZckNDJztfoueevfEh2JUVUGC +JurL57VI/e9t8xJ+DvlYoK5+RPHFB+KTXBB0wuGkAGhVihP4/91L/lOXPnfjTfwFQZtKk MsQ3k23yS8R/wi8BqJXmA8KNThEVnTLIO5sly5bbA6OKBZFExvsH5Cl809fLcDFgq8Y5hA VMpPXlVduTMKmryDasnpsybR8RlV94zwLi/L4ZHralLZT6A1UkzqLx+2JHoOymZkSZP9dX Dy5HDmpa3RMiVa6+NAcO6voerLSaml4zQlx4aExKoJKq89N0u90cHlsIzTEXU+TBahhHjL vdHjnNji0oNR2j2D6qMRCrWNuc/ucrjf0i7EHE59Ixaksz6ruCC0AAfmS0Ow X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 26 Aug 2026 12:21:14 -0400 (EDT) From: Kiryl Shutsemau To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org, usama.arif@linux.dev Cc: lance.yang@linux.dev, ziy@nvidia.com, hughd@google.com, baolin.wang@linux.alibaba.com, baohua@kernel.org, liam@infradead.org, nico.pache@linux.dev, dev.jain@arm.com, ryan.roberts@arm.com, balbirs@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kiryl Shutsemau (Meta)" Subject: [PATCH 4/5] mm/huge_memory: fold nested ifs in __folio_freeze_and_split_unmapped() Date: Wed, 26 Aug 2026 17:21:00 +0100 Message-ID: <20260826162101.1314941-5-kirill@shutemov.name> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826162101.1314941-1-kirill@shutemov.name> References: <20260826162101.1314941-1-kirill@shutemov.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Kiryl Shutsemau (Meta)" The two nested conditions guard a single statistics update. Fold them into one condition and drop the braces from the single-statement/single-line bodies. No functional change intended. Assisted-by: Claude-Code:claude-opus-5 Signed-off-by: Kiryl Shutsemau (Meta) --- mm/huge_memory.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 36e90756e83b..001d89c57fa2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3955,19 +3955,14 @@ static int __folio_freeze_and_split_unmapped(struct= folio *folio, unsigned int n MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1); } =20 - if (mapping) { + if (mapping && folio_test_pmd_mappable(folio) && + new_order < HPAGE_PMD_ORDER) { int nr =3D folio_nr_pages(folio); =20 - if (folio_test_pmd_mappable(folio) && - new_order < HPAGE_PMD_ORDER) { - if (folio_test_swapbacked(folio)) { - lruvec_stat_mod_folio(folio, - NR_SHMEM_THPS, -nr); - } else { - lruvec_stat_mod_folio(folio, - NR_FILE_THPS, -nr); - } - } + if (folio_test_swapbacked(folio)) + lruvec_stat_mod_folio(folio, NR_SHMEM_THPS, -nr); + else + lruvec_stat_mod_folio(folio, NR_FILE_THPS, -nr); } =20 if (folio_test_swapcache(folio)) { --=20 2.54.0 From nobody Mon Sep 28 04:55:37 2026 Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D564145D19F for ; Wed, 26 Aug 2026 16:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761283; cv=none; b=ZFIOwIdSvqmzgcYex3d+NJcIzQ23x/ftMaa9/N1Q7FQ6cTxRF2sKXbuyLPvql9DNO1eIfoi5IXGkDWRWPWmsFQHVIH+fPik/ef7dKwI+5fgToWXLbCVBthSb9bs6ZIQ+henE9hZJ/o68OuSwDP0dRYyw0LDfCXDFRhzpQ0FkXGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761283; c=relaxed/simple; bh=8zCsW+61D8x1V2jS30iFv0IIshOjw1HA3xm/0E5TtDs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sl1ox6D1d2HeX3LbjlAP5uNzUEDbwCMZlw/ekG8W9faPGVY4eXVeDA0IUL99cuckPXd3TsVHs/wXfus24FTsN7pGDK3IpBBR5SZCMKlGuat29ENRXrNJWChwcfJM6P5F5uxfqYSeKKcwJ4uoXdQpvzhl6yFjDL22qP4RgYISC9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name; spf=pass smtp.mailfrom=shutemov.name; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b=BP8PYztG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OZkFPany; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shutemov.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shutemov.name header.i=@shutemov.name header.b="BP8PYztG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OZkFPany" Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 1949CEC01B8; Wed, 26 Aug 2026 12:21:17 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Wed, 26 Aug 2026 12:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1787761277; x= 1787847677; bh=5mSjV0I5LbWvQ9sczjJL6C6KyVdbqTRz8cyjnim/Edo=; b=B P8PYztGw2WCo+TvJSt+P6YuyWjwWc6g3OnhflMvlOKY73JNJqQZAS8rWpIkxa7jS 5sy6kSLTNR6ZXg7Ye3++lUvIyDTBwJxL30+fyxiy8aWJ9Qs29R9VAsAP51Fq+dVi TORC/TNINXsILdoMIPh1jA/L6ujS/OddMjvAzebYyDDz9x6F5iEW/t9ulpIAamRl E+9VniKxIojwVi9x1hzFV8j2bVbrmhe3a3oytIexxkiCjpAM9t1z5tVm9uEicNF+ TdMVh97zYqfBKWb8qK/G7fO9UKHp+DJg2/O9wTVyX60e0vx55u4hiwMd9gOfrHq4 WFmzBNonn6CLm/ONCxPbA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1787761277; x=1787847677; bh=5 mSjV0I5LbWvQ9sczjJL6C6KyVdbqTRz8cyjnim/Edo=; b=OZkFPanygMXeDszE7 n2A4Y4veWU+G9z5j3qcLApIpDZxDsfy/clS/lf3LKvFGzEQpIhjq0CLjDJ/LY4iU wJXNO/TFbHOHNsVa6hVWL9BI8vGauPInF2P44IMTVQji1L7XvJ2KMJpUJMTWAyf2 4iSVkSvGu7Ri/5EWzwtjPZCNSPMEV9jqn8z4vIDbqqdPu4MTYtWBplRcSLQS14zj tIk5ZcFrKYMRWOa0bxyLEjqOuGIkHp7nasSHI5yGXrW5GTUI0vuOF/zN2VWFMCuw 3Q5ZwLeKtXZbMBBmzhx7boygrk7vUcVle72ejnI4G5A/XG6RxL1WEzSeYpFOdkK5 Cstgg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEpX8HBQysEAMlAbdyKFX4BLzWtS7+Qo1RjxAJeMJnS381384CQaxM92QA8W5J6jo 7r0RHbsPcTs1IpTXqcOu2ofgimA8w2hMK3OeOMvPUWs2NDJNBlDL/23E29uU3eWq90a8Ny uayj7GqONoh0NEQ91mQ/H+TE3rTPuVZ+wfrdHbeyaEyRe40ZIUYJyXTHqnubEDskXnqfPu FIQsvLmT+4mxeisAsg0TmWv4Y7l9NdKef8tTMihpDmjKvNxij8lw310+ofBfGEkzSLqnuN AyozbfZUQr702Kz+RkXguKuGQfBCnKcQhC5EFdpLjS6L6jWqh1sGvO+4Vl+gX27JPRP8Ht szkLAhJPkmHmsMuK+YkYr9yTyscVe3c0bf17pnNuHqUsHycYFqkLlrF5TB5u7lUu8OB/wM DV5bI0v3NOIPdRF9o4laEl7rxuvns0/4qf6WByMLMYQby4xvvTzd619MkHG7vrfgrIajil 9xrS+oFmBCtWr0VBzXNyMXnf0FwgHZ5PK75YysAf2sIgyHUj7LJL1q92xLX6X1MBq4U7uW lhwF/3qJ1OK36392uADRBMFSzHu8Lqs4TMnvmDfirdJRnCCZGu0TGiK789fROlpmrPHxnW Q4Y5yNtbL6/Q5184MpQJ3sa7GKBP7KWtEmd2SUmUnu6UiB8GFfT1xjDdsnxA X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 26 Aug 2026 12:21:16 -0400 (EDT) From: Kiryl Shutsemau To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org, usama.arif@linux.dev Cc: lance.yang@linux.dev, ziy@nvidia.com, hughd@google.com, baolin.wang@linux.alibaba.com, baohua@kernel.org, liam@infradead.org, nico.pache@linux.dev, dev.jain@arm.com, ryan.roberts@arm.com, balbirs@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kiryl Shutsemau (Meta)" Subject: [PATCH 5/5] mm/huge_memory: turn the swapcache-with-mapping error case into an assert Date: Wed, 26 Aug 2026 17:21:01 +0100 Message-ID: <20260826162101.1314941-6-kirill@shutemov.name> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826162101.1314941-1-kirill@shutemov.name> References: <20260826162101.1314941-1-kirill@shutemov.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Kiryl Shutsemau (Meta)" A folio in the swapcache has no mapping. __folio_freeze_and_split_unmapped() tests the combination after the freeze and returns -EINVAL. It leaves the folio frozen. It is not a real recovery. Assert the condition with VM_WARN_ON_ONCE_FOLIO() upfront, and do not pretend to recover from an impossible state. PG_swapcache is protected by the folio lock and stable from the start of the function. Assisted-by: Claude-Code:claude-opus-5 Signed-off-by: Kiryl Shutsemau (Meta) --- mm/huge_memory.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 001d89c57fa2..8fc844ba67a1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3936,6 +3936,7 @@ static int __folio_freeze_and_split_unmapped(struct f= olio *folio, unsigned int n int ret =3D 0; =20 VM_WARN_ON_ONCE(!mapping && end); + VM_WARN_ON_ONCE_FOLIO(mapping && folio_test_swapcache(folio), folio); =20 if (!folio_ref_freeze(folio, folio_cache_ref_count(folio) + 1)) return -EAGAIN; @@ -3965,14 +3966,8 @@ static int __folio_freeze_and_split_unmapped(struct = folio *folio, unsigned int n lruvec_stat_mod_folio(folio, NR_FILE_THPS, -nr); } =20 - if (folio_test_swapcache(folio)) { - if (mapping) { - VM_WARN_ON_ONCE_FOLIO(mapping, folio); - return -EINVAL; - } - + if (folio_test_swapcache(folio)) ci =3D swap_cluster_get_and_lock(folio); - } =20 /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ if (do_lru) --=20 2.54.0