On Mon, Jul 04, 2016 at 09:03:18AM +0900, Minchan Kim wrote: > On Fri, Jul 01, 2016 at 02:41:03PM +0800, Ganesh Mahendran wrote: > > Currently, if a class can not be merged, the max objects of zspage > > in that class may be calculated twice. > > > > This patch calculate max objects of zspage at the begin, and pass > > the value to can_merge() to decide whether the class can be merged. > > > > Signed-off-by: Ganesh Mahendran <opensource.ganesh@xxxxxxxxx> > > --- > > mm/zsmalloc.c | 21 ++++++++++----------- > > 1 file changed, 10 insertions(+), 11 deletions(-) > > > > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > > index 50283b1..2690914 100644 > > --- a/mm/zsmalloc.c > > +++ b/mm/zsmalloc.c > > @@ -1362,16 +1362,14 @@ static void init_zs_size_classes(void) > > zs_size_classes = nr; > > } > > > > -static bool can_merge(struct size_class *prev, int size, int pages_per_zspage) > > +static bool can_merge(struct size_class *prev, int pages_per_zspage, > > + int objs_per_zspage) > > { > > - if (prev->pages_per_zspage != pages_per_zspage) > > - return false; > > - > > - if (prev->objs_per_zspage > > - != get_maxobj_per_zspage(size, pages_per_zspage)) > > - return false; > > + if (prev->pages_per_zspage == pages_per_zspage && > > + prev->objs_per_zspage == objs_per_zspage) > > + return true; > > > > - return true; > > + return false; > > } > > > > static bool zspage_full(struct size_class *class, struct zspage *zspage) > > @@ -2460,6 +2458,7 @@ struct zs_pool *zs_create_pool(const char *name) > > for (i = zs_size_classes - 1; i >= 0; i--) { > > int size; > > int pages_per_zspage; > > + int objs_per_zspage; > > struct size_class *class; > > int fullness = 0; > > > > @@ -2467,6 +2466,7 @@ struct zs_pool *zs_create_pool(const char *name) > > if (size > ZS_MAX_ALLOC_SIZE) > > size = ZS_MAX_ALLOC_SIZE; > > pages_per_zspage = get_pages_per_zspage(size); > > + objs_per_zspage = get_maxobj_per_zspage(size, pages_per_zspage); > > So, user of get_maxobj_per_zspage is only here? If so, let's remove > get_maxobj_per_zspage to prevent misuse in future. Instead, use open code > here. Yes, get_maxobj_per_zspage is only called here. I will remove it in V2. Thanks. > > > > > > /* > > * size_class is used for normal zsmalloc operation such > > @@ -2478,7 +2478,7 @@ struct zs_pool *zs_create_pool(const char *name) > > * previous size_class if possible. > > */ > > if (prev_class) { > > - if (can_merge(prev_class, size, pages_per_zspage)) { > > + if (can_merge(prev_class, pages_per_zspage, objs_per_zspage)) { > > pool->size_class[i] = prev_class; > > continue; > > } > > @@ -2491,8 +2491,7 @@ struct zs_pool *zs_create_pool(const char *name) > > class->size = size; > > class->index = i; > > class->pages_per_zspage = pages_per_zspage; > > - class->objs_per_zspage = get_maxobj_per_zspage(class->size, > > - class->pages_per_zspage); > > + class->objs_per_zspage = objs_per_zspage; > > spin_lock_init(&class->lock); > > pool->size_class[i] = class; > > for (fullness = ZS_EMPTY; fullness < NR_ZS_FULLNESS; > > -- > > 1.9.1 > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>