From: Sebastien Buisson Date: Mon, 28 Aug 2023 09:37:51 +0000 (+0200) Subject: LU-17015 obdclass: make upcall cache hashtable size dynamic X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=556ca8d3adcf5aa8a6a2efb1ba3e094b1b04c46a;p=fs%2Flustre-release.git LU-17015 obdclass: make upcall cache hashtable size dynamic The hash table used by the upcall cache mechanism should have an adjustable size, depending on the purpose and context where it is used. Signed-off-by: Sebastien Buisson Change-Id: I53c5cb14f9a5630fc269d97cead9a5ca6a33895e --- diff --git a/lustre/include/upcall_cache.h b/lustre/include/upcall_cache.h index 572e616..42e6b7f 100644 --- a/lustre/include/upcall_cache.h +++ b/lustre/include/upcall_cache.h @@ -91,8 +91,7 @@ struct upcall_cache_entry { } u; }; -#define UC_CACHE_HASH_SIZE (128) -#define UC_CACHE_HASH_INDEX(id) ((id) & (UC_CACHE_HASH_SIZE - 1)) +#define UC_CACHE_HASH_INDEX(id, size) ((id) & ((size) - 1)) #define UC_CACHE_UPCALL_MAXPATH (1024UL) struct upcall_cache; @@ -114,7 +113,8 @@ struct upcall_cache_ops { }; struct upcall_cache { - struct list_head uc_hashtable[UC_CACHE_HASH_SIZE]; + struct list_head *uc_hashtable; + int uc_hashsize; spinlock_t uc_lock; struct rw_semaphore uc_upcall_rwsem; @@ -145,7 +145,7 @@ static inline void upcall_cache_flush_all(struct upcall_cache *cache) void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args); struct upcall_cache *upcall_cache_init(const char *name, const char *upcall, - struct upcall_cache_ops *ops); + int hashsz, struct upcall_cache_ops *ops); void upcall_cache_cleanup(struct upcall_cache *cache); /** @} ucache */ diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index f059339..773d2ba 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -6317,6 +6317,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, m->mdt_identity_cache = upcall_cache_init(mdt_obd_name(m), identity_upcall, + UC_IDCACHE_HASH_SIZE, &mdt_identity_upcall_cache_ops); if (IS_ERR(m->mdt_identity_cache)) { rc = PTR_ERR(m->mdt_identity_cache); diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 71fef0d..094b12b 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -1043,7 +1043,7 @@ static inline bool agent_req_in_final_state(enum agent_req_status ars) /* mdt/mdt_identity.c */ #define MDT_IDENTITY_UPCALL_PATH "/usr/sbin/l_getidentity" - +#define UC_IDCACHE_HASH_SIZE 128 extern struct upcall_cache_ops mdt_identity_upcall_cache_ops; struct md_identity *mdt_identity_get(struct upcall_cache *, __u32); diff --git a/lustre/obdclass/upcall_cache.c b/lustre/obdclass/upcall_cache.c index 325ccac..0a332c8 100644 --- a/lustre/obdclass/upcall_cache.c +++ b/lustre/obdclass/upcall_cache.c @@ -154,7 +154,8 @@ struct upcall_cache_entry *upcall_cache_get_entry(struct upcall_cache *cache, LASSERT(cache); - head = &cache->uc_hashtable[UC_CACHE_HASH_INDEX(key)]; + head = &cache->uc_hashtable[UC_CACHE_HASH_INDEX(key, + cache->uc_hashsize)]; find_again: found = 0; spin_lock(&cache->uc_lock); @@ -304,7 +305,8 @@ int upcall_cache_downcall(struct upcall_cache *cache, __u32 err, __u64 key, LASSERT(cache); - head = &cache->uc_hashtable[UC_CACHE_HASH_INDEX(key)]; + head = &cache->uc_hashtable[UC_CACHE_HASH_INDEX(key, + cache->uc_hashsize)]; spin_lock(&cache->uc_lock); list_for_each_entry(entry, head, ue_hash) { @@ -373,7 +375,7 @@ void upcall_cache_flush(struct upcall_cache *cache, int force) ENTRY; spin_lock(&cache->uc_lock); - for (i = 0; i < UC_CACHE_HASH_SIZE; i++) { + for (i = 0; i < cache->uc_hashsize; i++) { list_for_each_entry_safe(entry, next, &cache->uc_hashtable[i], ue_hash) { if (!force && atomic_read(&entry->ue_refcount)) { @@ -396,7 +398,8 @@ void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args) int found = 0; ENTRY; - head = &cache->uc_hashtable[UC_CACHE_HASH_INDEX(key)]; + head = &cache->uc_hashtable[UC_CACHE_HASH_INDEX(key, + cache->uc_hashsize)]; spin_lock(&cache->uc_lock); list_for_each_entry(entry, head, ue_hash) { @@ -422,7 +425,7 @@ void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key, void *args) EXPORT_SYMBOL(upcall_cache_flush_one); struct upcall_cache *upcall_cache_init(const char *name, const char *upcall, - struct upcall_cache_ops *ops) + int hashsz, struct upcall_cache_ops *ops) { struct upcall_cache *cache; int i; @@ -434,7 +437,12 @@ struct upcall_cache *upcall_cache_init(const char *name, const char *upcall, spin_lock_init(&cache->uc_lock); init_rwsem(&cache->uc_upcall_rwsem); - for (i = 0; i < UC_CACHE_HASH_SIZE; i++) + cache->uc_hashsize = hashsz; + LIBCFS_ALLOC(cache->uc_hashtable, + sizeof(*cache->uc_hashtable) * cache->uc_hashsize); + if (!cache->uc_hashtable) + RETURN(ERR_PTR(-ENOMEM)); + for (i = 0; i < cache->uc_hashsize; i++) INIT_LIST_HEAD(&cache->uc_hashtable[i]); strlcpy(cache->uc_name, name, sizeof(cache->uc_name)); /* upcall pathname proc tunable */ @@ -452,6 +460,8 @@ void upcall_cache_cleanup(struct upcall_cache *cache) if (!cache) return; upcall_cache_flush_all(cache); + LIBCFS_FREE(cache->uc_hashtable, + sizeof(*cache->uc_hashtable) * cache->uc_hashsize); LIBCFS_FREE(cache, sizeof(*cache)); } EXPORT_SYMBOL(upcall_cache_cleanup);