From: SeongJae Park Date: Wed, 27 Aug 2025 20:18:38 +0000 (-0700) Subject: mm/zswap: cleanup incompressible pages handling code X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=faa91e516bce67de75a48aa9bf2138c37037b1b0;p=users%2Fjedix%2Flinux-maple.git mm/zswap: cleanup incompressible pages handling code Following Chris Li's suggestions [1], make the code easier to read and manage. Link: https://lkml.kernel.org/r/20250828163913.57957-1-sj@kernel.org Kink: https://lore.kernel.org/CACePvbWGPApYr7G29FzbmWzRw-BJE39WH7kUHSaHs+Lnw8=-qQ@mail.gmail.com [1] Signed-off-by: SeongJae Park Acked-by: Chris Li Cc: Baoquan He Cc: Barry Song Cc: Chengming Zhou Cc: David Hildenbrand Cc: Johannes Weiner Cc: Kairui Song Cc: Nhat Pham Cc: Takero Funaki Signed-off-by: Andrew Morton --- diff --git a/mm/zswap.c b/mm/zswap.c index 0ec239aae9bc..0c8dd8876d8e 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -952,6 +952,7 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry, struct zpool *zpool; gfp_t gfp; u8 *dst; + bool mapped = false; acomp_ctx = acomp_ctx_get_cpu_lock(pool); dst = acomp_ctx->buffer; @@ -988,9 +989,8 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry, * only adds metadata overhead. swap_writeout() will put the page back * to the active LRU list in the case. */ - if (comp_ret || !dlen) + if (comp_ret || !dlen || dlen >= PAGE_SIZE) { dlen = PAGE_SIZE; - if (dlen >= PAGE_SIZE) { if (!mem_cgroup_zswap_writeback_enabled( folio_memcg(page_folio(page)))) { comp_ret = comp_ret ? comp_ret : -EINVAL; @@ -999,6 +999,7 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry, comp_ret = 0; dlen = PAGE_SIZE; dst = kmap_local_page(page); + mapped = true; } zpool = pool->zpool; @@ -1012,7 +1013,7 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry, entry->length = dlen; unlock: - if (dst != acomp_ctx->buffer) + if (mapped) kunmap_local(dst); if (comp_ret == -ENOSPC || alloc_ret == -ENOSPC) zswap_reject_compress_poor++; @@ -1030,7 +1031,7 @@ static bool zswap_decompress(struct zswap_entry *entry, struct folio *folio) struct zpool *zpool = entry->pool->zpool; struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; - int decomp_ret, dlen; + int decomp_ret = 0, dlen = PAGE_SIZE; u8 *src, *obj; acomp_ctx = acomp_ctx_get_cpu_lock(entry->pool); @@ -1039,9 +1040,7 @@ static bool zswap_decompress(struct zswap_entry *entry, struct folio *folio) /* zswap entries of length PAGE_SIZE are not compressed. */ if (entry->length == PAGE_SIZE) { memcpy_to_folio(folio, 0, obj, entry->length); - zpool_obj_read_end(zpool, entry->handle, obj); - acomp_ctx_put_unlock(acomp_ctx); - return true; + goto read_done; } /* @@ -1064,6 +1063,7 @@ static bool zswap_decompress(struct zswap_entry *entry, struct folio *folio) decomp_ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait); dlen = acomp_ctx->req->dlen; +read_done: zpool_obj_read_end(zpool, entry->handle, obj); acomp_ctx_put_unlock(acomp_ctx);