Skip to content

Commit e947ba0

Browse files
Chengming Zhouakpm00
authored andcommitted
mm/zswap: cleanup zswap_writeback_entry()
Also after the common decompress part goes to __zswap_load(), we can cleanup the zswap_writeback_entry() a little. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Chengming Zhou <[email protected]> Reviewed-by: Yosry Ahmed <[email protected]> Reviewed-by: Nhat Pham <[email protected]> Acked-by: Chris Li <[email protected]> (Google) Cc: Barry Song <[email protected]> Cc: Dan Streetman <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Seth Jennings <[email protected]> Cc: Vitaly Wool <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 66447fd commit e947ba0

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

mm/zswap.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,6 @@ static int zswap_writeback_entry(struct zswap_entry *entry,
14341434
struct page *page;
14351435
struct mempolicy *mpol;
14361436
bool page_was_allocated;
1437-
int ret;
14381437
struct writeback_control wbc = {
14391438
.sync_mode = WB_SYNC_NONE,
14401439
};
@@ -1443,16 +1442,17 @@ static int zswap_writeback_entry(struct zswap_entry *entry,
14431442
mpol = get_task_policy(current);
14441443
page = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol,
14451444
NO_INTERLEAVE_INDEX, &page_was_allocated, true);
1446-
if (!page) {
1447-
ret = -ENOMEM;
1448-
goto fail;
1449-
}
1445+
if (!page)
1446+
return -ENOMEM;
14501447

1451-
/* Found an existing page, we raced with load/swapin */
1448+
/*
1449+
* Found an existing page, we raced with load/swapin. We generally
1450+
* writeback cold pages from zswap, and swapin means the page just
1451+
* became hot. Skip this page and let the caller find another one.
1452+
*/
14521453
if (!page_was_allocated) {
14531454
put_page(page);
1454-
ret = -EEXIST;
1455-
goto fail;
1455+
return -EEXIST;
14561456
}
14571457

14581458
/*
@@ -1466,8 +1466,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry,
14661466
if (zswap_rb_search(&tree->rbroot, swp_offset(entry->swpentry)) != entry) {
14671467
spin_unlock(&tree->lock);
14681468
delete_from_swap_cache(page_folio(page));
1469-
ret = -ENOMEM;
1470-
goto fail;
1469+
return -ENOMEM;
14711470
}
14721471
spin_unlock(&tree->lock);
14731472

@@ -1483,15 +1482,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry,
14831482
__swap_writepage(page, &wbc);
14841483
put_page(page);
14851484

1486-
return ret;
1487-
1488-
fail:
1489-
/*
1490-
* If we get here because the page is already in swapcache, a
1491-
* load may be happening concurrently. It is safe and okay to
1492-
* not free the entry. It is also okay to return !0.
1493-
*/
1494-
return ret;
1485+
return 0;
14951486
}
14961487

14971488
static int zswap_is_page_same_filled(void *ptr, unsigned long *value)

0 commit comments

Comments
 (0)