Commit 1326359f authored by Kairui Song's avatar Kairui Song Committed by Andrew Morton
Browse files

mm/shmem, swap: simplify swapin path and result handling

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: default avatarKairui Song <kasong@tencent.com>
Reviewed-by: default avatarBaolin 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: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 69805ea7
Loading
Loading
Loading
Loading
+19 −26
Original line number Diff line number Diff line
@@ -2357,25 +2357,18 @@ 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;
			}

			/*
			 * Direct swapin handled order 0 fallback already,
			 * if it failed, abort.
			 */
			if (IS_ERR(folio)) {
				error = PTR_ERR(folio);
				folio = NULL;
				goto failed;
			}

			skip_swapcache = true;
		} else {
			/*
		 * Now swap device can only swap in order 0 folio, it is
			 * 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.
			 */
@@ -2390,7 +2383,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
				goto failed;
			}
		}
alloced:
	}
	if (order > folio_order(folio)) {
		/*
		 * Swapin may get smaller folios due to various reasons: