* mm/zsmalloc.c: count in handle's size when calculating pages_per_zspage
@ 2015-03-19 11:39 Yinghao Xie
2015-03-20 4:55 ` Minchan Kim
2015-03-20 5:55 ` Sergey Senozhatsky
0 siblings, 2 replies; 3+ messages in thread
From: Yinghao Xie @ 2015-03-19 11:39 UTC (permalink / raw)
To: Andrew Morton; +Cc: Minchan Kim, Nitin Gupta, mm, lkml
From 159d74b5a8f3d0f07e18ddad74b7025cf17dcc69 Mon Sep 17 00:00:00 2001
From: Yinghao Xie <yinghao.xie@sumsung.com>
Date: Thu, 19 Mar 2015 19:32:25 +0800
Subject: [PATCH] mm/zsmalloc.c: count in handle's size when calculating
size_class's pages_per_zspage
1. Fix wastage calculation;
2. Indirect handle introduced extra ZS_HANDLE_SIZE size for each object,it's transparent
for upper function, but a size_class's total objects will changed:
take the 43rd class which class_size = 32 + 43 * 16 = 720 as example:
4096 * 1 % 720 = 496
4096 * 2 % 720 = 272
4096 * 3 % 720 = 48
4096 * 4 %720 = 544
after handle introduced,class_size + ZS_HANDLE_SIZE (4 on 32bit) = 724
4096 * 1 % 724 = 476
4096 * 2 % 724 = 228
4096 * 3 % 724 = 704
4096 * 4 % 724 = 456
Clearly, ZS_HANDLE_SIZE should be considered when calculating pages_per_zspage;
3. in get_size_class_index(), min(zs_size_classes - 1, idx) insures a huge class's
index <= zs_size_classes - 1, so it's no need to check again;
Signed-off-by: Yinghao Xie <yinghao.xie@sumsung.com>
---
mm/zsmalloc.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 461243e..64c379b 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -760,7 +760,8 @@ out:
* to form a zspage for each size class. This is important
* to reduce wastage due to unusable space left at end of
* each zspage which is given as:
- * wastage = Zp - Zp % size_class
+ * wastage = Zp % (class_size + ZS_HANDLE_SIZE)
+ * usage = Zp - wastage
* where Zp = zspage size = k * PAGE_SIZE where k = 1, 2, ...
*
* For example, for size class of 3/8 * PAGE_SIZE, we should
@@ -773,6 +774,9 @@ static int get_pages_per_zspage(int class_size)
/* zspage order which gives maximum used size per KB */
int max_usedpc_order = 1;
+ if (class_size > ZS_MAX_ALLOC_SIZE)
+ class_size = ZS_MAX_ALLOC_SIZE;
+
for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
int zspage_size;
int waste, usedpc;
@@ -1426,11 +1430,6 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size)
/* extra space in chunk to keep the handle */
size += ZS_HANDLE_SIZE;
class = pool->size_class[get_size_class_index(size)];
- /* In huge class size, we store the handle into first_page->private */
- if (class->huge) {
- size -= ZS_HANDLE_SIZE;
- class = pool->size_class[get_size_class_index(size)];
- }
spin_lock(&class->lock);
first_page = find_get_zspage(class);
@@ -1856,9 +1855,7 @@ struct zs_pool *zs_create_pool(char *name, gfp_t flags)
struct size_class *class;
size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
- if (size > ZS_MAX_ALLOC_SIZE)
- size = ZS_MAX_ALLOC_SIZE;
- pages_per_zspage = get_pages_per_zspage(size);
+ pages_per_zspage = get_pages_per_zspage(size + ZS_HANDLE_SIZE);
/*
* size_class is used for normal zsmalloc operation such
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: mm/zsmalloc.c: count in handle's size when calculating pages_per_zspage
2015-03-19 11:39 mm/zsmalloc.c: count in handle's size when calculating pages_per_zspage Yinghao Xie
@ 2015-03-20 4:55 ` Minchan Kim
2015-03-20 5:55 ` Sergey Senozhatsky
1 sibling, 0 replies; 3+ messages in thread
From: Minchan Kim @ 2015-03-20 4:55 UTC (permalink / raw)
To: Yinghao Xie; +Cc: Andrew Morton, Nitin Gupta, mm, lkml
On Thu, Mar 19, 2015 at 11:39:20AM +0000, Yinghao Xie wrote:
> From 159d74b5a8f3d0f07e18ddad74b7025cf17dcc69 Mon Sep 17 00:00:00 2001
> From: Yinghao Xie <yinghao.xie@sumsung.com>
> Date: Thu, 19 Mar 2015 19:32:25 +0800
> Subject: [PATCH] mm/zsmalloc.c: count in handle's size when calculating
> size_class's pages_per_zspage
>
> 1. Fix wastage calculation;
> 2. Indirect handle introduced extra ZS_HANDLE_SIZE size for each object,it's transparent
> for upper function, but a size_class's total objects will changed:
> take the 43rd class which class_size = 32 + 43 * 16 = 720 as example:
> 4096 * 1 % 720 = 496
> 4096 * 2 % 720 = 272
> 4096 * 3 % 720 = 48
> 4096 * 4 %720 = 544
> after handle introduced,class_size + ZS_HANDLE_SIZE (4 on 32bit) = 724
> 4096 * 1 % 724 = 476
> 4096 * 2 % 724 = 228
> 4096 * 3 % 724 = 704
> 4096 * 4 % 724 = 456
> Clearly, ZS_HANDLE_SIZE should be considered when calculating pages_per_zspage;
Zsmalloc adds ZS_SIZE_HANDLE to size user passed before getting size_class so
we don't need to change size_class to calculate optimal pages for zspage.
>
> 3. in get_size_class_index(), min(zs_size_classes - 1, idx) insures a huge class's
> index <= zs_size_classes - 1, so it's no need to check again;
Sorry, I don't get it, either.
>
> Signed-off-by: Yinghao Xie <yinghao.xie@sumsung.com>
> ---
> mm/zsmalloc.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 461243e..64c379b 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -760,7 +760,8 @@ out:
> * to form a zspage for each size class. This is important
> * to reduce wastage due to unusable space left at end of
> * each zspage which is given as:
> - * wastage = Zp - Zp % size_class
> + * wastage = Zp % (class_size + ZS_HANDLE_SIZE)
> + * usage = Zp - wastage
> * where Zp = zspage size = k * PAGE_SIZE where k = 1, 2, ...
> *
> * For example, for size class of 3/8 * PAGE_SIZE, we should
> @@ -773,6 +774,9 @@ static int get_pages_per_zspage(int class_size)
> /* zspage order which gives maximum used size per KB */
> int max_usedpc_order = 1;
>
> + if (class_size > ZS_MAX_ALLOC_SIZE)
> + class_size = ZS_MAX_ALLOC_SIZE;
> +
> for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
> int zspage_size;
> int waste, usedpc;
> @@ -1426,11 +1430,6 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size)
> /* extra space in chunk to keep the handle */
> size += ZS_HANDLE_SIZE;
> class = pool->size_class[get_size_class_index(size)];
> - /* In huge class size, we store the handle into first_page->private */
> - if (class->huge) {
> - size -= ZS_HANDLE_SIZE;
> - class = pool->size_class[get_size_class_index(size)];
> - }
>
> spin_lock(&class->lock);
> first_page = find_get_zspage(class);
> @@ -1856,9 +1855,7 @@ struct zs_pool *zs_create_pool(char *name, gfp_t flags)
> struct size_class *class;
>
> size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
> - if (size > ZS_MAX_ALLOC_SIZE)
> - size = ZS_MAX_ALLOC_SIZE;
> - pages_per_zspage = get_pages_per_zspage(size);
> + pages_per_zspage = get_pages_per_zspage(size + ZS_HANDLE_SIZE);
>
> /*
> * size_class is used for normal zsmalloc operation such
> --
> 1.7.9.5
--
Kind regards,
Minchan Kim
--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: mm/zsmalloc.c: count in handle's size when calculating pages_per_zspage
2015-03-19 11:39 mm/zsmalloc.c: count in handle's size when calculating pages_per_zspage Yinghao Xie
2015-03-20 4:55 ` Minchan Kim
@ 2015-03-20 5:55 ` Sergey Senozhatsky
1 sibling, 0 replies; 3+ messages in thread
From: Sergey Senozhatsky @ 2015-03-20 5:55 UTC (permalink / raw)
To: Yinghao Xie
Cc: Andrew Morton, Minchan Kim, Nitin Gupta, mm, lkml, sergey.senozhatsky
Hello,
sorry, I've a question.
On (03/19/15 11:39), Yinghao Xie wrote:
> @@ -1426,11 +1430,6 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size)
> /* extra space in chunk to keep the handle */
> size += ZS_HANDLE_SIZE;
> class = pool->size_class[get_size_class_index(size)];
> - /* In huge class size, we store the handle into first_page->private */
> - if (class->huge) {
> - size -= ZS_HANDLE_SIZE;
> - class = pool->size_class[get_size_class_index(size)];
> - }
if huge class uses page->private to store a handle, shouldn't we pass
"size -= ZS_HANDLE_SIZE" to get_size_class_index() ?
-ss
> spin_lock(&class->lock);
> first_page = find_get_zspage(class);
> @@ -1856,9 +1855,7 @@ struct zs_pool *zs_create_pool(char *name, gfp_t flags)
> struct size_class *class;
>
> size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
> - if (size > ZS_MAX_ALLOC_SIZE)
> - size = ZS_MAX_ALLOC_SIZE;
> - pages_per_zspage = get_pages_per_zspage(size);
> + pages_per_zspage = get_pages_per_zspage(size + ZS_HANDLE_SIZE);
>
> /*
> * size_class is used for normal zsmalloc operation such
--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-20 5:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-19 11:39 mm/zsmalloc.c: count in handle's size when calculating pages_per_zspage Yinghao Xie
2015-03-20 4:55 ` Minchan Kim
2015-03-20 5:55 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).