From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: <linux-kernel@vger.kernel.org>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
<kernel-team@lge.com>, Minchan Kim <minchan@kernel.org>
Subject: [PATCH 5/5] zram: introduce zram data accessor
Date: Mon, 3 Apr 2017 14:17:33 +0900 [thread overview]
Message-ID: <1491196653-7388-6-git-send-email-minchan@kernel.org> (raw)
In-Reply-To: <1491196653-7388-1-git-send-email-minchan@kernel.org>
With element, sometime I got confused handle and element access.
It might be my bad but I think it's time to introduce accessor
to prevent future idiot like me.
This patch is just clean-up patch so it shouldn't change any
behavior.
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
drivers/block/zram/zram_drv.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index fdb73222841d..c3171e5aa582 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -57,6 +57,16 @@ static inline struct zram *dev_to_zram(struct device *dev)
return (struct zram *)dev_to_disk(dev)->private_data;
}
+static unsigned long zram_get_handle(struct zram *zram, u32 index)
+{
+ return zram->table[index].handle;
+}
+
+static void zram_set_handle(struct zram *zram, u32 index, unsigned long handle)
+{
+ zram->table[index].handle = handle;
+}
+
/* flag operations require table entry bit_spin_lock() being held */
static int zram_test_flag(struct zram *zram, u32 index,
enum zram_pageflags flag)
@@ -82,9 +92,9 @@ static inline void zram_set_element(struct zram *zram, u32 index,
zram->table[index].element = element;
}
-static inline void zram_clear_element(struct zram *zram, u32 index)
+static unsigned long zram_get_element(struct zram *zram, u32 index)
{
- zram->table[index].element = 0;
+ return zram->table[index].element;
}
static size_t zram_get_obj_size(struct zram *zram, u32 index)
@@ -428,13 +438,14 @@ static bool zram_special_page_read(struct zram *zram, u32 index,
unsigned int offset, unsigned int len)
{
zram_slot_lock(zram, index);
- if (unlikely(!zram->table[index].handle) ||
- zram_test_flag(zram, index, ZRAM_SAME)) {
+ if (unlikely(!zram_get_handle(zram, index) ||
+ zram_test_flag(zram, index, ZRAM_SAME))) {
void *mem;
zram_slot_unlock(zram, index);
mem = kmap_atomic(page);
- zram_fill_page(mem + offset, len, zram->table[index].element);
+ zram_fill_page(mem + offset, len,
+ zram_get_element(zram, index));
kunmap_atomic(mem);
return true;
}
@@ -473,7 +484,7 @@ static void zram_meta_free(struct zram *zram, u64 disksize)
/* Free all pages that are still in this zram device */
for (index = 0; index < num_pages; index++) {
- unsigned long handle = zram->table[index].handle;
+ unsigned long handle = zram_get_handle(zram, index);
/*
* No memory is allocated for same element filled pages.
* Simply clear same page flag.
@@ -513,7 +524,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
*/
static void zram_free_page(struct zram *zram, size_t index)
{
- unsigned long handle = zram->table[index].handle;
+ unsigned long handle = zram_get_handle(zram, index);
/*
* No memory is allocated for same element filled pages.
@@ -521,7 +532,7 @@ static void zram_free_page(struct zram *zram, size_t index)
*/
if (zram_test_flag(zram, index, ZRAM_SAME)) {
zram_clear_flag(zram, index, ZRAM_SAME);
- zram_clear_element(zram, index);
+ zram_set_element(zram, index, 0);
atomic64_dec(&zram->stats.same_pages);
return;
}
@@ -535,7 +546,7 @@ static void zram_free_page(struct zram *zram, size_t index)
&zram->stats.compr_data_size);
atomic64_dec(&zram->stats.pages_stored);
- zram->table[index].handle = 0;
+ zram_set_handle(zram, index, 0);
zram_set_obj_size(zram, index, 0);
}
@@ -550,7 +561,7 @@ static int zram_decompress_page(struct zram *zram, struct page *page, u32 index)
return 0;
zram_slot_lock(zram, index);
- handle = zram->table[index].handle;
+ handle = zram_get_handle(zram, index);
size = zram_get_obj_size(zram, index);
src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
@@ -721,7 +732,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
*/
zram_slot_lock(zram, index);
zram_free_page(zram, index);
- zram->table[index].handle = handle;
+ zram_set_handle(zram, index, handle);
zram_set_obj_size(zram, index, comp_len);
zram_slot_unlock(zram, index);
--
2.7.4
next prev parent reply other threads:[~2017-04-03 5:18 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-03 5:17 [PATCH 0/5] zram clean up Minchan Kim
2017-04-03 5:17 ` [PATCH 1/5] zram: handle multiple pages attached bio's bvec Minchan Kim
2017-04-03 22:45 ` Andrew Morton
2017-04-03 23:13 ` Minchan Kim
2017-04-04 4:55 ` Sergey Senozhatsky
2017-04-03 5:17 ` [PATCH 2/5] zram: partial IO refactoring Minchan Kim
2017-04-03 5:52 ` Mika Penttilä
2017-04-03 6:12 ` Minchan Kim
2017-04-03 6:57 ` Mika Penttilä
2017-04-04 2:17 ` Sergey Senozhatsky
2017-04-04 4:50 ` Minchan Kim
2017-04-03 5:17 ` [PATCH 3/5] zram: use zram_slot_lock instead of raw bit_spin_lock op Minchan Kim
2017-04-03 6:08 ` Sergey Senozhatsky
2017-04-03 6:34 ` Minchan Kim
2017-04-03 8:06 ` Sergey Senozhatsky
2017-04-04 2:18 ` Sergey Senozhatsky
2017-04-04 4:50 ` Minchan Kim
2017-04-03 5:17 ` [PATCH 4/5] zram: remove zram_meta structure Minchan Kim
2017-04-04 2:31 ` Sergey Senozhatsky
2017-04-04 4:52 ` Minchan Kim
2017-04-04 5:40 ` Minchan Kim
2017-04-04 5:54 ` Sergey Senozhatsky
2017-04-03 5:17 ` Minchan Kim [this message]
2017-04-04 4:40 ` [PATCH 5/5] zram: introduce zram data accessor Sergey Senozhatsky
2017-04-11 5:38 ` [PATCH 0/5] zram clean up Minchan Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1491196653-7388-6-git-send-email-minchan@kernel.org \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=kernel-team@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome