]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/zswap: cleanup incompressible pages handling code
authorSeongJae Park <sj@kernel.org>
Wed, 27 Aug 2025 20:18:38 +0000 (13:18 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:24:56 +0000 (17:24 -0700)
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 <sj@kernel.org>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: David Hildenbrand <david@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Takero Funaki <flintglass@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/zswap.c

index 0ec239aae9bcf54a752def2faeb17b8e01e62382..0c8dd8876d8eec17da47a65afd66def744a2d9de 100644 (file)
@@ -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);