Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1355643 > unrolled thread

[PATCH v1 09/19] zsmalloc: keep max_object in size_class

Started byMinchan Kim <minchan@kernel.org>
First post2016-03-11 08:40 +0100
Last post2016-03-15 07:50 +0100
Articles 5 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v1 09/19] zsmalloc: keep max_object in size_class Minchan Kim <minchan@kernel.org> - 2016-03-11 08:40 +0100
    Re: [PATCH v1 09/19] zsmalloc: keep max_object in size_class xuyiping <xuyiping@hisilicon.com> - 2016-03-12 02:50 +0100
      Re: [PATCH v1 09/19] zsmalloc: keep max_object in size_class Minchan Kim <minchan@kernel.org> - 2016-03-14 06:00 +0100
    Re: [PATCH v1 09/19] zsmalloc: keep max_object in size_class Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-03-15 07:30 +0100
      Re: [PATCH v1 09/19] zsmalloc: keep max_object in size_class Minchan Kim <minchan@kernel.org> - 2016-03-15 07:50 +0100

#1355643 — [PATCH v1 09/19] zsmalloc: keep max_object in size_class

FromMinchan Kim <minchan@kernel.org>
Date2016-03-11 08:40 +0100
Subject[PATCH v1 09/19] zsmalloc: keep max_object in size_class
Message-ID<rbpPX-2Oc-11@gated-at.bofh.it>
Every zspage in a size_class has same number of max objects so
we could move it to a size_class.

Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 mm/zsmalloc.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index b4fb11831acb..ca663c82c1fc 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -32,8 +32,6 @@
  *	page->freelist: points to the first free object in zspage.
  *		Free objects are linked together using in-place
  *		metadata.
- *	page->objects: maximum number of objects we can store in this
- *		zspage (class->zspage_order * PAGE_SIZE / class->size)
  *	page->lru: links together first pages of various zspages.
  *		Basically forming list of zspages in a fullness group.
  *	page->mapping: class index and fullness group of the zspage
@@ -211,6 +209,7 @@ struct size_class {
 	 * of ZS_ALIGN.
 	 */
 	int size;
+	int objs_per_zspage;
 	unsigned int index;
 
 	struct zs_size_stat stats;
@@ -622,21 +621,22 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)
  * the pool (not yet implemented). This function returns fullness
  * status of the given page.
  */
-static enum fullness_group get_fullness_group(struct page *first_page)
+static enum fullness_group get_fullness_group(struct size_class *class,
+						struct page *first_page)
 {
-	int inuse, max_objects;
+	int inuse, objs_per_zspage;
 	enum fullness_group fg;
 
 	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
 
 	inuse = first_page->inuse;
-	max_objects = first_page->objects;
+	objs_per_zspage = class->objs_per_zspage;
 
 	if (inuse == 0)
 		fg = ZS_EMPTY;
-	else if (inuse == max_objects)
+	else if (inuse == objs_per_zspage)
 		fg = ZS_FULL;
-	else if (inuse <= 3 * max_objects / fullness_threshold_frac)
+	else if (inuse <= 3 * objs_per_zspage / fullness_threshold_frac)
 		fg = ZS_ALMOST_EMPTY;
 	else
 		fg = ZS_ALMOST_FULL;
@@ -723,7 +723,7 @@ static enum fullness_group fix_fullness_group(struct size_class *class,
 	enum fullness_group currfg, newfg;
 
 	get_zspage_mapping(first_page, &class_idx, &currfg);
-	newfg = get_fullness_group(first_page);
+	newfg = get_fullness_group(class, first_page);
 	if (newfg == currfg)
 		goto out;
 
@@ -1003,9 +1003,6 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
 	init_zspage(class, first_page);
 
 	first_page->freelist = location_to_obj(first_page, 0);
-	/* Maximum number of objects we can store in this zspage */
-	first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
-
 	error = 0; /* Success */
 
 cleanup:
@@ -1235,11 +1232,11 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)
 	return true;
 }
 
-static bool zspage_full(struct page *first_page)
+static bool zspage_full(struct size_class *class, struct page *first_page)
 {
 	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
 
-	return first_page->inuse == first_page->objects;
+	return first_page->inuse == class->objs_per_zspage;
 }
 
 unsigned long zs_get_total_pages(struct zs_pool *pool)
@@ -1625,7 +1622,7 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
 		}
 
 		/* Stop if there is no more space */
-		if (zspage_full(d_page)) {
+		if (zspage_full(class, d_page)) {
 			unpin_tag(handle);
 			ret = -ENOMEM;
 			break;
@@ -1684,7 +1681,7 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,
 {
 	enum fullness_group fullness;
 
-	fullness = get_fullness_group(first_page);
+	fullness = get_fullness_group(class, first_page);
 	insert_zspage(class, fullness, first_page);
 	set_zspage_mapping(first_page, class->index, fullness);
 
@@ -1933,6 +1930,8 @@ struct zs_pool *zs_create_pool(const char *name, gfp_t flags)
 		class->size = size;
 		class->index = i;
 		class->pages_per_zspage = pages_per_zspage;
+		class->objs_per_zspage = class->pages_per_zspage *
+						PAGE_SIZE / class->size;
 		if (pages_per_zspage == 1 &&
 			get_maxobj_per_zspage(size, pages_per_zspage) == 1)
 			class->huge = true;
-- 
1.9.1

[toc] | [next] | [standalone]


#1356321

Fromxuyiping <xuyiping@hisilicon.com>
Date2016-03-12 02:50 +0100
Message-ID<rbGQO-6UP-17@gated-at.bofh.it>
In reply to#1355643

On 2016/3/11 15:30, Minchan Kim wrote:
> Every zspage in a size_class has same number of max objects so
> we could move it to a size_class.
>
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
>   mm/zsmalloc.c | 29 ++++++++++++++---------------
>   1 file changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index b4fb11831acb..ca663c82c1fc 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -32,8 +32,6 @@
>    *	page->freelist: points to the first free object in zspage.
>    *		Free objects are linked together using in-place
>    *		metadata.
> - *	page->objects: maximum number of objects we can store in this
> - *		zspage (class->zspage_order * PAGE_SIZE / class->size)
>    *	page->lru: links together first pages of various zspages.
>    *		Basically forming list of zspages in a fullness group.
>    *	page->mapping: class index and fullness group of the zspage
> @@ -211,6 +209,7 @@ struct size_class {
>   	 * of ZS_ALIGN.
>   	 */
>   	int size;
> +	int objs_per_zspage;
>   	unsigned int index;
>
>   	struct zs_size_stat stats;
> @@ -622,21 +621,22 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)
>    * the pool (not yet implemented). This function returns fullness
>    * status of the given page.
>    */
> -static enum fullness_group get_fullness_group(struct page *first_page)
> +static enum fullness_group get_fullness_group(struct size_class *class,
> +						struct page *first_page)
>   {
> -	int inuse, max_objects;
> +	int inuse, objs_per_zspage;
>   	enum fullness_group fg;
>
>   	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
>
>   	inuse = first_page->inuse;
> -	max_objects = first_page->objects;
> +	objs_per_zspage = class->objs_per_zspage;
>
>   	if (inuse == 0)
>   		fg = ZS_EMPTY;
> -	else if (inuse == max_objects)
> +	else if (inuse == objs_per_zspage)
>   		fg = ZS_FULL;
> -	else if (inuse <= 3 * max_objects / fullness_threshold_frac)
> +	else if (inuse <= 3 * objs_per_zspage / fullness_threshold_frac)
>   		fg = ZS_ALMOST_EMPTY;
>   	else
>   		fg = ZS_ALMOST_FULL;
> @@ -723,7 +723,7 @@ static enum fullness_group fix_fullness_group(struct size_class *class,
>   	enum fullness_group currfg, newfg;
>
>   	get_zspage_mapping(first_page, &class_idx, &currfg);
> -	newfg = get_fullness_group(first_page);
> +	newfg = get_fullness_group(class, first_page);
>   	if (newfg == currfg)
>   		goto out;
>
> @@ -1003,9 +1003,6 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
>   	init_zspage(class, first_page);
>
>   	first_page->freelist = location_to_obj(first_page, 0);
> -	/* Maximum number of objects we can store in this zspage */
> -	first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
> -
>   	error = 0; /* Success */
>
>   cleanup:
> @@ -1235,11 +1232,11 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)
>   	return true;
>   }
>
> -static bool zspage_full(struct page *first_page)
> +static bool zspage_full(struct size_class *class, struct page *first_page)
>   {
>   	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
>
> -	return first_page->inuse == first_page->objects;
> +	return first_page->inuse == class->objs_per_zspage;
>   }
>
>   unsigned long zs_get_total_pages(struct zs_pool *pool)
> @@ -1625,7 +1622,7 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
>   		}
>
>   		/* Stop if there is no more space */
> -		if (zspage_full(d_page)) {
> +		if (zspage_full(class, d_page)) {
>   			unpin_tag(handle);
>   			ret = -ENOMEM;
>   			break;
> @@ -1684,7 +1681,7 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,
>   {
>   	enum fullness_group fullness;
>
> -	fullness = get_fullness_group(first_page);
> +	fullness = get_fullness_group(class, first_page);
>   	insert_zspage(class, fullness, first_page);
>   	set_zspage_mapping(first_page, class->index, fullness);
>
> @@ -1933,6 +1930,8 @@ struct zs_pool *zs_create_pool(const char *name, gfp_t flags)
>   		class->size = size;
>   		class->index = i;
>   		class->pages_per_zspage = pages_per_zspage;
> +		class->objs_per_zspage = class->pages_per_zspage *
> +						PAGE_SIZE / class->size;
>   		if (pages_per_zspage == 1 &&
>   			get_maxobj_per_zspage(size, pages_per_zspage) == 1)
>   			class->huge = true;

		computes the "objs_per_zspage" twice here.

		class->objs_per_zspage = get_maxobj_per_zspage(size,
						pages_per_zspage);
		if (pages_per_zspage == 1 && class->objs_per_zspage ==1)
			class->huge = true;

>

[toc] | [prev] | [next] | [standalone]


#1356926

FromMinchan Kim <minchan@kernel.org>
Date2016-03-14 06:00 +0100
Message-ID<rcsLM-7m7-3@gated-at.bofh.it>
In reply to#1356321
On Sat, Mar 12, 2016 at 09:44:48AM +0800, xuyiping wrote:
> 
> 
> On 2016/3/11 15:30, Minchan Kim wrote:
> >Every zspage in a size_class has same number of max objects so
> >we could move it to a size_class.
> >
> >Signed-off-by: Minchan Kim <minchan@kernel.org>
> >---
> >  mm/zsmalloc.c | 29 ++++++++++++++---------------
> >  1 file changed, 14 insertions(+), 15 deletions(-)
> >
> >diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> >index b4fb11831acb..ca663c82c1fc 100644
> >--- a/mm/zsmalloc.c
> >+++ b/mm/zsmalloc.c
> >@@ -32,8 +32,6 @@
> >   *	page->freelist: points to the first free object in zspage.
> >   *		Free objects are linked together using in-place
> >   *		metadata.
> >- *	page->objects: maximum number of objects we can store in this
> >- *		zspage (class->zspage_order * PAGE_SIZE / class->size)
> >   *	page->lru: links together first pages of various zspages.
> >   *		Basically forming list of zspages in a fullness group.
> >   *	page->mapping: class index and fullness group of the zspage
> >@@ -211,6 +209,7 @@ struct size_class {
> >  	 * of ZS_ALIGN.
> >  	 */
> >  	int size;
> >+	int objs_per_zspage;
> >  	unsigned int index;
> >
> >  	struct zs_size_stat stats;
> >@@ -622,21 +621,22 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)
> >   * the pool (not yet implemented). This function returns fullness
> >   * status of the given page.
> >   */
> >-static enum fullness_group get_fullness_group(struct page *first_page)
> >+static enum fullness_group get_fullness_group(struct size_class *class,
> >+						struct page *first_page)
> >  {
> >-	int inuse, max_objects;
> >+	int inuse, objs_per_zspage;
> >  	enum fullness_group fg;
> >
> >  	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
> >
> >  	inuse = first_page->inuse;
> >-	max_objects = first_page->objects;
> >+	objs_per_zspage = class->objs_per_zspage;
> >
> >  	if (inuse == 0)
> >  		fg = ZS_EMPTY;
> >-	else if (inuse == max_objects)
> >+	else if (inuse == objs_per_zspage)
> >  		fg = ZS_FULL;
> >-	else if (inuse <= 3 * max_objects / fullness_threshold_frac)
> >+	else if (inuse <= 3 * objs_per_zspage / fullness_threshold_frac)
> >  		fg = ZS_ALMOST_EMPTY;
> >  	else
> >  		fg = ZS_ALMOST_FULL;
> >@@ -723,7 +723,7 @@ static enum fullness_group fix_fullness_group(struct size_class *class,
> >  	enum fullness_group currfg, newfg;
> >
> >  	get_zspage_mapping(first_page, &class_idx, &currfg);
> >-	newfg = get_fullness_group(first_page);
> >+	newfg = get_fullness_group(class, first_page);
> >  	if (newfg == currfg)
> >  		goto out;
> >
> >@@ -1003,9 +1003,6 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
> >  	init_zspage(class, first_page);
> >
> >  	first_page->freelist = location_to_obj(first_page, 0);
> >-	/* Maximum number of objects we can store in this zspage */
> >-	first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
> >-
> >  	error = 0; /* Success */
> >
> >  cleanup:
> >@@ -1235,11 +1232,11 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)
> >  	return true;
> >  }
> >
> >-static bool zspage_full(struct page *first_page)
> >+static bool zspage_full(struct size_class *class, struct page *first_page)
> >  {
> >  	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
> >
> >-	return first_page->inuse == first_page->objects;
> >+	return first_page->inuse == class->objs_per_zspage;
> >  }
> >
> >  unsigned long zs_get_total_pages(struct zs_pool *pool)
> >@@ -1625,7 +1622,7 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
> >  		}
> >
> >  		/* Stop if there is no more space */
> >-		if (zspage_full(d_page)) {
> >+		if (zspage_full(class, d_page)) {
> >  			unpin_tag(handle);
> >  			ret = -ENOMEM;
> >  			break;
> >@@ -1684,7 +1681,7 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,
> >  {
> >  	enum fullness_group fullness;
> >
> >-	fullness = get_fullness_group(first_page);
> >+	fullness = get_fullness_group(class, first_page);
> >  	insert_zspage(class, fullness, first_page);
> >  	set_zspage_mapping(first_page, class->index, fullness);
> >
> >@@ -1933,6 +1930,8 @@ struct zs_pool *zs_create_pool(const char *name, gfp_t flags)
> >  		class->size = size;
> >  		class->index = i;
> >  		class->pages_per_zspage = pages_per_zspage;
> >+		class->objs_per_zspage = class->pages_per_zspage *
> >+						PAGE_SIZE / class->size;
> >  		if (pages_per_zspage == 1 &&
> >  			get_maxobj_per_zspage(size, pages_per_zspage) == 1)
> >  			class->huge = true;
> 
> 		computes the "objs_per_zspage" twice here.
> 
> 		class->objs_per_zspage = get_maxobj_per_zspage(size,
> 						pages_per_zspage);
> 		if (pages_per_zspage == 1 && class->objs_per_zspage ==1)
> 			class->huge = true;

Yeb. I will do.

Thanks.

[toc] | [prev] | [next] | [standalone]


#1357825

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2016-03-15 07:30 +0100
Message-ID<rcQEq-6J1-5@gated-at.bofh.it>
In reply to#1355643
On (03/11/16 16:30), Minchan Kim wrote:
> Every zspage in a size_class has same number of max objects so
> we could move it to a size_class.
> 
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
>  mm/zsmalloc.c | 29 ++++++++++++++---------------
>  1 file changed, 14 insertions(+), 15 deletions(-)
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index b4fb11831acb..ca663c82c1fc 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -32,8 +32,6 @@
>   *	page->freelist: points to the first free object in zspage.
>   *		Free objects are linked together using in-place
>   *		metadata.
> - *	page->objects: maximum number of objects we can store in this
> - *		zspage (class->zspage_order * PAGE_SIZE / class->size)
>   *	page->lru: links together first pages of various zspages.
>   *		Basically forming list of zspages in a fullness group.
>   *	page->mapping: class index and fullness group of the zspage
> @@ -211,6 +209,7 @@ struct size_class {
>  	 * of ZS_ALIGN.
>  	 */
>  	int size;
> +	int objs_per_zspage;
>  	unsigned int index;

struct page ->objects "comes for free". now we don't use it, instead
every size_class grows by 4 bytes? is there any reason for this?

	-ss

[toc] | [prev] | [next] | [standalone]


#1357828

FromMinchan Kim <minchan@kernel.org>
Date2016-03-15 07:50 +0100
Message-ID<rcQXM-6S7-5@gated-at.bofh.it>
In reply to#1357825
On Tue, Mar 15, 2016 at 03:28:24PM +0900, Sergey Senozhatsky wrote:
> On (03/11/16 16:30), Minchan Kim wrote:
> > Every zspage in a size_class has same number of max objects so
> > we could move it to a size_class.
> > 
> > Signed-off-by: Minchan Kim <minchan@kernel.org>
> > ---
> >  mm/zsmalloc.c | 29 ++++++++++++++---------------
> >  1 file changed, 14 insertions(+), 15 deletions(-)
> > 
> > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> > index b4fb11831acb..ca663c82c1fc 100644
> > --- a/mm/zsmalloc.c
> > +++ b/mm/zsmalloc.c
> > @@ -32,8 +32,6 @@
> >   *	page->freelist: points to the first free object in zspage.
> >   *		Free objects are linked together using in-place
> >   *		metadata.
> > - *	page->objects: maximum number of objects we can store in this
> > - *		zspage (class->zspage_order * PAGE_SIZE / class->size)
> >   *	page->lru: links together first pages of various zspages.
> >   *		Basically forming list of zspages in a fullness group.
> >   *	page->mapping: class index and fullness group of the zspage
> > @@ -211,6 +209,7 @@ struct size_class {
> >  	 * of ZS_ALIGN.
> >  	 */
> >  	int size;
> > +	int objs_per_zspage;
> >  	unsigned int index;
> 
> struct page ->objects "comes for free". now we don't use it, instead
> every size_class grows by 4 bytes? is there any reason for this?

It is union with _mapcount and it is used by checking non-lru movable
page in this patchset.
> 
> 	-ss

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web