Similarly to write, move ZRAM_HUGE read handlig to a separate
function. This will make more sense with introduction of
multi-handle entries later in the series.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
drivers/block/zram/zram_drv.c | 71 ++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 27 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 9101fd0c670f..2b20afcfbb94 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1525,6 +1525,46 @@ static void zram_free_page(struct zram *zram, size_t index)
zram_set_obj_size(zram, index, 0);
}
+static int read_incompressible_page(struct zram *zram, struct page *page,
+ u32 index)
+{
+ unsigned long handle;
+ void *src, *dst;
+
+ handle = zram_get_handle(zram, index);
+ src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
+ dst = kmap_local_page(page);
+ copy_page(dst, src);
+ kunmap_local(dst);
+ zs_unmap_object(zram->mem_pool, handle);
+
+ return 0;
+}
+
+static int read_compressible_page(struct zram *zram, struct page *page,
+ u32 index)
+{
+ struct zcomp_strm *zstrm;
+ unsigned long handle;
+ unsigned int size;
+ void *src, *dst;
+ int ret, prio;
+
+ handle = zram_get_handle(zram, index);
+ size = zram_get_obj_size(zram, index);
+ prio = zram_get_priority(zram, index);
+
+ zstrm = zcomp_stream_get(zram->comps[prio]);
+ src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
+ dst = kmap_local_page(page);
+ ret = zcomp_decompress(zram->comps[prio], zstrm, src, size, dst);
+ kunmap_local(dst);
+ zs_unmap_object(zram->mem_pool, handle);
+ zcomp_stream_put(zram->comps[prio]);
+
+ return ret;
+}
+
/*
* Reads (decompresses if needed) a page from zspool (zsmalloc).
* Corresponding ZRAM slot should be locked.
@@ -1532,12 +1572,7 @@ static void zram_free_page(struct zram *zram, size_t index)
static int zram_read_from_zspool(struct zram *zram, struct page *page,
u32 index)
{
- struct zcomp_strm *zstrm;
unsigned long handle;
- unsigned int size;
- void *src, *dst;
- u32 prio;
- int ret;
handle = zram_get_handle(zram, index);
if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) {
@@ -1549,28 +1584,10 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page,
return 0;
}
- size = zram_get_obj_size(zram, index);
-
- if (size != PAGE_SIZE) {
- prio = zram_get_priority(zram, index);
- zstrm = zcomp_stream_get(zram->comps[prio]);
- }
-
- src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
- if (size == PAGE_SIZE) {
- dst = kmap_local_page(page);
- copy_page(dst, src);
- kunmap_local(dst);
- ret = 0;
- } else {
- dst = kmap_local_page(page);
- ret = zcomp_decompress(zram->comps[prio], zstrm,
- src, size, dst);
- kunmap_local(dst);
- zcomp_stream_put(zram->comps[prio]);
- }
- zs_unmap_object(zram->mem_pool, handle);
- return ret;
+ if (!zram_test_flag(zram, index, ZRAM_HUGE))
+ return read_compressible_page(zram, page, index);
+ else
+ return read_incompressible_page(zram, page, index);
}
static int zram_read_page(struct zram *zram, struct page *page, u32 index,
--
2.47.0.371.ga323438b13-goog