UPSTREAM: zram: use zram_slot_lock instead of raw bit_spin_lock op
authorMinchan Kim <minchan@kernel.org>
Wed, 3 May 2017 21:55:44 +0000 (14:55 -0700)
committerivanmeler <i_ivan@windowslive.com>
Wed, 13 Apr 2022 21:13:20 +0000 (21:13 +0000)
With this clean-up phase, I want to use zram's wrapper function to lock
table access which is more consistent with other zram's functions.

Link: http://lkml.kernel.org/r/1492052365-16169-4-git-send-email-minchan@kernel.org
Signed-off-by: Minchan Kim <minchan@kernel.org>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 86c49814d449ebc51c7d455ac8e3d17b9fa702eb)
Signed-off-by: Peter Kalauskas <peskal@google.com>
Bug: 112488418
Change-Id: I6afee89dce63dff6d759c78e25926814fc016107

drivers/block/zram/zram_drv.c

index e480eaff18064250c26c4988115edbdbda46ec2c..a883c9876345c93577bf7033cd9a00c32afcea58 100644 (file)
@@ -412,24 +412,38 @@ static DEVICE_ATTR_RO(io_stat);
 static DEVICE_ATTR_RO(mm_stat);
 static DEVICE_ATTR_RO(debug_stat);
 
+static void zram_slot_lock(struct zram *zram, u32 index)
+{
+       struct zram_meta *meta = zram->meta;
+
+       bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
+}
+
+static void zram_slot_unlock(struct zram *zram, u32 index)
+{
+       struct zram_meta *meta = zram->meta;
+
+       bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+}
+
 static bool zram_same_page_read(struct zram *zram, u32 index,
                                struct page *page,
                                unsigned int offset, unsigned int len)
 {
        struct zram_meta *meta = zram->meta;
 
-       bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_lock(zram, index);
        if (unlikely(!meta->table[index].handle) ||
                        zram_test_flag(meta, index, ZRAM_SAME)) {
                void *mem;
 
-               bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+               zram_slot_unlock(zram, index);
                mem = kmap_atomic(page);
                zram_fill_page(mem + offset, len, meta->table[index].element);
                kunmap_atomic(mem);
                return true;
        }
-       bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_unlock(zram, index);
 
        return false;
 }
@@ -445,11 +459,11 @@ static bool zram_same_page_write(struct zram *zram, u32 index,
 
                kunmap_atomic(mem);
                /* Free memory associated with this sector now. */
-               bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
+               zram_slot_lock(zram, index);
                zram_free_page(zram, index);
                zram_set_flag(meta, index, ZRAM_SAME);
                zram_set_element(meta, index, element);
-               bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+               zram_slot_unlock(zram, index);
 
                atomic64_inc(&zram->stats.same_pages);
                return true;
@@ -556,7 +570,7 @@ static int zram_decompress_page(struct zram *zram, struct page *page, u32 index)
        if (zram_same_page_read(zram, index, page, 0, PAGE_SIZE))
                return 0;
 
-       bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_lock(zram, index);
        handle = meta->table[index].handle;
        size = zram_get_obj_size(meta, index);
 
@@ -575,7 +589,7 @@ static int zram_decompress_page(struct zram *zram, struct page *page, u32 index)
                zcomp_stream_put(zram->comp);
        }
        zs_unmap_object(meta->mem_pool, handle);
-       bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_unlock(zram, index);
 
        /* Should NEVER happen. Return bio error if it does. */
        if (unlikely(ret))
@@ -724,11 +738,11 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index)
         * Free memory associated with this sector
         * before overwriting unused sectors.
         */
-       bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_lock(zram, index);
        zram_free_page(zram, index);
        meta->table[index].handle = handle;
        zram_set_obj_size(meta, index, comp_len);
-       bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_unlock(zram, index);
 
        /* Update stats */
        atomic64_add(comp_len, &zram->stats.compr_data_size);
@@ -786,7 +800,6 @@ static void zram_bio_discard(struct zram *zram, u32 index,
                             int offset, struct bio *bio)
 {
        size_t n = bio->bi_iter.bi_size;
-       struct zram_meta *meta = zram->meta;
 
        /*
         * zram manages data in physical block size units. Because logical block
@@ -807,9 +820,9 @@ static void zram_bio_discard(struct zram *zram, u32 index,
        }
 
        while (n >= PAGE_SIZE) {
-               bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
+               zram_slot_lock(zram, index);
                zram_free_page(zram, index);
-               bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+               zram_slot_unlock(zram, index);
                atomic64_inc(&zram->stats.notify_free);
                index++;
                n -= PAGE_SIZE;
@@ -918,9 +931,9 @@ static void zram_slot_free_notify(struct block_device *bdev,
        zram = bdev->bd_disk->private_data;
        meta = zram->meta;
 
-       bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_lock(zram, index);
        zram_free_page(zram, index);
-       bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+       zram_slot_unlock(zram, index);
        atomic64_inc(&zram->stats.notify_free);
 }