This patch encapsulates away the computes for compressing the pages in a folio and storing the compressed memory in zpool, into a distinct zswap_compress_folio() procedure. For now, zswap_compress_folio() simply calls zswap_compress() for each page in the folio it is called with. This facilitates adding compress batching in subsequent patches. Signed-off-by: Kanchana P Sridhar <kanchana.p.sridhar@xxxxxxxxx> --- mm/zswap.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index af682bf0f690..6563d12e907b 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1509,6 +1509,22 @@ static void shrink_worker(struct work_struct *w) * main API **********************************/ +static bool zswap_compress_folio(struct folio *folio, + struct zswap_entry *entries[], + struct zswap_pool *pool) +{ + long index, nr_pages = folio_nr_pages(folio); + + for (index = 0; index < nr_pages; ++index) { + struct page *page = folio_page(folio, index); + + if (!zswap_compress(page, entries[index], pool)) + return false; + } + + return true; +} + /* * Store all pages in a folio. * @@ -1542,12 +1558,8 @@ static bool zswap_store_folio(struct folio *folio, entries[index]->handle = (unsigned long)ERR_PTR(-EINVAL); } - for (index = 0; index < nr_pages; ++index) { - struct page *page = folio_page(folio, index); - - if (!zswap_compress(page, entries[index], pool)) - goto store_folio_failed; - } + if (!zswap_compress_folio(folio, entries, pool)) + goto store_folio_failed; for (index = 0; index < nr_pages; ++index) { swp_entry_t page_swpentry = page_swap_entry(folio_page(folio, index)); -- 2.27.0