]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/shmem, swap: simplify swapin path and result handling
authorKairui Song <kasong@tencent.com>
Mon, 28 Jul 2025 07:53:04 +0000 (15:53 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 2 Aug 2025 19:06:13 +0000 (12:06 -0700)
Slightly tidy up the different handling of swap in and error handling for
SWP_SYNCHRONOUS_IO and non-SWP_SYNCHRONOUS_IO devices.  Now swapin will
always use either shmem_swap_alloc_folio or shmem_swapin_cluster, then
check the result.

Simplify the control flow and avoid a redundant goto label.

Link: https://lkml.kernel.org/r/20250728075306.12704-7-ryncsn@gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Chris Li <chrisl@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/shmem.c

index e6207ad6f2f108fc2dd703023ce1d9db428ac980..0de37d0145243942f802388181ff75c1507352e7 100644 (file)
@@ -2357,40 +2357,33 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
                        count_memcg_event_mm(fault_mm, PGMAJFAULT);
                }
 
-               /* Skip swapcache for synchronous device. */
                if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
+                       /* Direct swapin skipping swap cache & readahead */
                        folio = shmem_swap_alloc_folio(inode, vma, index, swap, order, gfp);
-                       if (!IS_ERR(folio)) {
-                               skip_swapcache = true;
-                               goto alloced;
+                       if (IS_ERR(folio)) {
+                               error = PTR_ERR(folio);
+                               folio = NULL;
+                               goto failed;
                        }
-
+                       skip_swapcache = true;
+               } else {
                        /*
-                        * Direct swapin handled order 0 fallback already,
-                        * if it failed, abort.
+                        * Cached swapin only supports order 0 folio, it is
+                        * necessary to recalculate the new swap entry based on
+                        * the offset, as the swapin index might be unalgined.
                         */
-                       error = PTR_ERR(folio);
-                       folio = NULL;
-                       goto failed;
-               }
-
-               /*
-                * Now swap device can only swap in order 0 folio, it is
-                * necessary to recalculate the new swap entry based on
-                * the offset, as the swapin index might be unalgined.
-                */
-               if (order) {
-                       offset = index - round_down(index, 1 << order);
-                       swap = swp_entry(swp_type(swap), swp_offset(swap) + offset);
-               }
+                       if (order) {
+                               offset = index - round_down(index, 1 << order);
+                               swap = swp_entry(swp_type(swap), swp_offset(swap) + offset);
+                       }
 
-               folio = shmem_swapin_cluster(swap, gfp, info, index);
-               if (!folio) {
-                       error = -ENOMEM;
-                       goto failed;
+                       folio = shmem_swapin_cluster(swap, gfp, info, index);
+                       if (!folio) {
+                               error = -ENOMEM;
+                               goto failed;
+                       }
                }
        }
-alloced:
        if (order > folio_order(folio)) {
                /*
                 * Swapin may get smaller folios due to various reasons: