From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFE92606A322 for ; Fri, 4 Dec 2026 22:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WqN+tzna Received: by kanga.kvack.org (Postfix) id 700036B05BC; Fri, 4 Dec 2026 17:09:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D7656B05BE; Fri, 4 Dec 2026 17:09:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A09C6B05BF; Fri, 4 Dec 2026 17:09:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 236C26B05BC for ; Fri, 4 Dec 2026 17:09:24 -0500 (EST) Received: from smtpin19.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 741314054A for ; Fri, 4 Dec 2026 22:09:23 +0000 (UTC) X-FDA: 85507692606.19.D740308 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf07.hostedemail.com (Postfix) with ESMTP id BA5EF40006 for ; Fri, 4 Dec 2026 22:09:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=WqN+tzna; spf=pass (imf07.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796422161; b=xWUY3IdMd/B9m83yzbs+3xJGjWsjd2EyJLcTEPEZG5SpLqs2RRCL/ZJSkqGEuLyH7cRIh3 qBxe0QG6SHj5doXmj60Lvge09QjICiCY1XGaNdM+4GqGl3q5veE+MabSwnd6xNWiulIO0w Sl9vlOxRVlRfjuTdRd4p/vos2+deOZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796422161; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wjBi+ywid+zZHWxj37Npx0YnJwbSt+R2GJEs+chNVVs=; b=WfT9hx50VrgxkSO5PDhS+Z4ovfU6VYxNCfWpltqUBC4HQVHjHh6OOLFrxGlCXB9u1m+PL8 zlIs1pcx5bTKdlFhIiKbuBQkoAFX/qEnDIYYuOfICZZx74pAiXkbxTuwATgBp0mB+Y/KUx Y3GM8mVGOUfuyDFC4rO784VXbpnlg2o= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=WqN+tzna; spf=pass (imf07.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 10BFD407FC; Fri, 4 Dec 2026 22:09:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A92A41F00936; Fri, 4 Dec 2026 22:09:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796422160; bh=wjBi+ywid+zZHWxj37Npx0YnJwbSt+R2GJEs+chNVVs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=WqN+tznav1Vm3tA8VId6uSUSWoCsApekd17taQccQg59peCEs4CSgVIoBoLmF7Zon EhGkJEgfXUM8yqvT/ur7Ogvp9buKAj9mbg2E0Kn7Ay0nfjdisXOEGy+RrbcsOeWkzP DB1XIcEHXw9O/Fo61eJw4pVxK36nxoo0qMg+bHQL/jsnPiD1LRlgy8mLnPWDguPH9p rkv8LeQqWAWoFr0mzKnVzDtnleS/zlyKzYmYlHVC1ptZ3NehdLRLb4tv9WImr3BJd4 MexLAYbDViTikz7haUyI43UPLTfvMJigsgD9njfSS5ngaAr510WBMxlI8Z3YIWO4H+ djZjSV9+mEFdg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 07/20] mm/swap: prepare physical swapoff for virtual backing Reply-To: sashiko-reviews@lists.linux.dev To: "Nhat Pham" , linux-mm@kvack.org Cc: "Andrew Morton" , "Chris Li" , "Kairui Song" , "Kemeng Shi" , "Baoquan He" , "Barry Song" , "Youngjun Park" , "Johannes Weiner" , "Yosry Ahmed" , "Chengming Zhou" , "Qi Zheng" , "Shakeel Butt" , "Axel Rasmussen" , "Yuanchu Xie" , "Wei Xu" , "Baolin Wang" , "Michal Hocko" , "David Hildenbrand" , "Liam R. Howlett" , "Vlastimil Babka" , "Mike Rapoport" , "Hugh Dickins" , "Jonathan Corbet" , "Shuah Khan" , "Randy Dunlap" , "Roman Gushchin" , "Muchun Song" , "Arnd Bergmann" , "Karl Mehltretter" , "Dapeng Mi" , "Marco Elver" , "Ethan Nelson-Moore" , =?utf-8?b?Qm9yaXNsYXYgUGV0a292IChBTUQp?= , "Jeff Layton" , "Tejun Heo" , =?utf-8?b?TWljaGFsIEtvdXRuw70=?= In-Reply-To: <20261203220010.1302207-8-nphamcs@gmail.com> References: <20261203220010.1302207-1-nphamcs@gmail.com> <20261203220010.1302207-8-nphamcs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 22:09:19 +0000 X-Rspam-User: X-Rspamd-Queue-Id: BA5EF40006 X-Rspamd-Server: rspam03 X-Stat-Signature: ukotm89d1cxzgeogs8eo5rjimpx4row6 X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796422161-596322 X-HE-Meta: U2FsdGVkX1/QICQ4tt7w9dehSzZmJ856P6bkRc4SW7RTT1J0GRRKH83Mhw8DQEEpPIqw7m13mGPD+nxy5cycRp8rflxXsN5MFc1ZaCUkvPq5A2n5mv4srx2/ZAAISXxr8OQ2g+lKzn/EqjzipF/4dSdqYtIv/I4Rm4QaK5bqrV3l9iaFClTCaik6sMiu5A61T70WwpKh3TgnlqacfpnfXz1wHR+U7niGNaSHiciyuwNjFqX9481Hs9ueRHKBOp1wiVPuFXRWlRpWr9Fkht6DBW7ZoYJjwpKjCetU3F5+VwciWO6S3b0JNyt2Wy8fqxpC1kCeDkMVLOvEK0QAiYrdxo9q+RM4xzOjBfyEBEDcMpI7CP6yRUTHd+2PYa2y6o65juN+AZehr8TJbzvYJU7IcJflwIsrEjV4QYQs/uQFTvJnpLp2sxchkgh5/6WL3zLjBLxA98bXGErQuvWiAqRvjSsOhdwtSr1T8c2mLEdE+dh/LzXW/K1qTO/3PgCwVsdRIyGJpE19Slbpnqlilv3lsFpR9VCBIgPMi8wLNBxuTDLVTP34hymV58Wd+ISaVd3CXMOQQhcHVMd0knE7VfU0CP5q0oIIHQUOX5QOKvM6nmB4r4jywblm7NSe9nSCTx0BzyPHaAbQPBQNq9TkpYglFdL1HvhZtE/4mpAa6frmV6aZANTlzwP4daTlcId+By/2AgeqEDQrPrXNFdGx2/zm4oAIwip6YlHJ37YkK3tfXu9cuBrTaTmRa0uxhGdpOu5sqdEwjPhkumywuNm667x5urwmd66JBtmLUpEt1D5D2fYlYif636bNvm8yLrTVHGgmxbtfpev35oflQSBkK6Ai5RE0hutEAnpqsab9BdGzH9eOl4bHpIkHrWA4cUFOhKJ6CQZF7Qe+Xk3T1FW9cXQ0oJsRoqhdg1OM9948UVyi04bIPLQXyKmX5SDoj+NJii68YCZxw0ZKhNjXkSef+ep 7jaWHxum QTt2/osmcxm3ipTVw3XGhi/5BzBhrl1OKzZ0lnO1TJmStfQsPvrqLnrY4PROnNo5Wp4AXK0LnrhXtt58tLPdMtAB5KzRV7r54vru/IXh1NC4EhM06RxjSje+cIvbjjdbURF8s6pLn19sBkDsd443BvPe3+sdpijMfbHi1BCSAi+u6OogxQuOTWYUBne+9G4iG6qy2mqa0OEOkdlPO+UoIFyU0r/i0VdCJTxq3N+xTptqyWJBmjfgwufTRhqzdZw/93TZ3nbQF4s+MRhjCdoqMqtjgMmYm8pjktQ6mzWNztY0lL33+8Tb147IvCLcLgFVksUcgGKBicrrGrAKSpDJzIj9VijXGJPI7Itlyr75o/W4vDOai+SZMiGejKl5DLiq8JtwqJ4a4TR4nmZ6mSm3K+7Flq+pTksxkdvR0cym2vfv3UODauTDnTfkCQ4Qhj6/nx4MxT29wFmC+KQCfJPsSSvYLm+KW211wuUNOWpyJWPmFZFzXdkRpZArHT7FmuQIaJ1vhlE8DixWaf3AatfBVV8z8kKQLAPIhkDIOUV7TrVKUPn0/NVGOFJ9aEAbunX1xDNodkttJoA8rHSUPO0zgdE1hEdK25kni7U/auB1qMw10GxoO7KBThRz8/lLpteTXz2UkSabOOwjEHjM8fJ0w1RLZBTXCgJkUEISAZxiC6gH317IXuTnXeLg7fIW219911CAdV0mUllQnD4M9qCglzlG07WyLDfkqe4umCZhGaEL+Uu2Jmv4RpuzrnU1shrTS4q0evLePz++zq44tUmepvSYqfTCa9CCB6JOUXnoGVZSB8yITOEGTdlFYsnUlOutVk1ti Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] mm/swap: spurious swapoff -ENOMEM when unuse_pte_range() discards -ENOENT - [Medium] mm/swap: swapoff loses readahead and I/O batching for vswap entries - [Medium] mm: shmem_find_swap_entries() takes xa_lock_irq and restarts walk per entry - [Medium] mm/shmem: shmem_find_swapoff_entry() relocks vswap cluster per sub-slot -- commit f05da385c356349b81af60a33b89b354ca7cc636 Author: Nhat Pham mm/swap: prepare physical swapoff for virtual backing This commit updates physical swapoff in shmem and swapfile to match virtual swap entries backed by the device being removed, resolve physical reverse maps during the swap cache walk, and use order-0 allocations when reading vswap entries during unuse. > diff --git a/mm/shmem.c b/mm/shmem.c > index 344f7edf5e15a..5d68075184746 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c [ ... ] > @@ -1710,6 +1713,24 @@ static void shmem_evict_inode(struct inode *inode) > #endif > } > =20 > +static bool shmem_find_swapoff_entry(swp_entry_t entry, pgoff_t *index, > + unsigned int order, unsigned int type) > +{ > + unsigned long nr =3D 1UL << order; > + unsigned long off =3D *index & (nr - 1); > + > + if (!softleaf_is_swap(entry)) > + return false; > + entry.val +=3D off; > + for (; off < nr; off++, entry.val++) { > + if (swap_entry_is_backed_by(entry, type)) { > + *index =3D round_down(*index, nr) + off; > + return true; > + } > + } > + return false; > +} [Severity: Medium] Can this loop avoid re-looking up and relocking the same vswap cluster for every sub-slot of a large shmem swap entry? For a large entry (up to 512 sub-slots for a 2 MiB THP on 4 KiB pages) backed by zswap or another swap device, swap_entry_is_backed_by() -> vswap_to_phys() walks vswap_si->cluster_info_pool and acquires/releases ci->lock on each iteration, even though all sub-slots of a large entry reside in a single vswap cluster. Because shmem_find_swap_entries() calls this under rcu_read_lock() and continues past cond_resched_rcu() on non-matching entries, scanning large non-matching shmem files also extends the RCU read-side critical section across those lookups and lock round-trips. Locking the vswap cluster once and scanning the contiguous range in its virtual_table would eliminate the redundant XArray walks and lock cycles. [ ... ] > @@ -1726,15 +1749,27 @@ static unsigned int shmem_find_swap_entries(struc= t address_space *mapping, > if (!xa_is_value(folio)) > continue; > =20 > + /* A concurrent collapse can change both the value and its order. */ > + xas_lock_irq(&xas); > + xas_set(&xas, xas.xa_index); > + folio =3D xas_load(&xas); > + if (!xa_is_value(folio)) { > + xas_unlock_irq(&xas); > + continue; > + } > entry =3D radix_to_swp_entry(folio); > + index =3D xas.xa_index; > + order =3D xas_get_order(&xas); > + xas_unlock_irq(&xas); [Severity: Medium] Does taking xas_lock_irq(&xas) and restarting the XArray walk on every swap entry regress swapoff scanning on large swapped shmem files? shmem_unuse() scans every inode on shmem_swaplist regardless of which swap device or zswap backs it. xas_set() resets xas->xa_node to XAS_RESTART, so xas_load() re-descends from the root on every entry while repeatedly disabling IRQs and taking mapping->i_pages.xa_lock in contention with active shmem faults and reads. When CONFIG_THP_SWAP is disabled, shmem swap entries are always order 0 and need no lock; with CONFIG_THP_SWAP, batching entries under a single xas_lock_irq() acquisition with xas_pause() before unlocking would preserve sequential leaf scanning and reduce lock contention. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index d9e8c9365c447..6933e069bd2ea 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -2974,8 +3011,15 @@ static int unuse_pte_range(struct vm_area_struct *= vma, pmd_t *pmd, > .pmd =3D pmd, > }; > =20 > - folio =3D swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, > - &vmf); > + if (is_vswap_entry(entry)) { > + folio =3D swapin_sync(entry, GFP_HIGHUSER_MOVABLE, > + BIT(0), &vmf, NULL, 0); > + if (IS_ERR(folio)) > + folio =3D NULL; > + } else { > + folio =3D swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, > + &vmf); > + } [Severity: Medium] Will switching vswap entries to swapin_sync() with BIT(0) here and in shmem_swapin_folio() drop swapoff readahead and I/O batching? Previously, unuse_pte_range() called swapin_readahead() and shmem_swapin_folio() called shmem_swapin_cluster(), both of which plug the block queue, merge contiguous reads, and pipeline I/O across a readahead window. swapin_sync() submits a single un-plugged 4 KiB read and returns directly to folio_lock(folio), serializing physical swapoff to queue-depth-1 4 KiB synchronous reads. In shmem_swapin_folio(), forcing order 0 also triggers shmem_split_large_entry() on every large swap entry, and because shmem_unuse_inode() advances start to the last batched index, split siblings of earlier entries in a batch are deferred to subsequent try_to_unuse() retry passes. > } > if (!folio) { > swp_tb =3D swap_table_lookup(entry); [Severity: Medium] Could discarding ERR_PTR(-ENOENT) from swapin_sync() cause swapoff(2) to fail spuriously with -ENOMEM? Unlike a physical swap device being removed, which has SWP_WRITEOK cleared before try_to_unuse(), vswap_si stays writable throughout physical swapoff so a freed vswap slot can be reallocated immediately: CPU0 (swapoff) CPU1 unuse_pte_range() pte_unmap(pte) do_swap_page() / zap_pte_range() frees vswap slot (count -> 0) swapin_sync(entry, ...) __swap_cache_add_check() returns ERR_PTR(-ENOENT) folio =3D NULL swapout on live vswap_si reallocates same vswap slot (count >=3D 1) swap_table_lookup(entry) swp_tb_get_count(swp_tb) > 0 return -ENOMEM <-- aborts swapoff(2) The spurious -ENOMEM propagates out of try_to_unuse(), causing swapoff(2) to fail and reinsert the swap device even though no allocation failed. Checking PTR_ERR(folio) =3D=3D -ENOENT and continuing directly avoids the re-lookup race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203220010.1302= 207-1-nphamcs@gmail.com?part=3D7