mm/zswap: convert zswap_store_page() and zswap_compress() to take a folio
Subsystems (2)
PATCH 1/1 mm/zswap: convert zswap_store_page() and zswap_compress() to take a folio
Currently, zswap_store() iterates through a folio and extracts individual struct page pointers using folio_page() to pass into zswap_store_page() and zswap_compress().
Pass the folio and the page index directly into these functions instead. This eliminates the need to materialize struct page pointers inside the zswap_store() loop and replaces legacy page-based accessors with their folio equivalents:
- sg_set_page() -> sg_set_folio()
- kmap_local_page() -> kmap_local_folio()
- page_to_nid() -> folio_nid()
- page_swap_entry() -> calculated via folio->swap and index
--- mm/zswap.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
mm/zswap.c +12 -14
@@ -837,8 +837,8 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)return ret; } -static bool zswap_compress (struct page *page,struct zswap_entry *entry, -struct zswap_pool *pool) +static bool zswap_compress (struct folio *folio,long index, +struct zswap_entry *entry,struct zswap_pool *pool) {struct crypto_acomp_ctx *acomp_ctx;struct scatterlist input, output;
@@ -854,7 +854,7 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry, dst = acomp_ctx->buffer;sg_init_table (&input,1 ); -sg_set_page (&input, page,PAGE_SIZE ,0 ); +sg_set_folio (&input, folio,PAGE_SIZE , index *PAGE_SIZE );sg_init_one (&output, dst,PAGE_SIZE );acomp_request_set_params (acomp_ctx->req, &input, &output,PAGE_SIZE , dlen);
@@ -883,8 +883,7 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,*/ if (comp_ret || !dlen || dlen >=PAGE_SIZE ) {rcu_read_lock (); -if (!mem_cgroup_zswap_writeback_enabled ( -folio_memcg (page_folio (page)))) { +if (!mem_cgroup_zswap_writeback_enabled (folio_memcg (folio))) {rcu_read_unlock (); comp_ret = comp_ret ? comp_ret : -EINVAL ; goto unlock;
@@ -892,12 +891,12 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,rcu_read_unlock (); comp_ret =0 ; dlen =PAGE_SIZE ; - dst =kmap_local_page (page); + dst =kmap_local_folio (folio, index *PAGE_SIZE ); mapped = true; } gfp =GFP_NOWAIT | __GFP_NORETRY | __GFP_HIGHMEM | __GFP_MOVABLE; - handle =zs_malloc (pool->zs_pool, dlen, gfp,page_to_nid (page)); + handle =zs_malloc (pool->zs_pool, dlen, gfp,folio_nid (folio));if (IS_ERR_VALUE (handle)) { alloc_ret =PTR_ERR ((void *)handle); goto unlock;
@@ -1405,21 +1404,22 @@ static void shrink_worker(struct work_struct *w)* main API **********************************/ -static bool zswap_store_page (struct page *page, +static bool zswap_store_page (struct folio *folio,long index,struct obj_cgroup *objcg,struct zswap_pool *pool) { -swp_entry_t page_swpentry =page_swap_entry (page); +swp_entry_t page_swpentry =swp_entry (swp_type (folio->swap), +swp_offset (folio->swap) + index);struct zswap_entry *entry, *old;/* allocate entry */ - entry =zswap_entry_cache_alloc (GFP_KERNEL ,page_to_nid (page)); + entry =zswap_entry_cache_alloc (GFP_KERNEL ,folio_nid (folio));if (!entry) { zswap_reject_kmemcache_fail++;return false; } -if (!zswap_compress (page, entry, pool)) +if (!zswap_compress (folio, index, entry, pool)) goto compress_failed; old = xa_store(swap_zswap_tree(page_swpentry),
@@ -1528,9 +1528,7 @@ bool zswap_store(struct folio *folio) }for (index =0 ; index < nr_pages; ++index) { -struct page *page =folio_page (folio, index); - -if (!zswap_store_page (page, objcg, pool)) +if (!zswap_store_page (folio, index, objcg, pool)) goto put_pool; }
Signature · 1 line
2.55.0.979.g7e5102b832-goog
Quoted 9 lines
Currently,
zswap_store()iterates through a folio and extracts individual struct page pointers usingfolio_page()to pass intozswap_store_page()andzswap_compress().Pass the folio and the page index directly into these functions instead. This eliminates the need to materialize struct page pointers inside the
zswap_store()loop and replaces legacy page-based accessors with their folio equivalents:
Quoted 7 lines
-
sg_set_page()->sg_set_folio()
-kmap_local_page()->kmap_local_folio()
-page_to_nid()->folio_nid()
-page_swap_entry()-> calculated viafolio->swapand indexSigned-off-by Wilson Felipe Pereira <[email protected]>
I have a very similar patch as part of a larger series here [1]. It looks like we mostly aligned apart from a helper the series introduces, so I can easily rebase on top of this if this is applied, so:
[1]: https://lore.kernel.org/linux-mm/[email protected]/
Signature · 1 line
Tal Zussman <[email protected]>