Skip to content

Commit 1326359

Browse files
ryncsnakpm00
authored andcommitted
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/[email protected] Signed-off-by: Kairui Song <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Cc: Baoquan He <[email protected]> Cc: Barry Song <[email protected]> Cc: Chris Li <[email protected]> Cc: Dev Jain <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Kemeng Shi <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Nhat Pham <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 69805ea commit 1326359

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

mm/shmem.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,40 +2357,33 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
23572357
count_memcg_event_mm(fault_mm, PGMAJFAULT);
23582358
}
23592359

2360-
/* Skip swapcache for synchronous device. */
23612360
if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
2361+
/* Direct swapin skipping swap cache & readahead */
23622362
folio = shmem_swap_alloc_folio(inode, vma, index, swap, order, gfp);
2363-
if (!IS_ERR(folio)) {
2364-
skip_swapcache = true;
2365-
goto alloced;
2363+
if (IS_ERR(folio)) {
2364+
error = PTR_ERR(folio);
2365+
folio = NULL;
2366+
goto failed;
23662367
}
2367-
2368+
skip_swapcache = true;
2369+
} else {
23682370
/*
2369-
* Direct swapin handled order 0 fallback already,
2370-
* if it failed, abort.
2371+
* Cached swapin only supports order 0 folio, it is
2372+
* necessary to recalculate the new swap entry based on
2373+
* the offset, as the swapin index might be unalgined.
23712374
*/
2372-
error = PTR_ERR(folio);
2373-
folio = NULL;
2374-
goto failed;
2375-
}
2376-
2377-
/*
2378-
* Now swap device can only swap in order 0 folio, it is
2379-
* necessary to recalculate the new swap entry based on
2380-
* the offset, as the swapin index might be unalgined.
2381-
*/
2382-
if (order) {
2383-
offset = index - round_down(index, 1 << order);
2384-
swap = swp_entry(swp_type(swap), swp_offset(swap) + offset);
2385-
}
2375+
if (order) {
2376+
offset = index - round_down(index, 1 << order);
2377+
swap = swp_entry(swp_type(swap), swp_offset(swap) + offset);
2378+
}
23862379

2387-
folio = shmem_swapin_cluster(swap, gfp, info, index);
2388-
if (!folio) {
2389-
error = -ENOMEM;
2390-
goto failed;
2380+
folio = shmem_swapin_cluster(swap, gfp, info, index);
2381+
if (!folio) {
2382+
error = -ENOMEM;
2383+
goto failed;
2384+
}
23912385
}
23922386
}
2393-
alloced:
23942387
if (order > folio_order(folio)) {
23952388
/*
23962389
* Swapin may get smaller folios due to various reasons:

0 commit comments

Comments
 (0)