Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964998AbcJVS3E (ORCPT ); Sat, 22 Oct 2016 14:29:04 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33939 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935899AbcJVS3C (ORCPT ); Sat, 22 Oct 2016 14:29:02 -0400 MIME-Version: 1.0 In-Reply-To: References: <20161019183340.9e3738b403ddda1a04c8f906@gmail.com> <20161019183506.d25ef094d89331b812eabc4f@gmail.com> From: Vitaly Wool Date: Sat, 22 Oct 2016 20:28:59 +0200 Message-ID: Subject: Re: [PATCH 1/3] z3fold: make counters atomic To: Dan Streetman Cc: Linux-MM , linux-kernel , Andrew Morton Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4042 Lines: 94 On Thu, Oct 20, 2016 at 10:17 PM, Dan Streetman wrote: > On Wed, Oct 19, 2016 at 12:35 PM, Vitaly Wool wrote: >> This patch converts pages_nr per-pool counter to atomic64_t. >> It also introduces a new counter, unbuddied_nr, which is >> atomic64_t, too, to track the number of unbuddied (compactable) >> z3fold pages. >> >> Signed-off-by: Vitaly Wool >> --- >> mm/z3fold.c | 33 +++++++++++++++++++++++++-------- >> 1 file changed, 25 insertions(+), 8 deletions(-) >> >> diff --git a/mm/z3fold.c b/mm/z3fold.c >> index 8f9e89c..5ac325a 100644 >> --- a/mm/z3fold.c >> +++ b/mm/z3fold.c >> @@ -69,6 +69,7 @@ struct z3fold_ops { >> * @lru: list tracking the z3fold pages in LRU order by most recently >> * added buddy. >> * @pages_nr: number of z3fold pages in the pool. >> + * @unbuddied_nr: number of unbuddied z3fold pages in the pool. >> * @ops: pointer to a structure of user defined operations specified at >> * pool creation time. >> * >> @@ -80,7 +81,8 @@ struct z3fold_pool { >> struct list_head unbuddied[NCHUNKS]; >> struct list_head buddied; >> struct list_head lru; >> - u64 pages_nr; >> + atomic64_t pages_nr; >> + atomic64_t unbuddied_nr; >> const struct z3fold_ops *ops; >> struct zpool *zpool; >> const struct zpool_ops *zpool_ops; >> @@ -234,7 +236,8 @@ static struct z3fold_pool *z3fold_create_pool(gfp_t gfp, >> INIT_LIST_HEAD(&pool->unbuddied[i]); >> INIT_LIST_HEAD(&pool->buddied); >> INIT_LIST_HEAD(&pool->lru); >> - pool->pages_nr = 0; >> + atomic64_set(&pool->pages_nr, 0); >> + atomic64_set(&pool->unbuddied_nr, 0); >> pool->ops = ops; >> return pool; >> } >> @@ -334,6 +337,7 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, >> continue; >> } >> list_del(&zhdr->buddy); >> + atomic64_dec(&pool->unbuddied_nr); >> goto found; >> } >> } >> @@ -346,7 +350,7 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, >> if (!page) >> return -ENOMEM; >> spin_lock(&pool->lock); >> - pool->pages_nr++; >> + atomic64_inc(&pool->pages_nr); >> zhdr = init_z3fold_page(page); >> >> if (bud == HEADLESS) { >> @@ -369,6 +373,7 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, >> /* Add to unbuddied list */ >> freechunks = num_free_chunks(zhdr); >> list_add(&zhdr->buddy, &pool->unbuddied[freechunks]); >> + atomic64_inc(&pool->unbuddied_nr); >> } else { >> /* Add to buddied list */ >> list_add(&zhdr->buddy, &pool->buddied); >> @@ -412,6 +417,10 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) >> /* HEADLESS page stored */ >> bud = HEADLESS; >> } else { >> + bool is_unbuddied = zhdr->first_chunks == 0 || >> + zhdr->middle_chunks == 0 || >> + zhdr->last_chunks == 0; >> + >> bud = handle_to_buddy(handle); >> >> switch (bud) { >> @@ -431,6 +440,8 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) >> spin_unlock(&pool->lock); >> return; >> } >> + if (is_unbuddied) >> + atomic64_dec(&pool->unbuddied_nr); > > this should be below, where it's removed from its buddy list. If it's > under reclaim, it's already been removd from the buddy list and we > shouldn't dec the counter. Right, thanks. Will fix in the new respin. ~vitaly