From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932449AbdLVKew (ORCPT ); Fri, 22 Dec 2017 05:34:52 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:49326 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757667AbdLVKeq (ORCPT ); Fri, 22 Dec 2017 05:34:46 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20171222103444epoutp04196c94d27d28fa8cea1ad3268b65879b~Cl2T9Ys0E1030110301epoutp04h X-AuditID: b6c32a4b-cf7ff700000011c1-e7-5a3cdfc38992 From: Gopi Sai Teja To: minchan@kernel.org, ngupta@vflare.org, sergey.senozhatsky.work@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, v.narang@samsung.com, pankaj.m@samsung.com, a.sahrawat@samsung.com, prakash.a@samsung.com, himanshu.sh@samsung.com, lalit.mohan@samsung.com, Gopi Sai Teja Subject: [PATCH v2] zram: better utilization of zram swap space Date: Fri, 22 Dec 2017 16:00:06 +0530 Message-Id: <1513938606-17735-1-git-send-email-gopi.st@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42LZdlhTU/fwfZsog603tCwu7k61eNS2hdVi 75MWVov+xWYWl3fNYbO4t+Y/q8Wyr+/ZLTa0zGK3uPdmK5PF9RdvGS0eTZjEZHHo5FxGBx6P nbPusntsWtXJ5rHp0yR2j74tqxg9dn7azOrxeZNcAFsUl01Kak5mWWqRvl0CV8acnj1sBStl K97v/sfSwHhdrIuRk0NCwETi2+P1bF2MXBxCArsZJf6vf8gK4XxilJjasxXK+cYocebQU3aY lv27jjNBJPaCJJ4xQzhfGCXmf9/CBFLFJqAp8fzeB7AOEQEfiddnrrGDFDELvGGUuH/zPBtI QljAXuLHiUdANgcHi4CqxIWZKSAmr4CzxPz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KCHelMTKqtSi /Pii0pzU4kOM0hwsSuK88vnHIoUE0hNLUrNTUwtSi2CyTBycUg2ME29Pkrafz8p/9aC27qnN l6dPeXA6Xe7S1IWH/J43FRzt+rxib5CX3n/mFyrXo3fz/O9IXnWb82ssl0Hane9hljm/8pYf n8Zy9UVUjWaD337+YJbFOsY59wOauJ/dLv1+8s4soTUT7Op5EhXsq75nmB8uChO+Os97Xk30 Ed7VZ7SNfA78ZLzcr8RSnJFoqMVcVJwIAAX692I6AgAA X-CMS-MailID: 20171222103443epcas5p41f45e1a99146aac89edd63f76a3eb62a X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-MTR: 20171222103443epcas5p41f45e1a99146aac89edd63f76a3eb62a CMS-TYPE: 105P X-CMS-RootMailID: 20171222103443epcas5p41f45e1a99146aac89edd63f76a3eb62a X-RootMTR: 20171222103443epcas5p41f45e1a99146aac89edd63f76a3eb62a References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 75% of the PAGE_SIZE is not a correct threshold to store uncompressed pages in zs_page as this must be changed if the maximum pages stored in zspage changes. Instead using zs classes, we can set the correct threshold irrespective of the maximum pages stored in zspage. Tested on ARM: Before Patch: class size obj_allocated obj_used pages_used .... 190 3072 6744 6724 5058 202 3264 90 87 72 254 4096 11886 11886 11886 Total 123251 120511 55076 After Patch: class size obj_allocated obj_used pages_used ... 190 3072 6368 6326 4776 202 3264 2205 2197 1764 254 4096 12624 12624 12624 Total 125655 122045 56541 Signed-off-by: Gopi Sai Teja --- v1 -> v2: Earlier, threshold to store uncompressed page is set to 80% of PAGE_SIZE and now zsmalloc classes is used to set the threshold. drivers/block/zram/zram_drv.c | 2 +- include/linux/zsmalloc.h | 1 + mm/zsmalloc.c | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index d70eba3..dda0ef8 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -965,7 +965,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, return ret; } - if (unlikely(comp_len > max_zpage_size)) { + if (unlikely(comp_len > zs_max_zpage_size(zram->mem_pool))) { if (zram_wb_enabled(zram) && allow_wb) { zcomp_stream_put(zram->comp); ret = write_to_bdev(zram, bvec, index, bio, &element); diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 57a8e98..0b09aa5 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -54,5 +54,6 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, unsigned long zs_get_total_pages(struct zs_pool *pool); unsigned long zs_compact(struct zs_pool *pool); +unsigned int zs_max_zpage_size(struct zs_pool *pool); void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats); #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 685049a..5b434ab 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -261,6 +261,7 @@ struct zs_pool { * and unregister_shrinker() will not Oops. */ bool shrinker_enabled; + unsigned short max_zpage_size; #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; #endif @@ -318,6 +319,11 @@ static void init_deferred_free(struct zs_pool *pool) {} static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {} #endif +unsigned int zs_max_zpage_size(struct zs_pool *pool) +{ + return pool->max_zpage_size; +} + static int create_cache(struct zs_pool *pool) { pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE, @@ -2368,6 +2374,8 @@ struct zs_pool *zs_create_pool(const char *name) if (create_cache(pool)) goto err; + pool->max_zpage_size = 0; + /* * Iterate reversely, because, size of size_class that we want to use * for merging should be larger or equal to current size. @@ -2411,6 +2419,11 @@ struct zs_pool *zs_create_pool(const char *name) class->objs_per_zspage = objs_per_zspage; spin_lock_init(&class->lock); pool->size_class[i] = class; + + if (!pool->max_zpage_size && + pages_per_zspage < objs_per_zspage) + pool->max_zpage_size = class->size - ZS_HANDLE_SIZE; + for (fullness = ZS_EMPTY; fullness < NR_ZS_FULLNESS; fullness++) INIT_LIST_HEAD(&class->fullness_list[fullness]); -- 1.9.1