From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752453AbdFLFFI (ORCPT ); Mon, 12 Jun 2017 01:05:08 -0400 Received: from LGEAMRELO13.lge.com ([156.147.23.53]:57606 "EHLO lgeamrelo13.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752018AbdFLFDI (ORCPT ); Mon, 12 Jun 2017 01:03:08 -0400 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 10.177.220.163 X-Original-MAILFROM: minchan@kernel.org From: Minchan Kim To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Juneho Choi , Sergey Senozhatsky , kernel-team , Minchan Kim Subject: [RFC 1/7] zram: inlining zram_compress Date: Mon, 12 Jun 2017 14:02:45 +0900 Message-Id: <1497243771-27611-2-git-send-email-minchan@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497243771-27611-1-git-send-email-minchan@kernel.org> References: <1497243771-27611-1-git-send-email-minchan@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org zram_compress does several things, compress, entry alloc and check limitation. I did for just readbility but it hurts modulization.:( So this patch removes zram_compress functions and inline it in __zram_bvec_write for upcoming patches. Signed-off-by: Minchan Kim --- drivers/block/zram/zram_drv.c | 81 +++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 5440d1a..bed534e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -692,22 +692,45 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, return ret; } -static int zram_compress(struct zram *zram, struct zcomp_strm **zstrm, - struct page *page, struct zram_entry **out_entry, - unsigned int *out_comp_len) +static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index) { int ret; - unsigned int comp_len; - void *src; + struct zram_entry *uninitialized_var(entry); + unsigned int uninitialized_var(comp_len); + void *src, *dst, *mem; + struct zcomp_strm *zstrm; + struct page *page = bvec->bv_page; + u32 checksum; + enum zram_pageflags flags = 0; + unsigned long uninitialized_var(element); unsigned long alloced_pages; - struct zram_entry *entry = NULL; + + mem = kmap_atomic(page); + if (page_same_filled(mem, &element)) { + kunmap_atomic(mem); + /* Free memory associated with this sector now. */ + flags = ZRAM_SAME; + atomic64_inc(&zram->stats.same_pages); + goto out; + } + kunmap_atomic(mem); + + entry = zram_dedup_find(zram, page, &checksum); + if (entry) { + comp_len = entry->len; + flags = ZRAM_DUP; + atomic64_add(comp_len, &zram->stats.dup_data_size); + goto out; + } compress_again: + zstrm = zcomp_stream_get(zram->comp); src = kmap_atomic(page); - ret = zcomp_compress(*zstrm, src, &comp_len); + ret = zcomp_compress(zstrm, src, &comp_len); kunmap_atomic(src); if (unlikely(ret)) { + zcomp_stream_put(zram->comp); pr_err("Compression failed! err=%d\n", ret); if (entry) zram_entry_free(zram, entry); @@ -742,7 +765,6 @@ static int zram_compress(struct zram *zram, struct zcomp_strm **zstrm, entry = zram_entry_alloc(zram, comp_len, GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE); - *zstrm = zcomp_stream_get(zram->comp); if (entry) goto compress_again; return -ENOMEM; @@ -752,52 +774,11 @@ static int zram_compress(struct zram *zram, struct zcomp_strm **zstrm, update_used_max(zram, alloced_pages); if (zram->limit_pages && alloced_pages > zram->limit_pages) { + zcomp_stream_put(zram->comp); zram_entry_free(zram, entry); return -ENOMEM; } - *out_entry = entry; - *out_comp_len = comp_len; - return 0; -} - -static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index) -{ - int ret; - struct zram_entry *uninitialized_var(entry); - unsigned int uninitialized_var(comp_len); - void *src, *dst, *mem; - struct zcomp_strm *zstrm; - struct page *page = bvec->bv_page; - u32 checksum; - enum zram_pageflags flags = 0; - unsigned long uninitialized_var(element); - - mem = kmap_atomic(page); - if (page_same_filled(mem, &element)) { - kunmap_atomic(mem); - /* Free memory associated with this sector now. */ - flags = ZRAM_SAME; - atomic64_inc(&zram->stats.same_pages); - goto out; - } - kunmap_atomic(mem); - - entry = zram_dedup_find(zram, page, &checksum); - if (entry) { - comp_len = entry->len; - flags = ZRAM_DUP; - atomic64_add(comp_len, &zram->stats.dup_data_size); - goto out; - } - - zstrm = zcomp_stream_get(zram->comp); - ret = zram_compress(zram, &zstrm, page, &entry, &comp_len); - if (ret) { - zcomp_stream_put(zram->comp); - return ret; - } - dst = zs_map_object(zram->mem_pool, zram_entry_handle(zram, entry), ZS_MM_WO); -- 2.7.4