From mboxrd@z Thu Jan 1 00:00:00 1970 From: Geert Uytterhoeven Subject: Re: [PATCH v4 1/8] staging: zcache: introduce zero-filled pages handler Date: Sat, 23 Mar 2013 20:31:11 +0100 Message-ID: References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> <1363685150-18303-2-git-send-email-liwanp@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: In-Reply-To: <1363685150-18303-2-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org To: Wanpeng Li Cc: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Linux-Next List-Id: linux-next.vger.kernel.org On Tue, Mar 19, 2013 at 10:25 AM, Wanpeng Li wrote: > Introduce zero-filled pages handler to capture and handle zero pages. > > Acked-by: Dan Magenheimer > Signed-off-by: Wanpeng Li > --- > drivers/staging/zcache/zcache-main.c | 26 ++++++++++++++++++++++++++ > 1 files changed, 26 insertions(+), 0 deletions(-) > > diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c > index 328898e..d73dd4b 100644 > --- a/drivers/staging/zcache/zcache-main.c > +++ b/drivers/staging/zcache/zcache-main.c > +static void handle_zero_filled_page(void *page) > +{ > + void *user_mem; > + > + user_mem = kmap_atomic(page); kmap_atomic() takes a "struct page *", not a "void *". > + memset(user_mem, 0, PAGE_SIZE); > + kunmap_atomic(user_mem); > + > + flush_dcache_page(page); While flush_dcache_page() is a no-op on many architectures, it also takes a "struct page *", not a "void *": m68k/allmodconfig: drivers/staging/zcache/zcache-main.c:309:2: error: request for member 'virtual' in something not a structure or union Cfr. http://kisskb.ellerman.id.au/kisskb/buildresult/8433711/ > +} Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx134.postini.com [74.125.245.134]) by kanga.kvack.org (Postfix) with SMTP id 8576A6B0005 for ; Tue, 19 Mar 2013 05:26:11 -0400 (EDT) Received: from /spool/local by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 14:52:55 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 40CA5125805C for ; Tue, 19 Mar 2013 14:57:11 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9PvXn7471476 for ; Tue, 19 Mar 2013 14:55:58 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9Q10i002704 for ; Tue, 19 Mar 2013 20:26:02 +1100 From: Wanpeng Li Subject: [PATCH v4 2/8] staging: zcache: zero-filled pages awareness Date: Tue, 19 Mar 2013 17:25:44 +0800 Message-Id: <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Compression of zero-filled pages can unneccessarily cause internal fragmentation, and thus waste memory. This special case can be optimized. This patch captures zero-filled pages, and marks their corresponding zcache backing page entry as zero-filled. Whenever such zero-filled page is retrieved, we fill the page frame with zero. Acked-by: Dan Magenheimer Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Wanpeng Li --- drivers/staging/zcache/zcache-main.c | 80 ++++++++++++++++++++++++++++----- 1 files changed, 68 insertions(+), 12 deletions(-) diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 86ead8d..050a99f 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -61,6 +61,12 @@ static inline void frontswap_tmem_exclusive_gets(bool b) } #endif +/* + * mark pampd to special value in order that later + * retrieve will identify zero-filled pages + */ +#define ZERO_FILLED 0x2 + /* enable (or fix code) when Seth's patches are accepted upstream */ #define zcache_writeback_enabled 0 @@ -277,17 +283,23 @@ static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) kmem_cache_free(zcache_obj_cache, obj); } -static bool page_is_zero_filled(void *ptr) +/* + * Compressing zero-filled pages will waste memory and introduce + * serious fragmentation, skip it to avoid overhead. + */ +static bool page_is_zero_filled(struct page *p) { unsigned int pos; - unsigned long *page; - - page = (unsigned long *)ptr; + char *page; + page = kmap_atomic(p); for (pos = 0; pos < PAGE_SIZE / sizeof(*page); pos++) { - if (page[pos]) + if (page[pos]) { + kunmap_atomic(page); return false; + } } + kunmap_atomic(page); return true; } @@ -355,8 +367,15 @@ static void *zcache_pampd_eph_create(char *data, size_t size, bool raw, { void *pampd = NULL, *cdata = data; unsigned clen = size; + bool zero_filled = false; struct page *page = (struct page *)(data), *newpage; + if (page_is_zero_filled(page)) { + clen = 0; + zero_filled = true; + goto got_pampd; + } + if (!raw) { zcache_compress(page, &cdata, &clen); if (clen > zbud_max_buddy_size()) { @@ -396,6 +415,8 @@ got_pampd: inc_zcache_eph_zpages(); if (ramster_enabled && raw) ramster_count_foreign_pages(true, 1); + if (zero_filled) + pampd = (void *)ZERO_FILLED; out: return pampd; } @@ -405,6 +426,7 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, { void *pampd = NULL, *cdata = data; unsigned clen = size; + bool zero_filled = false; struct page *page = (struct page *)(data), *newpage; unsigned long zbud_mean_zsize; unsigned long curr_pers_zpages, total_zsize; @@ -413,6 +435,13 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, BUG_ON(!ramster_enabled); goto create_pampd; } + + if (page_is_zero_filled(page)) { + clen = 0; + zero_filled = true; + goto got_pampd; + } + curr_pers_zpages = zcache_pers_zpages; /* FIXME CONFIG_RAMSTER... subtract atomic remote_pers_pages here? */ if (!raw) @@ -470,6 +499,8 @@ got_pampd: inc_zcache_pers_zbytes(clen); if (ramster_enabled && raw) ramster_count_foreign_pages(false, 1); + if (zero_filled) + pampd = (void *)ZERO_FILLED; out: return pampd; } @@ -531,7 +562,8 @@ out: */ void zcache_pampd_create_finish(void *pampd, bool eph) { - zbud_create_finish((struct zbudref *)pampd, eph); + if (pampd != (void *)ZERO_FILLED) + zbud_create_finish((struct zbudref *)pampd, eph); } /* @@ -576,6 +608,14 @@ static int zcache_pampd_get_data(char *data, size_t *sizep, bool raw, BUG_ON(preemptible()); BUG_ON(eph); /* fix later if shared pools get implemented */ BUG_ON(pampd_is_remote(pampd)); + + if (pampd == (void *)ZERO_FILLED) { + handle_zero_filled_page(data); + if (!raw) + *sizep = PAGE_SIZE; + return 0; + } + if (raw) ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, sizep, eph); @@ -596,13 +636,22 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, void *pampd, struct tmem_pool *pool, struct tmem_oid *oid, uint32_t index) { - int ret; - bool eph = !is_persistent(pool); + int ret = 0; + bool eph = !is_persistent(pool), zero_filled = false; struct page *page = NULL; unsigned int zsize, zpages; BUG_ON(preemptible()); BUG_ON(pampd_is_remote(pampd)); + + if (pampd == (void *)ZERO_FILLED) { + handle_zero_filled_page(data); + zero_filled = true; + if (!raw) + *sizep = PAGE_SIZE; + goto zero_fill; + } + if (raw) ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, sizep, eph); @@ -614,6 +663,7 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, } page = zbud_free_and_delist((struct zbudref *)pampd, eph, &zsize, &zpages); +zero_fill: if (eph) { if (page) dec_zcache_eph_pageframes(); @@ -627,7 +677,7 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, } if (!is_local_client(pool->client)) ramster_count_foreign_pages(eph, -1); - if (page) + if (page && !zero_filled) zcache_free_page(page); return ret; } @@ -641,16 +691,22 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, { struct page *page = NULL; unsigned int zsize, zpages; + bool zero_filled = false; BUG_ON(preemptible()); - if (pampd_is_remote(pampd)) { + + if (pampd == (void *)ZERO_FILLED) + zero_filled = true; + + if (pampd_is_remote(pampd) && !zero_filled) { BUG_ON(!ramster_enabled); pampd = ramster_pampd_free(pampd, pool, oid, index, acct); if (pampd == NULL) return; } if (is_ephemeral(pool)) { - page = zbud_free_and_delist((struct zbudref *)pampd, + if (!zero_filled) + page = zbud_free_and_delist((struct zbudref *)pampd, true, &zsize, &zpages); if (page) dec_zcache_eph_pageframes(); @@ -667,7 +723,7 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, } if (!is_local_client(pool->client)) ramster_count_foreign_pages(is_ephemeral(pool), -1); - if (page) + if (page && !zero_filled) zcache_free_page(page); } -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx206.postini.com [74.125.245.206]) by kanga.kvack.org (Postfix) with SMTP id BE5F66B0027 for ; Tue, 19 Mar 2013 05:26:12 -0400 (EDT) Received: from /spool/local by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 14:51:37 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id B78953940062 for ; Tue, 19 Mar 2013 14:56:07 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9Q2891311080 for ; Tue, 19 Mar 2013 14:56:02 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9Q5Gc005389 for ; Tue, 19 Mar 2013 20:26:05 +1100 From: Wanpeng Li Subject: [PATCH v4 3/8] staging: zcache: handle zcache_[eph|pers]_zpages for zero-filled page Date: Tue, 19 Mar 2013 17:25:45 +0800 Message-Id: <1363685150-18303-4-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Increment/decrement zcache_[eph|pers]_zpages for zero-filled pages, the main point of the counters for zpages and pageframes is to be able to calculate density == zpages/pageframes. A zero-filled page becomes a zpage that "compresses" to zero bytes and, as a result, requires zero pageframes for storage. So the zpages counter should be increased but the pageframes counter should not. [Dan Magenheimer : patch description] Acked-by: Dan Magenheimer Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Wanpeng Li --- drivers/staging/zcache/zcache-main.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 050a99f..892e97e 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -647,6 +647,8 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, if (pampd == (void *)ZERO_FILLED) { handle_zero_filled_page(data); zero_filled = true; + zsize = 0; + zpages = 1; if (!raw) *sizep = PAGE_SIZE; goto zero_fill; @@ -695,8 +697,11 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, BUG_ON(preemptible()); - if (pampd == (void *)ZERO_FILLED) + if (pampd == (void *)ZERO_FILLED) { zero_filled = true; + zsize = 0; + zpages = 1; + } if (pampd_is_remote(pampd) && !zero_filled) { BUG_ON(!ramster_enabled); -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx203.postini.com [74.125.245.203]) by kanga.kvack.org (Postfix) with SMTP id C4BFF6B0037 for ; Tue, 19 Mar 2013 05:26:17 -0400 (EDT) Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 19:18:09 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 76AA62BB0023 for ; Tue, 19 Mar 2013 20:26:09 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9DH8b24576124 for ; Tue, 19 Mar 2013 20:13:17 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9Q8KO024934 for ; Tue, 19 Mar 2013 20:26:08 +1100 From: Wanpeng Li Subject: [PATCH v4 5/8] staging: zcache: fix zcache writeback in debugfs Date: Tue, 19 Mar 2013 17:25:47 +0800 Message-Id: <1363685150-18303-6-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li commit 9c0ad59ef ("zcache/debug: Use an array to initialize/use debugfs attributes") use an array to initialize/use debugfs attributes, .name = #x, .val = &zcache_##x. For zcache writeback, this commit set .name = zcache_outstanding_writeback_pages and .name = zcache_writtenback_pages seperately, however, corresponding .val = &zcache_zcache_outstanding_writeback_pages and .val = &zcache_zcache_writtenback_pages, which are not correct. Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/zcache/debug.c b/drivers/staging/zcache/debug.c index 254dada..d2d1fdf 100644 --- a/drivers/staging/zcache/debug.c +++ b/drivers/staging/zcache/debug.c @@ -31,8 +31,8 @@ static struct debug_entry { ATTR(eph_nonactive_puts_ignored), ATTR(pers_nonactive_puts_ignored), #ifdef CONFIG_ZCACHE_WRITEBACK - ATTR(zcache_outstanding_writeback_pages), - ATTR(zcache_writtenback_pages), + ATTR(outstanding_writeback_pages), + ATTR(writtenback_pages), #endif }; #undef ATTR -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx204.postini.com [74.125.245.204]) by kanga.kvack.org (Postfix) with SMTP id A35686B0039 for ; Tue, 19 Mar 2013 05:26:17 -0400 (EDT) Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 14:52:01 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id D8C2D1258059 for ; Tue, 19 Mar 2013 14:57:19 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9Q9Wq6488516 for ; Tue, 19 Mar 2013 14:56:09 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9QAGk023762 for ; Tue, 19 Mar 2013 20:26:11 +1100 From: Wanpeng Li Subject: [PATCH v4 6/8] staging: zcache: fix static variables defined in debug.h but used in mutiple C files Date: Tue, 19 Mar 2013 17:25:48 +0800 Message-Id: <1363685150-18303-7-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li After commit 95bdaee214 ("zcache: Move debugfs code out of zcache-main.c file") be merged, most of knods in zcache debugfs just export zero since these variables are defined in debug.h but use in multiple C files zcache-main.c and debug.c, in this case variables can't be treated as shared variables. Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.h | 62 +++++++++++++++++----------------- drivers/staging/zcache/zcache-main.c | 31 +++++++++++++++++ 2 files changed, 62 insertions(+), 31 deletions(-) diff --git a/drivers/staging/zcache/debug.h b/drivers/staging/zcache/debug.h index 4bbe49b..8ec82d4 100644 --- a/drivers/staging/zcache/debug.h +++ b/drivers/staging/zcache/debug.h @@ -3,9 +3,9 @@ #ifdef CONFIG_ZCACHE_DEBUG /* we try to keep these statistics SMP-consistent */ -static ssize_t zcache_obj_count; +extern ssize_t zcache_obj_count; static atomic_t zcache_obj_atomic = ATOMIC_INIT(0); -static ssize_t zcache_obj_count_max; +extern ssize_t zcache_obj_count_max; static inline void inc_zcache_obj_count(void) { zcache_obj_count = atomic_inc_return(&zcache_obj_atomic); @@ -17,9 +17,9 @@ static inline void dec_zcache_obj_count(void) zcache_obj_count = atomic_dec_return(&zcache_obj_atomic); BUG_ON(zcache_obj_count < 0); }; -static ssize_t zcache_objnode_count; +extern ssize_t zcache_objnode_count; static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0); -static ssize_t zcache_objnode_count_max; +extern ssize_t zcache_objnode_count_max; static inline void inc_zcache_objnode_count(void) { zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic); @@ -31,9 +31,9 @@ static inline void dec_zcache_objnode_count(void) zcache_objnode_count = atomic_dec_return(&zcache_objnode_atomic); BUG_ON(zcache_objnode_count < 0); }; -static u64 zcache_eph_zbytes; +extern u64 zcache_eph_zbytes; static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0); -static u64 zcache_eph_zbytes_max; +extern u64 zcache_eph_zbytes_max; static inline void inc_zcache_eph_zbytes(unsigned clen) { zcache_eph_zbytes = atomic_long_add_return(clen, &zcache_eph_zbytes_atomic); @@ -46,7 +46,7 @@ static inline void dec_zcache_eph_zbytes(unsigned zsize) }; extern u64 zcache_pers_zbytes; static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0); -static u64 zcache_pers_zbytes_max; +extern u64 zcache_pers_zbytes_max; static inline void inc_zcache_pers_zbytes(unsigned clen) { zcache_pers_zbytes = atomic_long_add_return(clen, &zcache_pers_zbytes_atomic); @@ -59,7 +59,7 @@ static inline void dec_zcache_pers_zbytes(unsigned zsize) } extern ssize_t zcache_eph_pageframes; static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0); -static ssize_t zcache_eph_pageframes_max; +extern ssize_t zcache_eph_pageframes_max; static inline void inc_zcache_eph_pageframes(void) { zcache_eph_pageframes = atomic_inc_return(&zcache_eph_pageframes_atomic); @@ -72,7 +72,7 @@ static inline void dec_zcache_eph_pageframes(void) }; extern ssize_t zcache_pers_pageframes; static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0); -static ssize_t zcache_pers_pageframes_max; +extern ssize_t zcache_pers_pageframes_max; static inline void inc_zcache_pers_pageframes(void) { zcache_pers_pageframes = atomic_inc_return(&zcache_pers_pageframes_atomic); @@ -83,21 +83,21 @@ static inline void dec_zcache_pers_pageframes(void) { zcache_pers_pageframes = atomic_dec_return(&zcache_pers_pageframes_atomic); } -static ssize_t zcache_pageframes_alloced; +extern ssize_t zcache_pageframes_alloced; static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0); static inline void inc_zcache_pageframes_alloced(void) { zcache_pageframes_alloced = atomic_inc_return(&zcache_pageframes_alloced_atomic); }; -static ssize_t zcache_pageframes_freed; +extern ssize_t zcache_pageframes_freed; static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0); static inline void inc_zcache_pageframes_freed(void) { zcache_pageframes_freed = atomic_inc_return(&zcache_pageframes_freed_atomic); } -static ssize_t zcache_eph_zpages; +extern ssize_t zcache_eph_zpages; static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0); -static ssize_t zcache_eph_zpages_max; +extern ssize_t zcache_eph_zpages_max; static inline void inc_zcache_eph_zpages(void) { zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic); @@ -110,7 +110,7 @@ static inline void dec_zcache_eph_zpages(unsigned zpages) } extern ssize_t zcache_pers_zpages; static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0); -static ssize_t zcache_pers_zpages_max; +extern ssize_t zcache_pers_zpages_max; static inline void inc_zcache_pers_zpages(void) { zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic); @@ -130,23 +130,23 @@ static inline unsigned long curr_pageframes_count(void) atomic_read(&zcache_pers_pageframes_atomic); }; /* but for the rest of these, counting races are ok */ -static ssize_t zcache_flush_total; -static ssize_t zcache_flush_found; -static ssize_t zcache_flobj_total; -static ssize_t zcache_flobj_found; -static ssize_t zcache_failed_eph_puts; -static ssize_t zcache_failed_pers_puts; -static ssize_t zcache_failed_getfreepages; -static ssize_t zcache_failed_alloc; -static ssize_t zcache_put_to_flush; -static ssize_t zcache_compress_poor; -static ssize_t zcache_mean_compress_poor; -static ssize_t zcache_eph_ate_tail; -static ssize_t zcache_eph_ate_tail_failed; -static ssize_t zcache_pers_ate_eph; -static ssize_t zcache_pers_ate_eph_failed; -static ssize_t zcache_evicted_eph_zpages; -static ssize_t zcache_evicted_eph_pageframes; +extern ssize_t zcache_flush_total; +extern ssize_t zcache_flush_found; +extern ssize_t zcache_flobj_total; +extern ssize_t zcache_flobj_found; +extern ssize_t zcache_failed_eph_puts; +extern ssize_t zcache_failed_pers_puts; +extern ssize_t zcache_failed_getfreepages; +extern ssize_t zcache_failed_alloc; +extern ssize_t zcache_put_to_flush; +extern ssize_t zcache_compress_poor; +extern ssize_t zcache_mean_compress_poor; +extern ssize_t zcache_eph_ate_tail; +extern ssize_t zcache_eph_ate_tail_failed; +extern ssize_t zcache_pers_ate_eph; +extern ssize_t zcache_pers_ate_eph_failed; +extern ssize_t zcache_evicted_eph_zpages; +extern ssize_t zcache_evicted_eph_pageframes; extern ssize_t zcache_last_active_file_pageframes; extern ssize_t zcache_last_inactive_file_pageframes; diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 892e97e..d1118f0 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -145,6 +145,37 @@ ssize_t zcache_pers_zpages; u64 zcache_pers_zbytes; ssize_t zcache_eph_pageframes; ssize_t zcache_pers_pageframes; +ssize_t zcache_obj_count; +ssize_t zcache_obj_count_max; +ssize_t zcache_objnode_count; +ssize_t zcache_objnode_count_max; +u64 zcache_eph_zbytes; +u64 zcache_eph_zbytes_max; +u64 zcache_pers_zbytes_max; +ssize_t zcache_eph_pageframes_max; +ssize_t zcache_pers_pageframes_max; +ssize_t zcache_pageframes_alloced; +ssize_t zcache_pageframes_freed; +ssize_t zcache_eph_zpages; +ssize_t zcache_eph_zpages_max; +ssize_t zcache_pers_zpages_max; +ssize_t zcache_flush_total; +ssize_t zcache_flush_found; +ssize_t zcache_flobj_total; +ssize_t zcache_flobj_found; +ssize_t zcache_failed_eph_puts; +ssize_t zcache_failed_pers_puts; +ssize_t zcache_failed_getfreepages; +ssize_t zcache_failed_alloc; +ssize_t zcache_put_to_flush; +ssize_t zcache_compress_poor; +ssize_t zcache_mean_compress_poor; +ssize_t zcache_eph_ate_tail; +ssize_t zcache_eph_ate_tail_failed; +ssize_t zcache_pers_ate_eph; +ssize_t zcache_pers_ate_eph_failed; +ssize_t zcache_evicted_eph_zpages; +ssize_t zcache_evicted_eph_pageframes; /* Used by this code. */ ssize_t zcache_last_active_file_pageframes; -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx156.postini.com [74.125.245.156]) by kanga.kvack.org (Postfix) with SMTP id 8EC666B0039 for ; Tue, 19 Mar 2013 05:26:21 -0400 (EDT) Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 19:15:54 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 3C2E82BB0023 for ; Tue, 19 Mar 2013 20:26:13 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9Q90D2031894 for ; Tue, 19 Mar 2013 20:26:09 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9QCYq012642 for ; Tue, 19 Mar 2013 20:26:12 +1100 From: Wanpeng Li Subject: [PATCH v4 7/8] staging: zcache: introduce zero-filled page stat count Date: Tue, 19 Mar 2013 17:25:49 +0800 Message-Id: <1363685150-18303-8-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Introduce zero-filled page statistics to monitor the number of zero-filled pages. Acked-by: Dan Magenheimer Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.h | 15 +++++++++++++++ drivers/staging/zcache/zcache-main.c | 5 +++++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/drivers/staging/zcache/debug.h b/drivers/staging/zcache/debug.h index 8ec82d4..178bf75 100644 --- a/drivers/staging/zcache/debug.h +++ b/drivers/staging/zcache/debug.h @@ -122,6 +122,21 @@ static inline void dec_zcache_pers_zpages(unsigned zpages) zcache_pers_zpages = atomic_sub_return(zpages, &zcache_pers_zpages_atomic); } +extern ssize_t zcache_zero_filled_pages; +static atomic_t zcache_zero_filled_pages_atomic = ATOMIC_INIT(0); +extern ssize_t zcache_zero_filled_pages_max; +static inline void inc_zcache_zero_filled_pages(void) +{ + zcache_zero_filled_pages = atomic_inc_return( + &zcache_zero_filled_pages_atomic); + if (zcache_zero_filled_pages > zcache_zero_filled_pages_max) + zcache_zero_filled_pages_max = zcache_zero_filled_pages; +} +static inline void dec_zcache_zero_filled_pages(void) +{ + zcache_zero_filled_pages = atomic_dec_return( + &zcache_zero_filled_pages_atomic); +} static inline unsigned long curr_pageframes_count(void) { return zcache_pageframes_alloced - diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index d1118f0..f8ba619 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -176,6 +176,8 @@ ssize_t zcache_pers_ate_eph; ssize_t zcache_pers_ate_eph_failed; ssize_t zcache_evicted_eph_zpages; ssize_t zcache_evicted_eph_pageframes; +ssize_t zcache_zero_filled_pages; +ssize_t zcache_zero_filled_pages_max; /* Used by this code. */ ssize_t zcache_last_active_file_pageframes; @@ -404,6 +406,7 @@ static void *zcache_pampd_eph_create(char *data, size_t size, bool raw, if (page_is_zero_filled(page)) { clen = 0; zero_filled = true; + inc_zcache_zero_filled_pages(); goto got_pampd; } @@ -470,6 +473,7 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, if (page_is_zero_filled(page)) { clen = 0; zero_filled = true; + inc_zcache_zero_filled_pages(); goto got_pampd; } @@ -682,6 +686,7 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, zpages = 1; if (!raw) *sizep = PAGE_SIZE; + dec_zcache_zero_filled_pages(); goto zero_fill; } -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx206.postini.com [74.125.245.206]) by kanga.kvack.org (Postfix) with SMTP id 11D126B0039 for ; Tue, 19 Mar 2013 05:26:27 -0400 (EDT) Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 14:53:07 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 26378125805D for ; Tue, 19 Mar 2013 14:57:30 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9QIK56357470 for ; Tue, 19 Mar 2013 14:56:18 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9QHiw015461 for ; Tue, 19 Mar 2013 20:26:19 +1100 From: Wanpeng Li Subject: [PATCH v4 8/8] staging: zcache: clean TODO list Date: Tue, 19 Mar 2013 17:25:50 +0800 Message-Id: <1363685150-18303-9-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Cleanup TODO list since support zero-filled pages more efficiently has already done by this patchset. Acked-by: Dan Magenheimer Signed-off-by: Wanpeng Li --- drivers/staging/zcache/TODO | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/drivers/staging/zcache/TODO b/drivers/staging/zcache/TODO index ec9aa11..d0c18fa 100644 --- a/drivers/staging/zcache/TODO +++ b/drivers/staging/zcache/TODO @@ -61,5 +61,4 @@ ZCACHE FUTURE NEW FUNCTIONALITY A. Support zsmalloc as an alternative high-density allocator (See https://lkml.org/lkml/2013/1/23/511) -B. Support zero-filled pages more efficiently -C. Possibly support three zbuds per pageframe when space allows +B. Possibly support three zbuds per pageframe when space allows -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx180.postini.com [74.125.245.180]) by kanga.kvack.org (Postfix) with SMTP id 45D286B003A for ; Tue, 19 Mar 2013 05:26:30 -0400 (EDT) Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 19:24:28 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 40A123578054 for ; Tue, 19 Mar 2013 20:26:23 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9D1vp63766708 for ; Tue, 19 Mar 2013 20:13:01 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9PqZw031888 for ; Tue, 19 Mar 2013 20:25:52 +1100 From: Wanpeng Li Subject: [PATCH v4 0/8] staging: zcache: Support zero-filled pages more efficiently Date: Tue, 19 Mar 2013 17:25:42 +0800 Message-Id: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Hi Greg, Since you have already merge 1/8, feel free to merge 2/8~8/8, I have already rebased against staging-next. Changelog: v3 -> v4: * handle duplication in page_is_zero_filled, spotted by Bob * fix zcache writeback in dubugfs * fix pers_pageframes|_max isn't exported in debugfs * fix static variable defined in debug.h but used in multiple C files * rebase on Greg's staging-next v2 -> v3: * increment/decrement zcache_[eph|pers]_zpages for zero-filled pages, spotted by Dan * replace "zero" or "zero page" by "zero_filled_page", spotted by Dan v1 -> v2: * avoid changing tmem.[ch] entirely, spotted by Dan. * don't accumulate [eph|pers]pageframe and [eph|pers]zpages for zero-filled pages, spotted by Dan * cleanup TODO list * add Dan Acked-by. Motivation: - Seth Jennings points out compress zero-filled pages with LZO(a lossless data compression algorithm) will waste memory and result in fragmentation. https://lkml.org/lkml/2012/8/14/347 - Dan Magenheimer add "Support zero-filled pages more efficiently" feature in zcache TODO list https://lkml.org/lkml/2013/2/13/503 Design: - For store page, capture zero-filled pages(evicted clean page cache pages and swap pages), but don't compress them, set pampd which store zpage address to 0x2(since 0x0 and 0x1 has already been ocuppied) to mark special zero-filled case and take advantage of tmem infrastructure to transform handle-tuple(pool id, object id, and an index) to a pampd. Twice compress zero-filled pages will contribute to one zcache_[eph|pers]_pageframes count accumulated. - For load page, traverse tmem hierachical to transform handle-tuple to pampd and identify zero-filled case by pampd equal to 0x2 when filesystem reads file pages or a page needs to be swapped in, then refill the page to zero and return. Test: dd if=/dev/zero of=zerofile bs=1MB count=500 vmtouch -t zerofile vmtouch -e zerofile formula: - fragmentation level = (zcache_[eph|pers]_pageframes * PAGE_SIZE - zcache_[eph|pers]_zbytes) * 100 / (zcache_[eph|pers]_pageframes * PAGE_SIZE) - memory zcache occupy = zcache_[eph|pers]_zbytes Result: without zero-filled awareness: - fragmentation level: 98% - memory zcache occupy: 238MB with zero-filled awareness: - fragmentation level: 0% - memory zcache occupy: 0MB Wanpeng Li (8): introduce zero filled pages handler zero-filled pages awareness handle zcache_[eph|pers]_pages for zero-filled page fix pers_pageframes|_max aren't exported in debugfs fix zcache writeback in debugfs fix static variables are defined in debug.h but use in multiple C files introduce zero-filled page stat count clean TODO list drivers/staging/zcache/TODO | 3 +- drivers/staging/zcache/debug.c | 5 +- drivers/staging/zcache/debug.h | 77 +++++++++++++--------- drivers/staging/zcache/zcache-main.c | 147 ++++++++++++++++++++++++++++++---- 4 files changed, 185 insertions(+), 47 deletions(-) -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx172.postini.com [74.125.245.172]) by kanga.kvack.org (Postfix) with SMTP id 8F4946B003C for ; Tue, 19 Mar 2013 05:26:31 -0400 (EDT) Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 19:19:44 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 46031357804A for ; Tue, 19 Mar 2013 20:26:25 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9D3sC2621872 for ; Tue, 19 Mar 2013 20:13:03 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9Ps5t012174 for ; Tue, 19 Mar 2013 20:25:54 +1100 From: Wanpeng Li Subject: [PATCH v4 1/8] staging: zcache: introduce zero-filled pages handler Date: Tue, 19 Mar 2013 17:25:43 +0800 Message-Id: <1363685150-18303-2-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Introduce zero-filled pages handler to capture and handle zero pages. Acked-by: Dan Magenheimer Signed-off-by: Wanpeng Li --- drivers/staging/zcache/zcache-main.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 328898e..d73dd4b 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -460,6 +460,32 @@ static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) kmem_cache_free(zcache_obj_cache, obj); } +static bool page_is_zero_filled(void *ptr) +{ + unsigned int pos; + unsigned long *page; + + page = (unsigned long *)ptr; + + for (pos = 0; pos < PAGE_SIZE / sizeof(*page); pos++) { + if (page[pos]) + return false; + } + + return true; +} + +static void handle_zero_filled_page(void *page) +{ + void *user_mem; + + user_mem = kmap_atomic(page); + memset(user_mem, 0, PAGE_SIZE); + kunmap_atomic(user_mem); + + flush_dcache_page(page); +} + static struct tmem_hostops zcache_hostops = { .obj_alloc = zcache_obj_alloc, .obj_free = zcache_obj_free, -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx191.postini.com [74.125.245.191]) by kanga.kvack.org (Postfix) with SMTP id 4AB9B6B003C for ; Tue, 19 Mar 2013 05:26:40 -0400 (EDT) Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2013 19:21:27 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 4C5B02BB0051 for ; Tue, 19 Mar 2013 20:26:07 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2J9Q3Re57671742 for ; Tue, 19 Mar 2013 20:26:03 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2J9Q6XS028045 for ; Tue, 19 Mar 2013 20:26:07 +1100 From: Wanpeng Li Subject: [PATCH v4 4/8] staging: zcache: fix pers_pageframes|_max aren't exported in debugfs Date: Tue, 19 Mar 2013 17:25:46 +0800 Message-Id: <1363685150-18303-5-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Before commit 9c0ad59ef ("zcache/debug: Use an array to initialize/use debugfs attributes"), pers_pageframes|_max are exported in debugfs, but this commit forgot use array export pers_pageframes|_max. This patch add pers_pageframes|_max back. Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/drivers/staging/zcache/debug.c b/drivers/staging/zcache/debug.c index e951c64..254dada 100644 --- a/drivers/staging/zcache/debug.c +++ b/drivers/staging/zcache/debug.c @@ -21,6 +21,7 @@ static struct debug_entry { ATTR(pers_ate_eph), ATTR(pers_ate_eph_failed), ATTR(evicted_eph_zpages), ATTR(evicted_eph_pageframes), ATTR(eph_pageframes), ATTR(eph_pageframes_max), + ATTR(pers_pageframes), ATTR(pers_pageframes_max), ATTR(eph_zpages), ATTR(eph_zpages_max), ATTR(pers_zpages), ATTR(pers_zpages_max), ATTR(last_active_file_pageframes), -- 1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx151.postini.com [74.125.245.151]) by kanga.kvack.org (Postfix) with SMTP id 8C5FB6B0005 for ; Tue, 19 Mar 2013 19:34:08 -0400 (EDT) Received: by mail-pb0-f43.google.com with SMTP id md12so843548pbc.16 for ; Tue, 19 Mar 2013 16:34:07 -0700 (PDT) Message-ID: <5148F5EA.3020904@gmail.com> Date: Wed, 20 Mar 2013 07:34:02 +0800 From: Ric Mason MIME-Version: 1.0 Subject: Re: [PATCH v4 0/8] staging: zcache: Support zero-filled pages more efficiently References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Wanpeng Li Cc: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org On 03/19/2013 05:25 PM, Wanpeng Li wrote: > Hi Greg, > > Since you have already merge 1/8, feel free to merge 2/8~8/8, I have already > rebased against staging-next. > > Changelog: > v3 -> v4: > * handle duplication in page_is_zero_filled, spotted by Bob > * fix zcache writeback in dubugfs > * fix pers_pageframes|_max isn't exported in debugfs > * fix static variable defined in debug.h but used in multiple C files > * rebase on Greg's staging-next > v2 -> v3: > * increment/decrement zcache_[eph|pers]_zpages for zero-filled pages, spotted by Dan > * replace "zero" or "zero page" by "zero_filled_page", spotted by Dan > v1 -> v2: > * avoid changing tmem.[ch] entirely, spotted by Dan. > * don't accumulate [eph|pers]pageframe and [eph|pers]zpages for > zero-filled pages, spotted by Dan > * cleanup TODO list > * add Dan Acked-by. > > Motivation: > > - Seth Jennings points out compress zero-filled pages with LZO(a lossless > data compression algorithm) will waste memory and result in fragmentation. > https://lkml.org/lkml/2012/8/14/347 > - Dan Magenheimer add "Support zero-filled pages more efficiently" feature > in zcache TODO list https://lkml.org/lkml/2013/2/13/503 > > Design: > > - For store page, capture zero-filled pages(evicted clean page cache pages and > swap pages), but don't compress them, set pampd which store zpage address to > 0x2(since 0x0 and 0x1 has already been ocuppied) to mark special zero-filled > case and take advantage of tmem infrastructure to transform handle-tuple(pool > id, object id, and an index) to a pampd. Twice compress zero-filled pages will > contribute to one zcache_[eph|pers]_pageframes count accumulated. > - For load page, traverse tmem hierachical to transform handle-tuple to pampd > and identify zero-filled case by pampd equal to 0x2 when filesystem reads > file pages or a page needs to be swapped in, then refill the page to zero > and return. > > Test: > > dd if=/dev/zero of=zerofile bs=1MB count=500 > vmtouch -t zerofile > vmtouch -e zerofile > > formula: > - fragmentation level = (zcache_[eph|pers]_pageframes * PAGE_SIZE - zcache_[eph|pers]_zbytes) > * 100 / (zcache_[eph|pers]_pageframes * PAGE_SIZE) > - memory zcache occupy = zcache_[eph|pers]_zbytes > > Result: > > without zero-filled awareness: > - fragmentation level: 98% > - memory zcache occupy: 238MB > with zero-filled awareness: > - fragmentation level: 0% > - memory zcache occupy: 0MB > > Wanpeng Li (8): > introduce zero filled pages handler > zero-filled pages awareness > handle zcache_[eph|pers]_pages for zero-filled page > fix pers_pageframes|_max aren't exported in debugfs > fix zcache writeback in debugfs > fix static variables are defined in debug.h but use in multiple C files > introduce zero-filled page stat count > clean TODO list You can add Reviewed-by: Ric Mason to this patchset. > > drivers/staging/zcache/TODO | 3 +- > drivers/staging/zcache/debug.c | 5 +- > drivers/staging/zcache/debug.h | 77 +++++++++++++--------- > drivers/staging/zcache/zcache-main.c | 147 ++++++++++++++++++++++++++++++---- > 4 files changed, 185 insertions(+), 47 deletions(-) > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx156.postini.com [74.125.245.156]) by kanga.kvack.org (Postfix) with SMTP id 9A9D86B0005 for ; Wed, 20 Mar 2013 06:30:57 -0400 (EDT) Message-ID: <51498FCE.60603@oracle.com> Date: Wed, 20 Mar 2013 18:30:38 +0800 From: Bob Liu MIME-Version: 1.0 Subject: Re: [PATCH v4 2/8] staging: zcache: zero-filled pages awareness References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Wanpeng Li Cc: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org > @@ -641,16 +691,22 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, > { > struct page *page = NULL; > unsigned int zsize, zpages; > + bool zero_filled = false; > > BUG_ON(preemptible()); > - if (pampd_is_remote(pampd)) { > + > + if (pampd == (void *)ZERO_FILLED) > + zero_filled = true; > + > + if (pampd_is_remote(pampd) && !zero_filled) { > BUG_ON(!ramster_enabled); > pampd = ramster_pampd_free(pampd, pool, oid, index, acct); > if (pampd == NULL) > return; > } > if (is_ephemeral(pool)) { > - page = zbud_free_and_delist((struct zbudref *)pampd, > + if (!zero_filled) > + page = zbud_free_and_delist((struct zbudref *)pampd, > true, &zsize, &zpages); This check should also apply for !is_ephemeral(pool). > if (page) > dec_zcache_eph_pageframes(); > @@ -667,7 +723,7 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, > } > if (!is_local_client(pool->client)) > ramster_count_foreign_pages(is_ephemeral(pool), -1); > - if (page) > + if (page && !zero_filled) > zcache_free_page(page); > } > > -- Regards, -Bob -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx158.postini.com [74.125.245.158]) by kanga.kvack.org (Postfix) with SMTP id DA6C56B0005 for ; Wed, 20 Mar 2013 06:44:29 -0400 (EDT) Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Mar 2013 20:39:13 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id C0BE83578051 for ; Wed, 20 Mar 2013 21:44:22 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2KAUnEs9961970 for ; Wed, 20 Mar 2013 21:30:50 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2KAhpZp013810 for ; Wed, 20 Mar 2013 21:43:51 +1100 Date: Wed, 20 Mar 2013 18:43:49 +0800 From: Wanpeng Li Subject: Re: [PATCH v4 2/8] staging: zcache: zero-filled pages awareness Message-ID: <20130320104349.GA21402@hacker.(null)> Reply-To: Wanpeng Li References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> <51498FCE.60603@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51498FCE.60603@oracle.com> Sender: owner-linux-mm@kvack.org List-ID: To: Bob Liu Cc: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org On Wed, Mar 20, 2013 at 06:30:38PM +0800, Bob Liu wrote: > >> @@ -641,16 +691,22 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, >> { >> struct page *page = NULL; >> unsigned int zsize, zpages; >> + bool zero_filled = false; >> >> BUG_ON(preemptible()); >> - if (pampd_is_remote(pampd)) { >> + >> + if (pampd == (void *)ZERO_FILLED) >> + zero_filled = true; >> + >> + if (pampd_is_remote(pampd) && !zero_filled) { >> BUG_ON(!ramster_enabled); >> pampd = ramster_pampd_free(pampd, pool, oid, index, acct); >> if (pampd == NULL) >> return; >> } >> if (is_ephemeral(pool)) { >> - page = zbud_free_and_delist((struct zbudref *)pampd, >> + if (!zero_filled) >> + page = zbud_free_and_delist((struct zbudref *)pampd, >> true, &zsize, &zpages); > >This check should also apply for !is_ephemeral(pool). Good catch, fixed. > >> if (page) >> dec_zcache_eph_pageframes(); >> @@ -667,7 +723,7 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, >> } >> if (!is_local_client(pool->client)) >> ramster_count_foreign_pages(is_ephemeral(pool), -1); >> - if (page) >> + if (page && !zero_filled) >> zcache_free_page(page); >> } >> >> > >-- >Regards, >-Bob -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wanpeng Li Subject: Re: [PATCH v4 2/8] staging: zcache: zero-filled pages awareness Date: Wed, 20 Mar 2013 18:43:49 +0800 Message-ID: <41677.2850011059$1363776299@news.gmane.org> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> <51498FCE.60603@oracle.com> Reply-To: Wanpeng Li Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from kanga.kvack.org ([205.233.56.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UIGVr-0000nj-Uh for glkm-linux-mm-2@m.gmane.org; Wed, 20 Mar 2013 11:44:56 +0100 Received: from psmtp.com (na3sys010amx158.postini.com [74.125.245.158]) by kanga.kvack.org (Postfix) with SMTP id DA6C56B0005 for ; Wed, 20 Mar 2013 06:44:29 -0400 (EDT) Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Mar 2013 20:39:13 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id C0BE83578051 for ; Wed, 20 Mar 2013 21:44:22 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2KAUnEs9961970 for ; Wed, 20 Mar 2013 21:30:50 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2KAhpZp013810 for ; Wed, 20 Mar 2013 21:43:51 +1100 Content-Disposition: inline In-Reply-To: <51498FCE.60603@oracle.com> Sender: owner-linux-mm@kvack.org List-ID: To: Bob Liu Cc: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org On Wed, Mar 20, 2013 at 06:30:38PM +0800, Bob Liu wrote: > >> @@ -641,16 +691,22 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, >> { >> struct page *page = NULL; >> unsigned int zsize, zpages; >> + bool zero_filled = false; >> >> BUG_ON(preemptible()); >> - if (pampd_is_remote(pampd)) { >> + >> + if (pampd == (void *)ZERO_FILLED) >> + zero_filled = true; >> + >> + if (pampd_is_remote(pampd) && !zero_filled) { >> BUG_ON(!ramster_enabled); >> pampd = ramster_pampd_free(pampd, pool, oid, index, acct); >> if (pampd == NULL) >> return; >> } >> if (is_ephemeral(pool)) { >> - page = zbud_free_and_delist((struct zbudref *)pampd, >> + if (!zero_filled) >> + page = zbud_free_and_delist((struct zbudref *)pampd, >> true, &zsize, &zpages); > >This check should also apply for !is_ephemeral(pool). Good catch, fixed. > >> if (page) >> dec_zcache_eph_pageframes(); >> @@ -667,7 +723,7 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, >> } >> if (!is_local_client(pool->client)) >> ramster_count_foreign_pages(is_ephemeral(pool), -1); >> - if (page) >> + if (page && !zero_filled) >> zcache_free_page(page); >> } >> >> > >-- >Regards, >-Bob -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757877Ab3CSJ0G (ORCPT ); Tue, 19 Mar 2013 05:26:06 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:37770 "EHLO e23smtp08.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755166Ab3CSJ0C (ORCPT ); Tue, 19 Mar 2013 05:26:02 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 1/8] staging: zcache: introduce zero-filled pages handler Date: Tue, 19 Mar 2013 17:25:43 +0800 Message-Id: <1363685150-18303-2-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031909-5140-0000-0000-000002E9638E Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce zero-filled pages handler to capture and handle zero pages. Acked-by: Dan Magenheimer Signed-off-by: Wanpeng Li --- drivers/staging/zcache/zcache-main.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 328898e..d73dd4b 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -460,6 +460,32 @@ static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) kmem_cache_free(zcache_obj_cache, obj); } +static bool page_is_zero_filled(void *ptr) +{ + unsigned int pos; + unsigned long *page; + + page = (unsigned long *)ptr; + + for (pos = 0; pos < PAGE_SIZE / sizeof(*page); pos++) { + if (page[pos]) + return false; + } + + return true; +} + +static void handle_zero_filled_page(void *page) +{ + void *user_mem; + + user_mem = kmap_atomic(page); + memset(user_mem, 0, PAGE_SIZE); + kunmap_atomic(user_mem); + + flush_dcache_page(page); +} + static struct tmem_hostops zcache_hostops = { .obj_alloc = zcache_obj_alloc, .obj_free = zcache_obj_free, -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932826Ab3CSJ0N (ORCPT ); Tue, 19 Mar 2013 05:26:13 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:38735 "EHLO e28smtp05.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755166Ab3CSJ0I (ORCPT ); Tue, 19 Mar 2013 05:26:08 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 2/8] staging: zcache: zero-filled pages awareness Date: Tue, 19 Mar 2013 17:25:44 +0800 Message-Id: <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031909-8256-0000-0000-000006B3C0A7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Compression of zero-filled pages can unneccessarily cause internal fragmentation, and thus waste memory. This special case can be optimized. This patch captures zero-filled pages, and marks their corresponding zcache backing page entry as zero-filled. Whenever such zero-filled page is retrieved, we fill the page frame with zero. Acked-by: Dan Magenheimer Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Wanpeng Li --- drivers/staging/zcache/zcache-main.c | 80 ++++++++++++++++++++++++++++----- 1 files changed, 68 insertions(+), 12 deletions(-) diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 86ead8d..050a99f 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -61,6 +61,12 @@ static inline void frontswap_tmem_exclusive_gets(bool b) } #endif +/* + * mark pampd to special value in order that later + * retrieve will identify zero-filled pages + */ +#define ZERO_FILLED 0x2 + /* enable (or fix code) when Seth's patches are accepted upstream */ #define zcache_writeback_enabled 0 @@ -277,17 +283,23 @@ static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) kmem_cache_free(zcache_obj_cache, obj); } -static bool page_is_zero_filled(void *ptr) +/* + * Compressing zero-filled pages will waste memory and introduce + * serious fragmentation, skip it to avoid overhead. + */ +static bool page_is_zero_filled(struct page *p) { unsigned int pos; - unsigned long *page; - - page = (unsigned long *)ptr; + char *page; + page = kmap_atomic(p); for (pos = 0; pos < PAGE_SIZE / sizeof(*page); pos++) { - if (page[pos]) + if (page[pos]) { + kunmap_atomic(page); return false; + } } + kunmap_atomic(page); return true; } @@ -355,8 +367,15 @@ static void *zcache_pampd_eph_create(char *data, size_t size, bool raw, { void *pampd = NULL, *cdata = data; unsigned clen = size; + bool zero_filled = false; struct page *page = (struct page *)(data), *newpage; + if (page_is_zero_filled(page)) { + clen = 0; + zero_filled = true; + goto got_pampd; + } + if (!raw) { zcache_compress(page, &cdata, &clen); if (clen > zbud_max_buddy_size()) { @@ -396,6 +415,8 @@ got_pampd: inc_zcache_eph_zpages(); if (ramster_enabled && raw) ramster_count_foreign_pages(true, 1); + if (zero_filled) + pampd = (void *)ZERO_FILLED; out: return pampd; } @@ -405,6 +426,7 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, { void *pampd = NULL, *cdata = data; unsigned clen = size; + bool zero_filled = false; struct page *page = (struct page *)(data), *newpage; unsigned long zbud_mean_zsize; unsigned long curr_pers_zpages, total_zsize; @@ -413,6 +435,13 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, BUG_ON(!ramster_enabled); goto create_pampd; } + + if (page_is_zero_filled(page)) { + clen = 0; + zero_filled = true; + goto got_pampd; + } + curr_pers_zpages = zcache_pers_zpages; /* FIXME CONFIG_RAMSTER... subtract atomic remote_pers_pages here? */ if (!raw) @@ -470,6 +499,8 @@ got_pampd: inc_zcache_pers_zbytes(clen); if (ramster_enabled && raw) ramster_count_foreign_pages(false, 1); + if (zero_filled) + pampd = (void *)ZERO_FILLED; out: return pampd; } @@ -531,7 +562,8 @@ out: */ void zcache_pampd_create_finish(void *pampd, bool eph) { - zbud_create_finish((struct zbudref *)pampd, eph); + if (pampd != (void *)ZERO_FILLED) + zbud_create_finish((struct zbudref *)pampd, eph); } /* @@ -576,6 +608,14 @@ static int zcache_pampd_get_data(char *data, size_t *sizep, bool raw, BUG_ON(preemptible()); BUG_ON(eph); /* fix later if shared pools get implemented */ BUG_ON(pampd_is_remote(pampd)); + + if (pampd == (void *)ZERO_FILLED) { + handle_zero_filled_page(data); + if (!raw) + *sizep = PAGE_SIZE; + return 0; + } + if (raw) ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, sizep, eph); @@ -596,13 +636,22 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, void *pampd, struct tmem_pool *pool, struct tmem_oid *oid, uint32_t index) { - int ret; - bool eph = !is_persistent(pool); + int ret = 0; + bool eph = !is_persistent(pool), zero_filled = false; struct page *page = NULL; unsigned int zsize, zpages; BUG_ON(preemptible()); BUG_ON(pampd_is_remote(pampd)); + + if (pampd == (void *)ZERO_FILLED) { + handle_zero_filled_page(data); + zero_filled = true; + if (!raw) + *sizep = PAGE_SIZE; + goto zero_fill; + } + if (raw) ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd, sizep, eph); @@ -614,6 +663,7 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, } page = zbud_free_and_delist((struct zbudref *)pampd, eph, &zsize, &zpages); +zero_fill: if (eph) { if (page) dec_zcache_eph_pageframes(); @@ -627,7 +677,7 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, } if (!is_local_client(pool->client)) ramster_count_foreign_pages(eph, -1); - if (page) + if (page && !zero_filled) zcache_free_page(page); return ret; } @@ -641,16 +691,22 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, { struct page *page = NULL; unsigned int zsize, zpages; + bool zero_filled = false; BUG_ON(preemptible()); - if (pampd_is_remote(pampd)) { + + if (pampd == (void *)ZERO_FILLED) + zero_filled = true; + + if (pampd_is_remote(pampd) && !zero_filled) { BUG_ON(!ramster_enabled); pampd = ramster_pampd_free(pampd, pool, oid, index, acct); if (pampd == NULL) return; } if (is_ephemeral(pool)) { - page = zbud_free_and_delist((struct zbudref *)pampd, + if (!zero_filled) + page = zbud_free_and_delist((struct zbudref *)pampd, true, &zsize, &zpages); if (page) dec_zcache_eph_pageframes(); @@ -667,7 +723,7 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, } if (!is_local_client(pool->client)) ramster_count_foreign_pages(is_ephemeral(pool), -1); - if (page) + if (page && !zero_filled) zcache_free_page(page); } -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933352Ab3CSJ0S (ORCPT ); Tue, 19 Mar 2013 05:26:18 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:33962 "EHLO e28smtp04.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932842Ab3CSJ0O (ORCPT ); Tue, 19 Mar 2013 05:26:14 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 3/8] staging: zcache: handle zcache_[eph|pers]_zpages for zero-filled page Date: Tue, 19 Mar 2013 17:25:45 +0800 Message-Id: <1363685150-18303-4-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031909-5564-0000-0000-00000720E53F Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Increment/decrement zcache_[eph|pers]_zpages for zero-filled pages, the main point of the counters for zpages and pageframes is to be able to calculate density == zpages/pageframes. A zero-filled page becomes a zpage that "compresses" to zero bytes and, as a result, requires zero pageframes for storage. So the zpages counter should be increased but the pageframes counter should not. [Dan Magenheimer : patch description] Acked-by: Dan Magenheimer Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Wanpeng Li --- drivers/staging/zcache/zcache-main.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 050a99f..892e97e 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -647,6 +647,8 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, if (pampd == (void *)ZERO_FILLED) { handle_zero_filled_page(data); zero_filled = true; + zsize = 0; + zpages = 1; if (!raw) *sizep = PAGE_SIZE; goto zero_fill; @@ -695,8 +697,11 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, BUG_ON(preemptible()); - if (pampd == (void *)ZERO_FILLED) + if (pampd == (void *)ZERO_FILLED) { zero_filled = true; + zsize = 0; + zpages = 1; + } if (pampd_is_remote(pampd) && !zero_filled) { BUG_ON(!ramster_enabled); -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934263Ab3CSJ0Z (ORCPT ); Tue, 19 Mar 2013 05:26:25 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:48329 "EHLO e23smtp01.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932884Ab3CSJ0S (ORCPT ); Tue, 19 Mar 2013 05:26:18 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 0/8] staging: zcache: Support zero-filled pages more efficiently Date: Tue, 19 Mar 2013 17:25:42 +0800 Message-Id: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031909-1618-0000-0000-000003880C5D Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, Since you have already merge 1/8, feel free to merge 2/8~8/8, I have already rebased against staging-next. Changelog: v3 -> v4: * handle duplication in page_is_zero_filled, spotted by Bob * fix zcache writeback in dubugfs * fix pers_pageframes|_max isn't exported in debugfs * fix static variable defined in debug.h but used in multiple C files * rebase on Greg's staging-next v2 -> v3: * increment/decrement zcache_[eph|pers]_zpages for zero-filled pages, spotted by Dan * replace "zero" or "zero page" by "zero_filled_page", spotted by Dan v1 -> v2: * avoid changing tmem.[ch] entirely, spotted by Dan. * don't accumulate [eph|pers]pageframe and [eph|pers]zpages for zero-filled pages, spotted by Dan * cleanup TODO list * add Dan Acked-by. Motivation: - Seth Jennings points out compress zero-filled pages with LZO(a lossless data compression algorithm) will waste memory and result in fragmentation. https://lkml.org/lkml/2012/8/14/347 - Dan Magenheimer add "Support zero-filled pages more efficiently" feature in zcache TODO list https://lkml.org/lkml/2013/2/13/503 Design: - For store page, capture zero-filled pages(evicted clean page cache pages and swap pages), but don't compress them, set pampd which store zpage address to 0x2(since 0x0 and 0x1 has already been ocuppied) to mark special zero-filled case and take advantage of tmem infrastructure to transform handle-tuple(pool id, object id, and an index) to a pampd. Twice compress zero-filled pages will contribute to one zcache_[eph|pers]_pageframes count accumulated. - For load page, traverse tmem hierachical to transform handle-tuple to pampd and identify zero-filled case by pampd equal to 0x2 when filesystem reads file pages or a page needs to be swapped in, then refill the page to zero and return. Test: dd if=/dev/zero of=zerofile bs=1MB count=500 vmtouch -t zerofile vmtouch -e zerofile formula: - fragmentation level = (zcache_[eph|pers]_pageframes * PAGE_SIZE - zcache_[eph|pers]_zbytes) * 100 / (zcache_[eph|pers]_pageframes * PAGE_SIZE) - memory zcache occupy = zcache_[eph|pers]_zbytes Result: without zero-filled awareness: - fragmentation level: 98% - memory zcache occupy: 238MB with zero-filled awareness: - fragmentation level: 0% - memory zcache occupy: 0MB Wanpeng Li (8): introduce zero filled pages handler zero-filled pages awareness handle zcache_[eph|pers]_pages for zero-filled page fix pers_pageframes|_max aren't exported in debugfs fix zcache writeback in debugfs fix static variables are defined in debug.h but use in multiple C files introduce zero-filled page stat count clean TODO list drivers/staging/zcache/TODO | 3 +- drivers/staging/zcache/debug.c | 5 +- drivers/staging/zcache/debug.h | 77 +++++++++++++--------- drivers/staging/zcache/zcache-main.c | 147 ++++++++++++++++++++++++++++++---- 4 files changed, 185 insertions(+), 47 deletions(-) -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933663Ab3CSJ0W (ORCPT ); Tue, 19 Mar 2013 05:26:22 -0400 Received: from e28smtp03.in.ibm.com ([122.248.162.3]:41618 "EHLO e28smtp03.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932860Ab3CSJ0T (ORCPT ); Tue, 19 Mar 2013 05:26:19 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 6/8] staging: zcache: fix static variables defined in debug.h but used in mutiple C files Date: Tue, 19 Mar 2013 17:25:48 +0800 Message-Id: <1363685150-18303-7-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031909-3864-0000-0000-000007551375 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After commit 95bdaee214 ("zcache: Move debugfs code out of zcache-main.c file") be merged, most of knods in zcache debugfs just export zero since these variables are defined in debug.h but use in multiple C files zcache-main.c and debug.c, in this case variables can't be treated as shared variables. Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.h | 62 +++++++++++++++++----------------- drivers/staging/zcache/zcache-main.c | 31 +++++++++++++++++ 2 files changed, 62 insertions(+), 31 deletions(-) diff --git a/drivers/staging/zcache/debug.h b/drivers/staging/zcache/debug.h index 4bbe49b..8ec82d4 100644 --- a/drivers/staging/zcache/debug.h +++ b/drivers/staging/zcache/debug.h @@ -3,9 +3,9 @@ #ifdef CONFIG_ZCACHE_DEBUG /* we try to keep these statistics SMP-consistent */ -static ssize_t zcache_obj_count; +extern ssize_t zcache_obj_count; static atomic_t zcache_obj_atomic = ATOMIC_INIT(0); -static ssize_t zcache_obj_count_max; +extern ssize_t zcache_obj_count_max; static inline void inc_zcache_obj_count(void) { zcache_obj_count = atomic_inc_return(&zcache_obj_atomic); @@ -17,9 +17,9 @@ static inline void dec_zcache_obj_count(void) zcache_obj_count = atomic_dec_return(&zcache_obj_atomic); BUG_ON(zcache_obj_count < 0); }; -static ssize_t zcache_objnode_count; +extern ssize_t zcache_objnode_count; static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0); -static ssize_t zcache_objnode_count_max; +extern ssize_t zcache_objnode_count_max; static inline void inc_zcache_objnode_count(void) { zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic); @@ -31,9 +31,9 @@ static inline void dec_zcache_objnode_count(void) zcache_objnode_count = atomic_dec_return(&zcache_objnode_atomic); BUG_ON(zcache_objnode_count < 0); }; -static u64 zcache_eph_zbytes; +extern u64 zcache_eph_zbytes; static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0); -static u64 zcache_eph_zbytes_max; +extern u64 zcache_eph_zbytes_max; static inline void inc_zcache_eph_zbytes(unsigned clen) { zcache_eph_zbytes = atomic_long_add_return(clen, &zcache_eph_zbytes_atomic); @@ -46,7 +46,7 @@ static inline void dec_zcache_eph_zbytes(unsigned zsize) }; extern u64 zcache_pers_zbytes; static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0); -static u64 zcache_pers_zbytes_max; +extern u64 zcache_pers_zbytes_max; static inline void inc_zcache_pers_zbytes(unsigned clen) { zcache_pers_zbytes = atomic_long_add_return(clen, &zcache_pers_zbytes_atomic); @@ -59,7 +59,7 @@ static inline void dec_zcache_pers_zbytes(unsigned zsize) } extern ssize_t zcache_eph_pageframes; static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0); -static ssize_t zcache_eph_pageframes_max; +extern ssize_t zcache_eph_pageframes_max; static inline void inc_zcache_eph_pageframes(void) { zcache_eph_pageframes = atomic_inc_return(&zcache_eph_pageframes_atomic); @@ -72,7 +72,7 @@ static inline void dec_zcache_eph_pageframes(void) }; extern ssize_t zcache_pers_pageframes; static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0); -static ssize_t zcache_pers_pageframes_max; +extern ssize_t zcache_pers_pageframes_max; static inline void inc_zcache_pers_pageframes(void) { zcache_pers_pageframes = atomic_inc_return(&zcache_pers_pageframes_atomic); @@ -83,21 +83,21 @@ static inline void dec_zcache_pers_pageframes(void) { zcache_pers_pageframes = atomic_dec_return(&zcache_pers_pageframes_atomic); } -static ssize_t zcache_pageframes_alloced; +extern ssize_t zcache_pageframes_alloced; static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0); static inline void inc_zcache_pageframes_alloced(void) { zcache_pageframes_alloced = atomic_inc_return(&zcache_pageframes_alloced_atomic); }; -static ssize_t zcache_pageframes_freed; +extern ssize_t zcache_pageframes_freed; static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0); static inline void inc_zcache_pageframes_freed(void) { zcache_pageframes_freed = atomic_inc_return(&zcache_pageframes_freed_atomic); } -static ssize_t zcache_eph_zpages; +extern ssize_t zcache_eph_zpages; static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0); -static ssize_t zcache_eph_zpages_max; +extern ssize_t zcache_eph_zpages_max; static inline void inc_zcache_eph_zpages(void) { zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic); @@ -110,7 +110,7 @@ static inline void dec_zcache_eph_zpages(unsigned zpages) } extern ssize_t zcache_pers_zpages; static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0); -static ssize_t zcache_pers_zpages_max; +extern ssize_t zcache_pers_zpages_max; static inline void inc_zcache_pers_zpages(void) { zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic); @@ -130,23 +130,23 @@ static inline unsigned long curr_pageframes_count(void) atomic_read(&zcache_pers_pageframes_atomic); }; /* but for the rest of these, counting races are ok */ -static ssize_t zcache_flush_total; -static ssize_t zcache_flush_found; -static ssize_t zcache_flobj_total; -static ssize_t zcache_flobj_found; -static ssize_t zcache_failed_eph_puts; -static ssize_t zcache_failed_pers_puts; -static ssize_t zcache_failed_getfreepages; -static ssize_t zcache_failed_alloc; -static ssize_t zcache_put_to_flush; -static ssize_t zcache_compress_poor; -static ssize_t zcache_mean_compress_poor; -static ssize_t zcache_eph_ate_tail; -static ssize_t zcache_eph_ate_tail_failed; -static ssize_t zcache_pers_ate_eph; -static ssize_t zcache_pers_ate_eph_failed; -static ssize_t zcache_evicted_eph_zpages; -static ssize_t zcache_evicted_eph_pageframes; +extern ssize_t zcache_flush_total; +extern ssize_t zcache_flush_found; +extern ssize_t zcache_flobj_total; +extern ssize_t zcache_flobj_found; +extern ssize_t zcache_failed_eph_puts; +extern ssize_t zcache_failed_pers_puts; +extern ssize_t zcache_failed_getfreepages; +extern ssize_t zcache_failed_alloc; +extern ssize_t zcache_put_to_flush; +extern ssize_t zcache_compress_poor; +extern ssize_t zcache_mean_compress_poor; +extern ssize_t zcache_eph_ate_tail; +extern ssize_t zcache_eph_ate_tail_failed; +extern ssize_t zcache_pers_ate_eph; +extern ssize_t zcache_pers_ate_eph_failed; +extern ssize_t zcache_evicted_eph_zpages; +extern ssize_t zcache_evicted_eph_pageframes; extern ssize_t zcache_last_active_file_pageframes; extern ssize_t zcache_last_inactive_file_pageframes; diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index 892e97e..d1118f0 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -145,6 +145,37 @@ ssize_t zcache_pers_zpages; u64 zcache_pers_zbytes; ssize_t zcache_eph_pageframes; ssize_t zcache_pers_pageframes; +ssize_t zcache_obj_count; +ssize_t zcache_obj_count_max; +ssize_t zcache_objnode_count; +ssize_t zcache_objnode_count_max; +u64 zcache_eph_zbytes; +u64 zcache_eph_zbytes_max; +u64 zcache_pers_zbytes_max; +ssize_t zcache_eph_pageframes_max; +ssize_t zcache_pers_pageframes_max; +ssize_t zcache_pageframes_alloced; +ssize_t zcache_pageframes_freed; +ssize_t zcache_eph_zpages; +ssize_t zcache_eph_zpages_max; +ssize_t zcache_pers_zpages_max; +ssize_t zcache_flush_total; +ssize_t zcache_flush_found; +ssize_t zcache_flobj_total; +ssize_t zcache_flobj_found; +ssize_t zcache_failed_eph_puts; +ssize_t zcache_failed_pers_puts; +ssize_t zcache_failed_getfreepages; +ssize_t zcache_failed_alloc; +ssize_t zcache_put_to_flush; +ssize_t zcache_compress_poor; +ssize_t zcache_mean_compress_poor; +ssize_t zcache_eph_ate_tail; +ssize_t zcache_eph_ate_tail_failed; +ssize_t zcache_pers_ate_eph; +ssize_t zcache_pers_ate_eph_failed; +ssize_t zcache_evicted_eph_zpages; +ssize_t zcache_evicted_eph_pageframes; /* Used by this code. */ ssize_t zcache_last_active_file_pageframes; -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964969Ab3CSJ0h (ORCPT ); Tue, 19 Mar 2013 05:26:37 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:60226 "EHLO e28smtp01.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932884Ab3CSJ0b (ORCPT ); Tue, 19 Mar 2013 05:26:31 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 8/8] staging: zcache: clean TODO list Date: Tue, 19 Mar 2013 17:25:50 +0800 Message-Id: <1363685150-18303-9-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031909-4790-0000-0000-00000773F026 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cleanup TODO list since support zero-filled pages more efficiently has already done by this patchset. Acked-by: Dan Magenheimer Signed-off-by: Wanpeng Li --- drivers/staging/zcache/TODO | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/drivers/staging/zcache/TODO b/drivers/staging/zcache/TODO index ec9aa11..d0c18fa 100644 --- a/drivers/staging/zcache/TODO +++ b/drivers/staging/zcache/TODO @@ -61,5 +61,4 @@ ZCACHE FUTURE NEW FUNCTIONALITY A. Support zsmalloc as an alternative high-density allocator (See https://lkml.org/lkml/2013/1/23/511) -B. Support zero-filled pages more efficiently -C. Possibly support three zbuds per pageframe when space allows +B. Possibly support three zbuds per pageframe when space allows -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965116Ab3CSJ0p (ORCPT ); Tue, 19 Mar 2013 05:26:45 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:52939 "EHLO e23smtp06.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932884Ab3CSJ0l (ORCPT ); Tue, 19 Mar 2013 05:26:41 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 5/8] staging: zcache: fix zcache writeback in debugfs Date: Tue, 19 Mar 2013 17:25:47 +0800 Message-Id: <1363685150-18303-6-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031909-7014-0000-0000-000002BBE464 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 9c0ad59ef ("zcache/debug: Use an array to initialize/use debugfs attributes") use an array to initialize/use debugfs attributes, .name = #x, .val = &zcache_##x. For zcache writeback, this commit set .name = zcache_outstanding_writeback_pages and .name = zcache_writtenback_pages seperately, however, corresponding .val = &zcache_zcache_outstanding_writeback_pages and .val = &zcache_zcache_writtenback_pages, which are not correct. Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/zcache/debug.c b/drivers/staging/zcache/debug.c index 254dada..d2d1fdf 100644 --- a/drivers/staging/zcache/debug.c +++ b/drivers/staging/zcache/debug.c @@ -31,8 +31,8 @@ static struct debug_entry { ATTR(eph_nonactive_puts_ignored), ATTR(pers_nonactive_puts_ignored), #ifdef CONFIG_ZCACHE_WRITEBACK - ATTR(zcache_outstanding_writeback_pages), - ATTR(zcache_writtenback_pages), + ATTR(outstanding_writeback_pages), + ATTR(writtenback_pages), #endif }; #undef ATTR -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757884Ab3CSJ0w (ORCPT ); Tue, 19 Mar 2013 05:26:52 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:53796 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932884Ab3CSJ0s (ORCPT ); Tue, 19 Mar 2013 05:26:48 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 7/8] staging: zcache: introduce zero-filled page stat count Date: Tue, 19 Mar 2013 17:25:49 +0800 Message-Id: <1363685150-18303-8-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> x-cbid: 13031909-3568-0000-0000-0000034F3AB9 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce zero-filled page statistics to monitor the number of zero-filled pages. Acked-by: Dan Magenheimer Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.h | 15 +++++++++++++++ drivers/staging/zcache/zcache-main.c | 5 +++++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/drivers/staging/zcache/debug.h b/drivers/staging/zcache/debug.h index 8ec82d4..178bf75 100644 --- a/drivers/staging/zcache/debug.h +++ b/drivers/staging/zcache/debug.h @@ -122,6 +122,21 @@ static inline void dec_zcache_pers_zpages(unsigned zpages) zcache_pers_zpages = atomic_sub_return(zpages, &zcache_pers_zpages_atomic); } +extern ssize_t zcache_zero_filled_pages; +static atomic_t zcache_zero_filled_pages_atomic = ATOMIC_INIT(0); +extern ssize_t zcache_zero_filled_pages_max; +static inline void inc_zcache_zero_filled_pages(void) +{ + zcache_zero_filled_pages = atomic_inc_return( + &zcache_zero_filled_pages_atomic); + if (zcache_zero_filled_pages > zcache_zero_filled_pages_max) + zcache_zero_filled_pages_max = zcache_zero_filled_pages; +} +static inline void dec_zcache_zero_filled_pages(void) +{ + zcache_zero_filled_pages = atomic_dec_return( + &zcache_zero_filled_pages_atomic); +} static inline unsigned long curr_pageframes_count(void) { return zcache_pageframes_alloced - diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c index d1118f0..f8ba619 100644 --- a/drivers/staging/zcache/zcache-main.c +++ b/drivers/staging/zcache/zcache-main.c @@ -176,6 +176,8 @@ ssize_t zcache_pers_ate_eph; ssize_t zcache_pers_ate_eph_failed; ssize_t zcache_evicted_eph_zpages; ssize_t zcache_evicted_eph_pageframes; +ssize_t zcache_zero_filled_pages; +ssize_t zcache_zero_filled_pages_max; /* Used by this code. */ ssize_t zcache_last_active_file_pageframes; @@ -404,6 +406,7 @@ static void *zcache_pampd_eph_create(char *data, size_t size, bool raw, if (page_is_zero_filled(page)) { clen = 0; zero_filled = true; + inc_zcache_zero_filled_pages(); goto got_pampd; } @@ -470,6 +473,7 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw, if (page_is_zero_filled(page)) { clen = 0; zero_filled = true; + inc_zcache_zero_filled_pages(); goto got_pampd; } @@ -682,6 +686,7 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw, zpages = 1; if (!raw) *sizep = PAGE_SIZE; + dec_zcache_zero_filled_pages(); goto zero_fill; } -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757921Ab3CSJ1g (ORCPT ); Tue, 19 Mar 2013 05:27:36 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:37829 "EHLO e23smtp08.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965004Ab3CSJ0n (ORCPT ); Tue, 19 Mar 2013 05:26:43 -0400 From: Wanpeng Li To: Greg Kroah-Hartman Cc: Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wanpeng Li Subject: [PATCH v4 4/8] staging: zcache: fix pers_pageframes|_max aren't exported in debugfs Date: Tue, 19 Mar 2013 17:25:46 +0800 Message-Id: <1363685150-18303-5-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> x-cbid: 13031909-5140-0000-0000-000002E963BD Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before commit 9c0ad59ef ("zcache/debug: Use an array to initialize/use debugfs attributes"), pers_pageframes|_max are exported in debugfs, but this commit forgot use array export pers_pageframes|_max. This patch add pers_pageframes|_max back. Signed-off-by: Wanpeng Li --- drivers/staging/zcache/debug.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/drivers/staging/zcache/debug.c b/drivers/staging/zcache/debug.c index e951c64..254dada 100644 --- a/drivers/staging/zcache/debug.c +++ b/drivers/staging/zcache/debug.c @@ -21,6 +21,7 @@ static struct debug_entry { ATTR(pers_ate_eph), ATTR(pers_ate_eph_failed), ATTR(evicted_eph_zpages), ATTR(evicted_eph_pageframes), ATTR(eph_pageframes), ATTR(eph_pageframes_max), + ATTR(pers_pageframes), ATTR(pers_pageframes_max), ATTR(eph_zpages), ATTR(eph_zpages_max), ATTR(pers_zpages), ATTR(pers_zpages_max), ATTR(last_active_file_pageframes), -- 1.7.7.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934388Ab3CSXeK (ORCPT ); Tue, 19 Mar 2013 19:34:10 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:58934 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755311Ab3CSXeI (ORCPT ); Tue, 19 Mar 2013 19:34:08 -0400 Message-ID: <5148F5EA.3020904@gmail.com> Date: Wed, 20 Mar 2013 07:34:02 +0800 From: Ric Mason User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: Wanpeng Li CC: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 0/8] staging: zcache: Support zero-filled pages more efficiently References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/19/2013 05:25 PM, Wanpeng Li wrote: > Hi Greg, > > Since you have already merge 1/8, feel free to merge 2/8~8/8, I have already > rebased against staging-next. > > Changelog: > v3 -> v4: > * handle duplication in page_is_zero_filled, spotted by Bob > * fix zcache writeback in dubugfs > * fix pers_pageframes|_max isn't exported in debugfs > * fix static variable defined in debug.h but used in multiple C files > * rebase on Greg's staging-next > v2 -> v3: > * increment/decrement zcache_[eph|pers]_zpages for zero-filled pages, spotted by Dan > * replace "zero" or "zero page" by "zero_filled_page", spotted by Dan > v1 -> v2: > * avoid changing tmem.[ch] entirely, spotted by Dan. > * don't accumulate [eph|pers]pageframe and [eph|pers]zpages for > zero-filled pages, spotted by Dan > * cleanup TODO list > * add Dan Acked-by. > > Motivation: > > - Seth Jennings points out compress zero-filled pages with LZO(a lossless > data compression algorithm) will waste memory and result in fragmentation. > https://lkml.org/lkml/2012/8/14/347 > - Dan Magenheimer add "Support zero-filled pages more efficiently" feature > in zcache TODO list https://lkml.org/lkml/2013/2/13/503 > > Design: > > - For store page, capture zero-filled pages(evicted clean page cache pages and > swap pages), but don't compress them, set pampd which store zpage address to > 0x2(since 0x0 and 0x1 has already been ocuppied) to mark special zero-filled > case and take advantage of tmem infrastructure to transform handle-tuple(pool > id, object id, and an index) to a pampd. Twice compress zero-filled pages will > contribute to one zcache_[eph|pers]_pageframes count accumulated. > - For load page, traverse tmem hierachical to transform handle-tuple to pampd > and identify zero-filled case by pampd equal to 0x2 when filesystem reads > file pages or a page needs to be swapped in, then refill the page to zero > and return. > > Test: > > dd if=/dev/zero of=zerofile bs=1MB count=500 > vmtouch -t zerofile > vmtouch -e zerofile > > formula: > - fragmentation level = (zcache_[eph|pers]_pageframes * PAGE_SIZE - zcache_[eph|pers]_zbytes) > * 100 / (zcache_[eph|pers]_pageframes * PAGE_SIZE) > - memory zcache occupy = zcache_[eph|pers]_zbytes > > Result: > > without zero-filled awareness: > - fragmentation level: 98% > - memory zcache occupy: 238MB > with zero-filled awareness: > - fragmentation level: 0% > - memory zcache occupy: 0MB > > Wanpeng Li (8): > introduce zero filled pages handler > zero-filled pages awareness > handle zcache_[eph|pers]_pages for zero-filled page > fix pers_pageframes|_max aren't exported in debugfs > fix zcache writeback in debugfs > fix static variables are defined in debug.h but use in multiple C files > introduce zero-filled page stat count > clean TODO list You can add Reviewed-by: Ric Mason to this patchset. > > drivers/staging/zcache/TODO | 3 +- > drivers/staging/zcache/debug.c | 5 +- > drivers/staging/zcache/debug.h | 77 +++++++++++++--------- > drivers/staging/zcache/zcache-main.c | 147 ++++++++++++++++++++++++++++++---- > 4 files changed, 185 insertions(+), 47 deletions(-) > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754127Ab3CTKbD (ORCPT ); Wed, 20 Mar 2013 06:31:03 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:43954 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750835Ab3CTKbC (ORCPT ); Wed, 20 Mar 2013 06:31:02 -0400 Message-ID: <51498FCE.60603@oracle.com> Date: Wed, 20 Mar 2013 18:30:38 +0800 From: Bob Liu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: Wanpeng Li CC: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/8] staging: zcache: zero-filled pages awareness References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> In-Reply-To: <1363685150-18303-3-git-send-email-liwanp@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > @@ -641,16 +691,22 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, > { > struct page *page = NULL; > unsigned int zsize, zpages; > + bool zero_filled = false; > > BUG_ON(preemptible()); > - if (pampd_is_remote(pampd)) { > + > + if (pampd == (void *)ZERO_FILLED) > + zero_filled = true; > + > + if (pampd_is_remote(pampd) && !zero_filled) { > BUG_ON(!ramster_enabled); > pampd = ramster_pampd_free(pampd, pool, oid, index, acct); > if (pampd == NULL) > return; > } > if (is_ephemeral(pool)) { > - page = zbud_free_and_delist((struct zbudref *)pampd, > + if (!zero_filled) > + page = zbud_free_and_delist((struct zbudref *)pampd, > true, &zsize, &zpages); This check should also apply for !is_ephemeral(pool). > if (page) > dec_zcache_eph_pageframes(); > @@ -667,7 +723,7 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, > } > if (!is_local_client(pool->client)) > ramster_count_foreign_pages(is_ephemeral(pool), -1); > - if (page) > + if (page && !zero_filled) > zcache_free_page(page); > } > > -- Regards, -Bob From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751967Ab3CWTbN (ORCPT ); Sat, 23 Mar 2013 15:31:13 -0400 Received: from mail-ia0-f169.google.com ([209.85.210.169]:35680 "EHLO mail-ia0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751703Ab3CWTbM (ORCPT ); Sat, 23 Mar 2013 15:31:12 -0400 MIME-Version: 1.0 In-Reply-To: <1363685150-18303-2-git-send-email-liwanp@linux.vnet.ibm.com> References: <1363685150-18303-1-git-send-email-liwanp@linux.vnet.ibm.com> <1363685150-18303-2-git-send-email-liwanp@linux.vnet.ibm.com> Date: Sat, 23 Mar 2013 20:31:11 +0100 X-Google-Sender-Auth: 31Zho1S_09P_q-hQYA-9R7rUw64 Message-ID: Subject: Re: [PATCH v4 1/8] staging: zcache: introduce zero-filled pages handler From: Geert Uytterhoeven To: Wanpeng Li Cc: Greg Kroah-Hartman , Andrew Morton , Dan Magenheimer , Seth Jennings , Konrad Rzeszutek Wilk , Minchan Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Linux-Next Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 19, 2013 at 10:25 AM, Wanpeng Li wrote: > Introduce zero-filled pages handler to capture and handle zero pages. > > Acked-by: Dan Magenheimer > Signed-off-by: Wanpeng Li > --- > drivers/staging/zcache/zcache-main.c | 26 ++++++++++++++++++++++++++ > 1 files changed, 26 insertions(+), 0 deletions(-) > > diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c > index 328898e..d73dd4b 100644 > --- a/drivers/staging/zcache/zcache-main.c > +++ b/drivers/staging/zcache/zcache-main.c > +static void handle_zero_filled_page(void *page) > +{ > + void *user_mem; > + > + user_mem = kmap_atomic(page); kmap_atomic() takes a "struct page *", not a "void *". > + memset(user_mem, 0, PAGE_SIZE); > + kunmap_atomic(user_mem); > + > + flush_dcache_page(page); While flush_dcache_page() is a no-op on many architectures, it also takes a "struct page *", not a "void *": m68k/allmodconfig: drivers/staging/zcache/zcache-main.c:309:2: error: request for member 'virtual' in something not a structure or union Cfr. http://kisskb.ellerman.id.au/kisskb/buildresult/8433711/ > +} Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds