Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/shmem, swap: remove redundant error handling for replacing folio

Shmem may replace a folio in the swap cache if the cached one doesn't fit
the swapin's GFP zone. When doing so, shmem has already double checked
that the swap cache folio is locked, still has the swap cache flag set,
and contains the wanted swap entry. So it is impossible to fail due to an
XArray mismatch. There is even a comment for that.

Delete the defensive error handling path, and add a WARN_ON instead: if
that happened, something has broken the basic principle of how the swap
cache works, we should catch and fix that.

Link: https://lkml.kernel.org/r/20250916160100.31545-10-ryncsn@gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Suggested-by: Chris Li <chrisl@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: kernel test robot <oliver.sang@intel.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
84a7a982 fd8d4f86

+7 -25
+7 -25
mm/shmem.c
··· 2121 2121 /* Swap cache still stores N entries instead of a high-order entry */ 2122 2122 xa_lock_irq(&swap_mapping->i_pages); 2123 2123 for (i = 0; i < nr_pages; i++) { 2124 - void *item = xas_load(&xas); 2125 - 2126 - if (item != old) { 2127 - error = -ENOENT; 2128 - break; 2129 - } 2130 - 2131 - xas_store(&xas, new); 2124 + WARN_ON_ONCE(xas_store(&xas, new) != old); 2132 2125 xas_next(&xas); 2133 2126 } 2134 - if (!error) { 2135 - mem_cgroup_replace_folio(old, new); 2136 - shmem_update_stats(new, nr_pages); 2137 - shmem_update_stats(old, -nr_pages); 2138 - } 2127 + 2128 + mem_cgroup_replace_folio(old, new); 2129 + shmem_update_stats(new, nr_pages); 2130 + shmem_update_stats(old, -nr_pages); 2139 2131 xa_unlock_irq(&swap_mapping->i_pages); 2140 2132 2141 - if (unlikely(error)) { 2142 - /* 2143 - * Is this possible? I think not, now that our callers 2144 - * check both the swapcache flag and folio->private 2145 - * after getting the folio lock; but be defensive. 2146 - * Reverse old to newpage for clear and free. 2147 - */ 2148 - old = new; 2149 - } else { 2150 - folio_add_lru(new); 2151 - *foliop = new; 2152 - } 2133 + folio_add_lru(new); 2134 + *foliop = new; 2153 2135 2154 2136 folio_clear_swapcache(old); 2155 2137 old->private = NULL;