From 10f86dc25dd5e428a92348ed082bbbcf6b0cc90f Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Thu, 12 Dec 2024 00:40:32 -0500 Subject: [PATCH] LU-18538 ldlm: use bitmap for NS flags Use a bitmap for namespace flags in LDLM. Consolidate two bit fields into a single bitmap. This is more in line with Linux kernel style and more correct. Fixes: 70b9dc5 ("LU-17812 ldlm: stack trace log for LDLM error") Fixes: 3d4b5da ("LU-11518 ldlm: cancel LRU improvement") Signed-off-by: Timothy Day Change-Id: I50dd21d064147db1a93edb2e582db29c26b1c211 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57386 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/include/lustre_dlm.h | 50 +++++++++++++++++---------------------------- lustre/ldlm/ldlm_lockd.c | 2 +- lustre/ldlm/ldlm_pool.c | 2 +- lustre/ldlm/ldlm_request.c | 14 +++++++------ lustre/ldlm/ldlm_resource.c | 49 ++++++++++++++++++++++---------------------- lustre/ptlrpc/import.c | 4 ++-- 6 files changed, 55 insertions(+), 66 deletions(-) diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index bcf17a3..5e4f904 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -365,14 +365,25 @@ enum ldlm_ns_type { }; enum ldlm_namespace_flags { - /** + /* * Flag to indicate the LRU cancel is in progress. * Used to limit the process by 1 thread only. */ - LDLM_LRU_CANCEL = 0 + LDLM_NS_LRU_CANCEL, + LDLM_NS_STOPPING, + /* Controls the stack trace log in ldlm_lock_debug */ + LDLM_NS_DUMP_STACK, + /* + * Flag to indicate the LRU recalc on RPC reply is in progress. + * Used to limit the process by 1 thread only. + */ + LDLM_NS_RPC_RECALC, + /* lru_size is set even before connection */ + LDLM_NS_LRU_SIZE_SET_BEFORE_CONN, + LDLM_NS_NUM_FLAGS }; -/** +/* * LDLM Namespace. * * Namespace serves to contain locks related to a particular service. @@ -558,27 +569,6 @@ struct ldlm_namespace { struct lprocfs_stats *ns_stats; /** - * Flag to indicate namespace is being freed. Used to determine if - * recalculation of LDLM pool statistics should be skipped. - */ - unsigned int ns_stopping:1, - - - /** - * This namespace will control the stack trace log in ldlm_lock_debug - */ - ns_dump_stack_on_error:1, - - /** - * Flag to indicate the LRU recalc on RPC reply is in progress. - * Used to limit the process by 1 thread only. - */ - ns_rpc_recalc:1, - - /* lru_size is set even before connection */ - ns_lru_size_set_before_connection:1; - - /** * Which bucket should we start with the lock reclaim. */ int ns_reclaim_start; @@ -586,10 +576,8 @@ struct ldlm_namespace { struct kobject ns_kobj; /* sysfs object */ struct completion ns_kobj_unregister; - /** - * To avoid another ns_lock usage, a separate bitops field. - */ - unsigned long ns_flags; + /* See enum ldlm_namespace_flags */ + DECLARE_BITMAP(ns_flags, LDLM_NS_NUM_FLAGS); }; /** @@ -1348,9 +1336,9 @@ extern const char *ldlm_it2str(enum ldlm_intent_flags it); ((libcfs_debug & (mask)) != 0 && \ (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) { \ _ldlm_lock_debug(lock, msgdata, fmt, ##a); \ - if (unlikely(ldlm_lock_to_ns(lock)-> \ - ns_dump_stack_on_error) && \ - !!((mask) & D_ERROR)) \ + if (unlikely(test_bit(LDLM_NS_DUMP_STACK, \ + ldlm_lock_to_ns(lock)->ns_flags)) && \ + !!((mask) & D_ERROR)) \ dump_stack(); \ } \ } while (0) diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index 809ce3e..a28a7a4 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -2961,7 +2961,7 @@ static int ldlm_bl_thread_blwi(struct ldlm_bl_pool *blp, } else { ldlm_pool_recalc(&blwi->blwi_ns->ns_pool, true); spin_lock(&blwi->blwi_ns->ns_lock); - blwi->blwi_ns->ns_rpc_recalc = 0; + clear_bit(LDLM_NS_RPC_RECALC, blwi->blwi_ns->ns_flags); spin_unlock(&blwi->blwi_ns->ns_lock); ldlm_namespace_put(blwi->blwi_ns); } diff --git a/lustre/ldlm/ldlm_pool.c b/lustre/ldlm/ldlm_pool.c index ab24521..e1bac43 100644 --- a/lustre/ldlm/ldlm_pool.c +++ b/lustre/ldlm/ldlm_pool.c @@ -1314,7 +1314,7 @@ static time64_t ldlm_pools_recalc_delay(enum ldlm_side side) * skip ns which is being freed, and we don't want to increase * its refcount again, not even temporarily. bz21519 & LU-499. */ - if (ns->ns_stopping) { + if (test_bit(LDLM_NS_STOPPING, ns->ns_flags)) { skip = 1; } else { skip = 0; diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c index 81133ff..f5a0c3b 100644 --- a/lustre/ldlm/ldlm_request.c +++ b/lustre/ldlm/ldlm_request.c @@ -1571,14 +1571,16 @@ int ldlm_cli_update_pool(struct ptlrpc_request *req) ratio = 100 * new_slv / ldlm_pool_get_slv(&ns->ns_pool); if (100 - ratio >= ns->ns_recalc_pct && - !ns->ns_stopping && !ns->ns_rpc_recalc) { + !test_bit(LDLM_NS_STOPPING, ns->ns_flags) && + !test_bit(LDLM_NS_RPC_RECALC, ns->ns_flags)) { bool recalc = false; spin_lock(&ns->ns_lock); - if (!ns->ns_stopping && !ns->ns_rpc_recalc) { + if (!test_bit(LDLM_NS_STOPPING, ns->ns_flags) && + !test_bit(LDLM_NS_RPC_RECALC, ns->ns_flags)) { ldlm_namespace_get(ns); recalc = true; - ns->ns_rpc_recalc = 1; + set_bit(LDLM_NS_RPC_RECALC, ns->ns_flags); } spin_unlock(&ns->ns_lock); if (recalc) @@ -1933,9 +1935,9 @@ static int ldlm_prepare_lru_list(struct ldlm_namespace *ns, * @max limit given (ELC), as LRU may be left not cleaned up in full. */ if (max == 0) { - if (test_and_set_bit(LDLM_LRU_CANCEL, &ns->ns_flags)) + if (test_and_set_bit(LDLM_NS_LRU_CANCEL, ns->ns_flags)) RETURN(0); - } else if (test_bit(LDLM_LRU_CANCEL, &ns->ns_flags)) + } else if (test_bit(LDLM_NS_LRU_CANCEL, ns->ns_flags)) RETURN(0); LASSERT(ergo(max, min <= max)); @@ -2082,7 +2084,7 @@ static int ldlm_prepare_lru_list(struct ldlm_namespace *ns, } if (max == 0) - clear_bit(LDLM_LRU_CANCEL, &ns->ns_flags); + clear_bit(LDLM_NS_LRU_CANCEL, ns->ns_flags); RETURN(added); } diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index f471fac..327f428 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -202,7 +202,7 @@ static ssize_t lru_size_store(struct kobject *kobj, struct attribute *attr, */ spin_lock(&ns->ns_lock); if (ns->ns_connect_flags == 0) - ns->ns_lru_size_set_before_connection = 1; + set_bit(LDLM_NS_LRU_SIZE_SET_BEFORE_CONN, ns->ns_flags); spin_unlock(&ns->ns_lock); /* Make sure that LRU resize was originally supported before @@ -382,7 +382,7 @@ static ssize_t dump_stack_on_error_show(struct kobject *kobj, ns_kobj); return snprintf(buf, sizeof(buf) - 1, "%u\n", - ns->ns_dump_stack_on_error); + test_bit(LDLM_NS_DUMP_STACK, ns->ns_flags)); } static ssize_t dump_stack_on_error_store(struct kobject *kobj, @@ -395,10 +395,13 @@ static ssize_t dump_stack_on_error_store(struct kobject *kobj, int err; err = kstrtobool(buffer, &tmp); - if (err != 0) + if (err) return -EINVAL; - ns->ns_dump_stack_on_error = tmp; + if (tmp) + set_bit(LDLM_NS_DUMP_STACK, ns->ns_flags); + else + clear_bit(LDLM_NS_DUMP_STACK, ns->ns_flags); return count; } @@ -815,26 +818,22 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, atomic_set(&ns->ns_bref, 0); init_waitqueue_head(&ns->ns_waitq); - ns->ns_connect_flags = 0; - ns->ns_orig_connect_flags = 0; - ns->ns_nr_unused = 0; - ns->ns_last_pos = &ns->ns_unused_list; - ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE; - ns->ns_cancel_batch = LDLM_DEFAULT_LRU_SHRINK_BATCH; - ns->ns_recalc_pct = LDLM_DEFAULT_SLV_RECALC_PCT; - ns->ns_max_age = ktime_set(LDLM_DEFAULT_LRU_MAX_AGE, 0); - ns->ns_timeouts = 0; - ns->ns_ctime_age_limit = LDLM_CTIME_AGE_LIMIT; - ns->ns_dirty_age_limit = ktime_set(LDLM_DIRTY_AGE_LIMIT, 0); - ns->ns_contended_locks = NS_DEFAULT_CONTENDED_LOCKS; - ns->ns_contention_time = NS_DEFAULT_CONTENTION_SECONDS; - ns->ns_max_nolock_size = NS_DEFAULT_MAX_NOLOCK_BYTES; - ns->ns_max_parallel_ast = LDLM_DEFAULT_PARALLEL_AST_LIMIT; - ns->ns_stopping = 0; - ns->ns_rpc_recalc = 0; - ns->ns_dump_stack_on_error = 0; - ns->ns_reclaim_start = 0; - ns->ns_flags = 0; + ns->ns_connect_flags = 0; + ns->ns_orig_connect_flags = 0; + ns->ns_nr_unused = 0; + ns->ns_last_pos = &ns->ns_unused_list; + ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE; + ns->ns_cancel_batch = LDLM_DEFAULT_LRU_SHRINK_BATCH; + ns->ns_recalc_pct = LDLM_DEFAULT_SLV_RECALC_PCT; + ns->ns_max_age = ktime_set(LDLM_DEFAULT_LRU_MAX_AGE, 0); + ns->ns_timeouts = 0; + ns->ns_ctime_age_limit = LDLM_CTIME_AGE_LIMIT; + ns->ns_dirty_age_limit = ktime_set(LDLM_DIRTY_AGE_LIMIT, 0); + ns->ns_contended_locks = NS_DEFAULT_CONTENDED_LOCKS; + ns->ns_contention_time = NS_DEFAULT_CONTENTION_SECONDS; + ns->ns_max_nolock_size = NS_DEFAULT_MAX_NOLOCK_BYTES; + ns->ns_max_parallel_ast = LDLM_DEFAULT_PARALLEL_AST_LIMIT; + ns->ns_reclaim_start = 0; rc = ldlm_namespace_sysfs_register(ns); if (rc) { @@ -1085,7 +1084,7 @@ void ldlm_namespace_free_prior(struct ldlm_namespace *ns, } spin_lock(&ns->ns_lock); - ns->ns_stopping = 1; + set_bit(LDLM_NS_STOPPING, ns->ns_flags); spin_unlock(&ns->ns_lock); /* Can fail with -EINTR when force == 0 in which case try harder. */ diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c index 6379f77..03b4184 100644 --- a/lustre/ptlrpc/import.c +++ b/lustre/ptlrpc/import.c @@ -955,11 +955,11 @@ static int ptlrpc_connect_set_flags(struct obd_import *imp, * see lru_size_store(). */ if (ns_connect_lru_resize(ns) && - ns->ns_lru_size_set_before_connection && + test_bit(LDLM_NS_LRU_SIZE_SET_BEFORE_CONN, ns->ns_flags) && ns->ns_max_unused != 0) ns->ns_connect_flags &= ~OBD_CONNECT_LRU_RESIZE; - ns->ns_lru_size_set_before_connection = 0; + clear_bit(LDLM_NS_LRU_SIZE_SET_BEFORE_CONN, ns->ns_flags); spin_unlock(&ns->ns_lock); } -- 1.8.3.1