From patchwork Thu Feb 7 00:03:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10800321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 819C713B4 for ; Thu, 7 Feb 2019 00:07:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DAD42D348 for ; Thu, 7 Feb 2019 00:07:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 621992D62D; Thu, 7 Feb 2019 00:07:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 04EBE2D348 for ; Thu, 7 Feb 2019 00:07:07 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id C7A494C3BD2; Wed, 6 Feb 2019 16:07:06 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id EBB694C3D10 for ; Wed, 6 Feb 2019 16:07:03 -0800 (PST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E2DC6ADE5; Thu, 7 Feb 2019 00:07:02 +0000 (UTC) From: NeilBrown To: Andreas Dilger , James Simmons , Oleg Drokin Date: Thu, 07 Feb 2019 11:03:33 +1100 Message-ID: <154949781321.10620.15836497514344103445.stgit@noble.brown> In-Reply-To: <154949776249.10620.1215070753973826063.stgit@noble.brown> References: <154949776249.10620.1215070753973826063.stgit@noble.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [lustre-devel] [PATCH 13/21] lustre: make cp_ref in cl_page a refcount_t X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" X-Virus-Scanned: ClamAV using ClamSMTP As this is used as a refcount, it should be declared as one. Signed-off-by: NeilBrown Reviewed-by: Andreas Dilger Reviewed-by: James Simmons --- drivers/staging/lustre/lustre/include/cl_object.h | 4 ++-- drivers/staging/lustre/lustre/llite/vvp_page.c | 9 +++++---- drivers/staging/lustre/lustre/obdclass/cl_page.c | 14 +++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/cl_object.h b/drivers/staging/lustre/lustre/include/cl_object.h index bf7678aed6bf..c2273c3100e8 100644 --- a/drivers/staging/lustre/lustre/include/cl_object.h +++ b/drivers/staging/lustre/lustre/include/cl_object.h @@ -717,7 +717,7 @@ enum cl_page_type { */ struct cl_page { /** Reference counter. */ - atomic_t cp_ref; + refcount_t cp_ref; /** An object this page is a part of. Immutable after creation. */ struct cl_object *cp_obj; /** vmpage */ @@ -1021,7 +1021,7 @@ static inline struct page *cl_page_vmpage(struct cl_page *page) */ static inline bool __page_in_use(const struct cl_page *page, int refc) { - return (atomic_read(&page->cp_ref) > refc + 1); + return (refcount_read(&page->cp_ref) > refc + 1); } /** diff --git a/drivers/staging/lustre/lustre/llite/vvp_page.c b/drivers/staging/lustre/lustre/llite/vvp_page.c index 77bf923f2578..ec0d93313f55 100644 --- a/drivers/staging/lustre/lustre/llite/vvp_page.c +++ b/drivers/staging/lustre/lustre/llite/vvp_page.c @@ -157,15 +157,16 @@ static void vvp_page_delete(const struct lu_env *env, struct inode *inode = vmpage->mapping->host; struct cl_object *obj = slice->cpl_obj; struct cl_page *page = slice->cpl_page; - int refc; LASSERT(PageLocked(vmpage)); LASSERT((struct cl_page *)vmpage->private == page); LASSERT(inode == vvp_object_inode(obj)); /* Drop the reference count held in vvp_page_init */ - refc = atomic_dec_return(&page->cp_ref); - LASSERTF(refc >= 1, "page = %p, refc = %d\n", page, refc); + if (refcount_dec_and_test(&page->cp_ref)) { + /* It mustn't reach zero here! */ + LASSERTF(0, "page = %p, refc reached zero\n", page); + } ClearPagePrivate(vmpage); vmpage->private = 0; @@ -507,7 +508,7 @@ int vvp_page_init(const struct lu_env *env, struct cl_object *obj, if (page->cp_type == CPT_CACHEABLE) { /* in cache, decref in vvp_page_delete */ - atomic_inc(&page->cp_ref); + refcount_inc(&page->cp_ref); SetPagePrivate(vmpage); vmpage->private = (unsigned long)page; cl_page_slice_add(page, &vpg->vpg_cl, obj, index, diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c index 31ded52e0499..f0ece7e9a4ac 100644 --- a/drivers/staging/lustre/lustre/obdclass/cl_page.c +++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c @@ -67,8 +67,8 @@ static void __cl_page_delete(const struct lu_env *env, struct cl_page *pg); */ static void cl_page_get_trust(struct cl_page *page) { - LASSERT(atomic_read(&page->cp_ref) > 0); - atomic_inc(&page->cp_ref); + LASSERT(refcount_read(&page->cp_ref) > 0); + refcount_inc(&page->cp_ref); } /** @@ -135,7 +135,7 @@ struct cl_page *cl_page_alloc(const struct lu_env *env, if (page) { int result = 0; - atomic_set(&page->cp_ref, 1); + refcount_set(&page->cp_ref, 1); page->cp_obj = o; cl_object_get(o); lu_object_ref_add_at(&o->co_lu, &page->cp_obj_ref, "cl_page", @@ -310,12 +310,12 @@ EXPORT_SYMBOL(cl_page_get); void cl_page_put(const struct lu_env *env, struct cl_page *page) { CL_PAGE_HEADER(D_TRACE, env, page, "%d\n", - atomic_read(&page->cp_ref)); + refcount_read(&page->cp_ref)); - if (atomic_dec_and_test(&page->cp_ref)) { + if (refcount_dec_and_test(&page->cp_ref)) { LASSERT(page->cp_state == CPS_FREEING); - LASSERT(atomic_read(&page->cp_ref) == 0); + LASSERT(refcount_read(&page->cp_ref) == 0); PASSERT(env, page, !page->cp_owner); PASSERT(env, page, list_empty(&page->cp_batch)); /* @@ -869,7 +869,7 @@ void cl_page_header_print(const struct lu_env *env, void *cookie, { (*printer)(env, cookie, "page@%p[%d %p %d %d %p]\n", - pg, atomic_read(&pg->cp_ref), pg->cp_obj, + pg, refcount_read(&pg->cp_ref), pg->cp_obj, pg->cp_state, pg->cp_type, pg->cp_owner); }