Received: by 10.223.164.221 with SMTP id h29csp2770712wrb; Wed, 18 Oct 2017 06:42:47 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDmZRCokGmfqf6fu6tNe0Mtb2cN/4HulF0uj2ywddShrYfkhryoU46PQ/Pa5HVpjbTTUE6C X-Received: by 10.99.8.5 with SMTP id 5mr13903920pgi.28.1508334167251; Wed, 18 Oct 2017 06:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508334167; cv=none; d=google.com; s=arc-20160816; b=TVCIJ3Zb6DqvlsOMo7HMnH3+M8lKvQIxOcRHFFORB9CcEoOBnwPiDBjkbDlKGtU7Uc mXZ53wcSe0Rq/DtV5GO0uNJHwzfGOyKVClN7gtI5wln9yPaiWLHDgdDJuqTwPp2iGhsu 3FS5U/FoxiSMk1Fo9TE84bSmoZrYZWfRWuR2qhG7fPjlBdRbAyqMjlFEdqsaH71KkU7J BThTbhtBRYS4cnTXYAsM1V78s8eSnR3fxGVfZj+apBd5uI8T0zGEnLm+Q0UYUWLwZwOO KDmkHWHgHde/NVmGHU0tyepyMtLHO26Ax0Q5nulrcKbLNgHGvguI3TIYxl3QPS2CXLq3 DEOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type :content-transfer-encoding:date:message-id:illegal-object:cc:to:from :reply-to:subject:mime-version:arc-authentication-results; bh=8CBs0UDwZI/4Bu8fdhe6AIWuZN2W9M9/NPuoxOMMK1E=; b=dNIzwXfe2lZM0us4e5FRyNlwAjVRWZUW/35bos2roAChbmDPfL/aNa+Gt67fOHjQ4+ AInujNs5djo52noyG+Hhv++//ndCQxJUcp9sDmAvKz/ojgg51HnrmJUcbHXPmSL+W0GF g2txbNTo6GvWTJmsmil4YcVyeSNloRyaPX7HAjcOIkgyxmt9UdJGT1X5Pmu1a4ypVRZ8 swRwoXHwPQU2olbwUuOn3NyK5SyZ2v2oCnY1fdcug/3gxaS+N3xvGabLr9aQ4qUJMmQD RAHSdhe8OxO5+54KtwXtCW1QFrCXz8P3KmXBV9MQ9onHLl8Qzwkx6OLjrzj43JGojv4k nOgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x66si7499172pfa.129.2017.10.18.06.42.32; Wed, 18 Oct 2017 06:42:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938001AbdJRKsi (ORCPT + 99 others); Wed, 18 Oct 2017 06:48:38 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:41342 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932961AbdJRKsg (ORCPT ); Wed, 18 Oct 2017 06:48:36 -0400 Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20171018104834epoutp0222d176b5f50cbf15ca0c69aeafd09fb6~upG1cL81p1893518935epoutp025 for ; Wed, 18 Oct 2017 10:48:34 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20171018104833epcas5p4001b9bda02e1f79e0d1e293e46b13c93~upG0SPAYw1089010890epcas5p4M; Wed, 18 Oct 2017 10:48:33 +0000 (GMT) X-AuditID: b6c32a4b-56dff70000001095-04-59e731810cb0 Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 0F.14.04245.18137E95; Wed, 18 Oct 2017 19:48:33 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH] zswap: Same-filled pages handling Reply-To: srividya.dr@samsung.com From: Srividya Desireddy To: "sjenning@redhat.com" , "ddstreet@ieee.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "penberg@kernel.org" CC: Dinakar Reddy Pathireddy , SHARAN ALLUR , RAJIB BASU , JUHUN KIM , "srividya.desireddy@gmail.com" X-Priority: 3 X-Content-Kind-Code: NORMAL X-Drm-Type: N,general X-EPLocale: en_US.EUC-KR X-EPWebmail-Msg-Type: personal X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Illegal-Object: Syntax error in X-Sender: address found on vger.kernel.org: X-Sender: =?utf-8?B?U2Ftc3VuZyBFbGVjdHJvbmljcxtTUkktQmFuZ2Fs?= ^-Extraneous program text X-Sender-IP: 107.108.50.76 X-Local-Sender: =?UTF-8?B?U3JpdmlkeWEgRGVzaXJlZGR5G1NSSS1CYW5nYWxvcmUtQVAgU3lzdGVt?= =?UTF-8?B?cyAxG++/ve+/veyHse+/veq5hu+/ve+/ve+/ve+/ve+/vRtU?= =?UTF-8?B?ZWNobmljYWwgTGVhZA==?= X-Global-Sender: =?UTF-8?B?U3JpdmlkeWEgRGVzaXJlZGR5G1NSSS1CYW5nYWxvcmUtQVAgU3lzdGVt?= =?UTF-8?B?cyAxG1NhbXN1bmcgRWxlY3Ryb25pY3MbVGVjaG5pY2FsIExl?= =?UTF-8?B?YWQ=?= X-Sender-Code: =?UTF-8?B?QzEwGxtDMTBJRDAxSUQwMTA4OTQ=?= Message-ID: <20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0@epcms5p1> Date: Wed, 18 Oct 2017 10:48:32 +0000 X-CMS-MailID: 20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-CPGSPASS: Y X-CPGSPASS: Y X-MTR: 20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0 CMS-TYPE: 105P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJKsWRmVeSWpSXmKPExsWy7bCmlm6j4fNIgwf/FS1eHtK0uNC2m8Vi d8cJRovT306zWlzeNYfN4t6a/6wWbZ//sVrM+jmJzWLJsrXMFrsuPmGzODezmdGB22PnrLvs Hk8nHGTy2LSqk81j06dJ7B7v911l8+jbsorR4/MmuQD2KC6blNSczLLUIn27BK6M7zs3sBU0 OFQcuLqMuYFxsXEXIyeHhICJxJfPk1i7GLk4hAR2M0osWHuUuYuRg4NXQFDi7w5hkBphASOJ K/MusoDYQgKKEs3dGxgh4iYSm/4tYAIpZwOqOXw+B2SMiMBnRonzq/+ygDjMAi8ZJbo2b2OF WMYrMaP9KQuELS2xfflWRghbVOLm6rfsELaExOqFz9kgbDmJaV/XMMPUvD82H6peRKL13lmo uKDEg5+7oeKVEh2fF0PtkpK4++0A2BESAtsYJSZNXskEkVjOKHHvDlSRucTblweZIB72lfj6 hA8kzCKgKrF770Ko+S4SD2fcBJvPLCAvsf3tHHD4MAtoSqzfpQ/zVsPG3+yYbFuJD19XMkO0 8kn0/n7CBFOzY94TpgmMKrMQIT0LyYJZCAsWMDKvYpRMLSjOTU8tNi0wzkst1ytOzC0uzUvX S87P3cQITlBa3jsYN53zOcQowMGoxMMboPIsUog1say4MvcQowQHs5IIL/NHoBBvSmJlVWpR fnxRaU5q8SFGaQ4WJXHeYztLI4UE0hNLUrNTUwtSi2CyTBycUg2MqTcvaP7R8+cylC75eOrd 3i7HdbHz8m9XnIo50rM543Gx8Islb76bMm7/lbh4097H+WVTg1xeta+YHp0YInenpjhP4WCO 1ZSOxw1H3Ro3Trt+OvPEDOZ/4VzfO553T3H5vn3r23CLcOFbs62+ly93LVjb3Kv6z4E7sYN9 r6KemPIfg+0O1XqcSizFGYmGWsxFxYkANZ1kj0wDAAA= X-CMS-RootMailID: 20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0 X-RootMTR: 20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0 References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srividya Desireddy Date: Wed, 18 Oct 2017 15:39:02 +0530 Subject: [PATCH] zswap: Same-filled pages handling Zswap is a cache which compresses the pages that are being swapped out and stores them into a dynamically allocated RAM-based memory pool. Experiments have shown that around 10-20% of pages stored in zswap are same-filled pages (i.e. contents of the page are all same), but these pages are handled as normal pages by compressing and allocating memory in the pool. This patch adds a check in zswap_frontswap_store() to identify same-filled page before compression of the page. If the page is a same-filled page, set zswap_entry.length to zero, save the same-filled value and skip the compression of the page and alloction of memory in zpool. In zswap_frontswap_load(), check if value of zswap_entry.length is zero corresponding to the page to be loaded. If zswap_entry.length is zero, fill the page with same-filled value. This saves the decompression time during load. On a ARM Quad Core 32-bit device with 1.5GB RAM by launching and relaunching different applications, out of ~64000 pages stored in zswap, ~11000 pages were same-value filled pages (including zero-filled pages) and ~9000 pages were zero-filled pages. An average of 17% of pages(including zero-filled pages) in zswap are same-value filled pages and 14% pages are zero-filled pages. An average of 3% of pages are same-filled non-zero pages. The below table shows the execution time profiling with the patch. Baseline With patch % Improvement ----------------------------------------------------------------- *Zswap Store Time 26.5ms 18ms 32% (of same value pages) *Zswap Load Time (of same value pages) 25.5ms 13ms 49% ----------------------------------------------------------------- On Ubuntu PC with 2GB RAM, while executing kernel build and other test scripts and running multimedia applications, out of 360000 pages stored in zswap 78000(~22%) of pages were found to be same-value filled pages (including zero-filled pages) and 64000(~17%) are zero-filled pages. So an average of %5 of pages are same-filled non-zero pages. The below table shows the execution time profiling with the patch. Baseline With patch % Improvement ----------------------------------------------------------------- *Zswap Store Time 91ms 74ms 19% (of same value pages) *Zswap Load Time 50ms 7.5ms 85% (of same value pages) ----------------------------------------------------------------- *The execution times may vary with test device used. Signed-off-by: Srividya Desireddy --- mm/zswap.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index d39581a..4dd8b89 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -49,6 +49,8 @@ static u64 zswap_pool_total_size; /* The number of compressed pages currently stored in zswap */ static atomic_t zswap_stored_pages = ATOMIC_INIT(0); +/* The number of same-value filled pages currently stored in zswap */ +static atomic_t zswap_same_filled_pages = ATOMIC_INIT(0); /* * The statistics below are not protected from concurrent access for @@ -116,6 +118,11 @@ static int zswap_compressor_param_set(const char *, static unsigned int zswap_max_pool_percent = 20; module_param_named(max_pool_percent, zswap_max_pool_percent, uint, 0644); +/* Enable/disable handling same-value filled pages (enabled by default) */ +static bool zswap_same_filled_pages_enabled = true; +module_param_named(same_filled_pages_enabled, zswap_same_filled_pages_enabled, + bool, 0644); + /********************************* * data structures **********************************/ @@ -145,9 +152,10 @@ struct zswap_pool { * be held while changing the refcount. Since the lock must * be held, there is no reason to also make refcount atomic. * length - the length in bytes of the compressed page data. Needed during - * decompression + * decompression. For a same value filled page length is 0. * pool - the zswap_pool the entry's data is in * handle - zpool allocation handle that stores the compressed page data + * value - value of the same-value filled pages which have same content */ struct zswap_entry { struct rb_node rbnode; @@ -155,7 +163,10 @@ struct zswap_entry { int refcount; unsigned int length; struct zswap_pool *pool; - unsigned long handle; + union { + unsigned long handle; + unsigned long value; + }; }; struct zswap_header { @@ -320,8 +331,12 @@ static void zswap_rb_erase(struct rb_root *root, struct zswap_entry *entry) */ static void zswap_free_entry(struct zswap_entry *entry) { - zpool_free(entry->pool->zpool, entry->handle); - zswap_pool_put(entry->pool); + if (!entry->length) + atomic_dec(&zswap_same_filled_pages); + else { + zpool_free(entry->pool->zpool, entry->handle); + zswap_pool_put(entry->pool); + } zswap_entry_cache_free(entry); atomic_dec(&zswap_stored_pages); zswap_update_total_size(); @@ -953,6 +968,34 @@ static int zswap_shrink(void) return ret; } +static int zswap_is_page_same_filled(void *ptr, unsigned long *value) +{ + unsigned int pos; + unsigned long *page; + + page = (unsigned long *)ptr; + for (pos = 1; pos < PAGE_SIZE / sizeof(*page); pos++) { + if (page[pos] != page[0]) + return 0; + } + *value = page[0]; + return 1; +} + +static void zswap_fill_page(void *ptr, unsigned long value) +{ + unsigned int pos; + unsigned long *page; + + page = (unsigned long *)ptr; + if (value == 0) + memset(page, 0, PAGE_SIZE); + else { + for (pos = 0; pos < PAGE_SIZE / sizeof(*page); pos++) + page[pos] = value; + } +} + /********************************* * frontswap hooks **********************************/ @@ -965,7 +1008,7 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, struct crypto_comp *tfm; int ret; unsigned int dlen = PAGE_SIZE, len; - unsigned long handle; + unsigned long handle, value; char *buf; u8 *src, *dst; struct zswap_header *zhdr; @@ -993,6 +1036,19 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, goto reject; } + if (zswap_same_filled_pages_enabled) { + src = kmap_atomic(page); + if (zswap_is_page_same_filled(src, &value)) { + kunmap_atomic(src); + entry->offset = offset; + entry->length = 0; + entry->value = value; + atomic_inc(&zswap_same_filled_pages); + goto insert_entry; + } + kunmap_atomic(src); + } + /* if entry is successfully added, it keeps the reference */ entry->pool = zswap_pool_current_get(); if (!entry->pool) { @@ -1037,6 +1093,7 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset, entry->handle = handle; entry->length = dlen; +insert_entry: /* map */ spin_lock(&tree->lock); do { @@ -1089,6 +1146,13 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, } spin_unlock(&tree->lock); + if (!entry->length) { + dst = kmap_atomic(page); + zswap_fill_page(dst, entry->value); + kunmap_atomic(dst); + goto freeentry; + } + /* decompress */ dlen = PAGE_SIZE; src = (u8 *)zpool_map_handle(entry->pool->zpool, entry->handle, @@ -1101,6 +1165,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset, zpool_unmap_handle(entry->pool->zpool, entry->handle); BUG_ON(ret); +freeentry: spin_lock(&tree->lock); zswap_entry_put(tree, entry); spin_unlock(&tree->lock); @@ -1209,6 +1274,8 @@ static int __init zswap_debugfs_init(void) zswap_debugfs_root, &zswap_pool_total_size); debugfs_create_atomic_t("stored_pages", S_IRUGO, zswap_debugfs_root, &zswap_stored_pages); + debugfs_create_atomic_t("same_filled_pages", 0444, + zswap_debugfs_root, &zswap_same_filled_pages); return 0; } -- 1.9.1 From 1585309411083717610@xxx Tue Nov 28 11:34:28 +0000 2017 X-GM-THRID: 1585309411083717610 X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread