zswap: do not map same object twice
authorVitaly Wool <vitalywool@gmail.com>
Mon, 23 Sep 2019 22:39:43 +0000 (15:39 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 Sep 2019 22:54:12 +0000 (15:54 -0700)
zswap_writeback_entry() maps a handle to read swpentry first, and
then in the most common case it would map the same handle again.
This is ok when zbud is the backend since its mapping callback is
plain and simple, but it slows things down for z3fold.

Since there's hardly a point in unmapping a handle _that_ fast as
zswap_writeback_entry() does when it reads swpentry, the
suggestion is to keep the handle mapped till the end.

Link: http://lkml.kernel.org/r/20190916004640.b453167d3556c4093af4cf7d@gmail.com
Signed-off-by: Vitaly Wool <vitalywool@gmail.com>
Reviewed-by: Dan Streetman <ddstreet@ieee.org>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Vitaly Wool <vitalywool@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/zswap.c

index 08b6cefae5d84a9f53d5656326bd4f2a96dc0c89..46a322316e52c92fcb95f443d2e4ca3c00cb7955 100644 (file)
@@ -856,7 +856,6 @@ static int zswap_writeback_entry(struct zpool *pool, unsigned long handle)
        /* extract swpentry from data */
        zhdr = zpool_map_handle(pool, handle, ZPOOL_MM_RO);
        swpentry = zhdr->swpentry; /* here */
-       zpool_unmap_handle(pool, handle);
        tree = zswap_trees[swp_type(swpentry)];
        offset = swp_offset(swpentry);
 
@@ -866,6 +865,7 @@ static int zswap_writeback_entry(struct zpool *pool, unsigned long handle)
        if (!entry) {
                /* entry was invalidated */
                spin_unlock(&tree->lock);
+               zpool_unmap_handle(pool, handle);
                return 0;
        }
        spin_unlock(&tree->lock);
@@ -886,15 +886,13 @@ static int zswap_writeback_entry(struct zpool *pool, unsigned long handle)
        case ZSWAP_SWAPCACHE_NEW: /* page is locked */
                /* decompress */
                dlen = PAGE_SIZE;
-               src = (u8 *)zpool_map_handle(entry->pool->zpool, entry->handle,
-                               ZPOOL_MM_RO) + sizeof(struct zswap_header);
+               src = (u8 *)zhdr + sizeof(struct zswap_header);
                dst = kmap_atomic(page);
                tfm = *get_cpu_ptr(entry->pool->tfm);
                ret = crypto_comp_decompress(tfm, src, entry->length,
                                             dst, &dlen);
                put_cpu_ptr(entry->pool->tfm);
                kunmap_atomic(dst);
-               zpool_unmap_handle(entry->pool->zpool, entry->handle);
                BUG_ON(ret);
                BUG_ON(dlen != PAGE_SIZE);
 
@@ -940,6 +938,7 @@ fail:
        spin_unlock(&tree->lock);
 
 end:
+       zpool_unmap_handle(pool, handle);
        return ret;
 }