From e19804a3b7e793a11b1c8b5e0db9f6315f243b8c Mon Sep 17 00:00:00 2001 From: "Mr. NeilBrown" Date: Tue, 8 Nov 2022 12:23:04 -0500 Subject: [PATCH] LU-6142 clio: make cp_ref in cl_page a refcount_t As this is used as a refcount, it should be declared as one. Change-Id: I8108e14e545bb56aae34a0f6ae9d5a04227fc067 Signed-off-by: Mr. NeilBrown Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49072 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- lustre/include/cl_object.h | 4 ++-- lustre/llite/vvp_io.c | 2 +- lustre/llite/vvp_page.c | 2 +- lustre/obdclass/cl_page.c | 18 ++++++++---------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lustre/include/cl_object.h b/lustre/include/cl_object.h index 3094b61..3daeefa 100644 --- a/lustre/include/cl_object.h +++ b/lustre/include/cl_object.h @@ -734,7 +734,7 @@ enum cl_page_type { */ struct cl_page { /** Reference counter. */ - atomic_t cp_ref; + refcount_t cp_ref; /** layout_entry + stripe index, composed using lov_comp_index() */ unsigned int cp_lov_index; /** page->index of the page within the whole file */ @@ -982,7 +982,7 @@ static inline pgoff_t cl_page_index(const struct cl_page *cp) */ 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/lustre/llite/vvp_io.c b/lustre/llite/vvp_io.c index 699e9a6..f095c0a 100644 --- a/lustre/llite/vvp_io.c +++ b/lustre/llite/vvp_io.c @@ -1400,7 +1400,7 @@ static void detach_and_deref_page(struct cl_page *clp, struct page *vmpage) vmpage->private = 0; put_page(vmpage); - atomic_dec(&clp->cp_ref); + refcount_dec(&clp->cp_ref); } static int vvp_io_kernel_fault(const struct lu_env *env, diff --git a/lustre/llite/vvp_page.c b/lustre/llite/vvp_page.c index f3840c4..b892013 100644 --- a/lustre/llite/vvp_page.c +++ b/lustre/llite/vvp_page.c @@ -190,7 +190,7 @@ int vvp_page_init(const struct lu_env *env, struct cl_object *obj, } else { get_page(vmpage); /* in cache, decref in cl_page_delete() */ - atomic_inc(&page->cp_ref); + refcount_inc(&page->cp_ref); SetPagePrivate(vmpage); vmpage->private = (unsigned long)page; cl_page_slice_add(page, cpl, obj, &vvp_page_ops); diff --git a/lustre/obdclass/cl_page.c b/lustre/obdclass/cl_page.c index d7e384d..bc384be 100644 --- a/lustre/obdclass/cl_page.c +++ b/lustre/obdclass/cl_page.c @@ -118,8 +118,8 @@ static void cs_pagestate_dec(const struct cl_object *obj, */ 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); } static struct cl_page_slice * @@ -271,7 +271,7 @@ struct cl_page *cl_page_alloc(const struct lu_env *env, struct cl_object *o, */ BUILD_BUG_ON((1 << CP_STATE_BITS) < CPS_NR); /* cp_state */ BUILD_BUG_ON((1 << CP_TYPE_BITS) < CPT_NR); /* cp_type */ - atomic_set(&cl_page->cp_ref, 1); + refcount_set(&cl_page->cp_ref, 1); cl_page->cp_obj = o; if (type != CPT_TRANSIENT) cl_object_get(o); @@ -470,12 +470,12 @@ void cl_pagevec_put(const struct lu_env *env, struct cl_page *page, { ENTRY; 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 == NULL); PASSERT(env, page, list_empty(&page->cp_batch)); /* @@ -806,7 +806,6 @@ static void __cl_page_delete(const struct lu_env *env, struct cl_page *cp) { struct page *vmpage; const struct cl_page_slice *slice; - int refc; int i; ENTRY; @@ -847,8 +846,7 @@ static void __cl_page_delete(const struct lu_env *env, struct cl_page *cp) get_page(vmpage); } else { /* Drop the reference count held in vvp_page_init */ - refc = atomic_dec_return(&cp->cp_ref); - LASSERTF(refc >= 1, "page = %p, refc = %d\n", cp, refc); + refcount_dec(&cp->cp_ref); ClearPagePrivate(vmpage); vmpage->private = 0; @@ -1133,7 +1131,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); } -- 1.8.3.1