Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752957AbcCUGa7 (ORCPT ); Mon, 21 Mar 2016 02:30:59 -0400 Received: from LGEAMRELO13.lge.com ([156.147.23.53]:37248 "EHLO lgeamrelo13.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbcCUGaK (ORCPT ); Mon, 21 Mar 2016 02:30:10 -0400 X-Original-SENDERIP: 156.147.1.127 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 10.177.223.161 X-Original-MAILFROM: minchan@kernel.org From: Minchan Kim To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jlayton@poochiereds.net, bfields@fieldses.org, Vlastimil Babka , Joonsoo Kim , koct9i@gmail.com, aquini@redhat.com, virtualization@lists.linux-foundation.org, Mel Gorman , Hugh Dickins , Sergey Senozhatsky , Rik van Riel , rknize@motorola.com, Gioh Kim , Sangseok Lee , Chan Gyun Jeong , Al Viro , YiPing Xu , Minchan Kim Subject: [PATCH v2 06/18] zsmalloc: keep max_object in size_class Date: Mon, 21 Mar 2016 15:30:55 +0900 Message-Id: <1458541867-27380-7-git-send-email-minchan@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458541867-27380-1-git-send-email-minchan@kernel.org> References: <1458541867-27380-1-git-send-email-minchan@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4178 Lines: 122 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 --- mm/zsmalloc.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index a0890e9003e2..8649d0243e6c 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; @@ -627,21 +626,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; @@ -728,7 +728,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; @@ -1008,9 +1008,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: @@ -1238,11 +1235,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) @@ -1628,7 +1625,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; @@ -1687,7 +1684,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); @@ -1936,8 +1933,9 @@ 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; - if (pages_per_zspage == 1 && - get_maxobj_per_zspage(size, pages_per_zspage) == 1) + class->objs_per_zspage = class->pages_per_zspage * + PAGE_SIZE / class->size; + if (pages_per_zspage == 1 && class->objs_per_zspage == 1) class->huge = true; spin_lock_init(&class->lock); pool->size_class[i] = class; -- 1.9.1