From b0b1eed4474359f72f4481e58eb212823e20d281 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Mon, 28 Aug 2023 11:37:51 +0200 Subject: [PATCH] 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. Lustre-change: https://review.whamcloud.com/52128 Lustre-commit: 79f823bd40ee97a5846d828efce1080dc04a6057 Signed-off-by: Sebastien Buisson Change-Id: I53c5cb14f9a5630fc269d97cead9a5ca6a33895e Reviewed-by: Andreas Dilger Reviewed-by: Aurelien Degremont Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52369 Tested-by: jenkins Tested-by: Maloo --- lustre/include/upcall_cache.h | 8 ++++---- lustre/mdt/mdt_handler.c | 1 + lustre/mdt/mdt_internal.h | 2 +- lustre/obdclass/upcall_cache.c | 22 ++++++++++++++++------ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lustre/include/upcall_cache.h b/lustre/include/upcall_cache.h index 1f02294..abc3032 100644 --- a/lustre/include/upcall_cache.h +++ b/lustre/include/upcall_cache.h @@ -92,8 +92,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; @@ -115,7 +114,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; @@ -146,7 +146,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 22a02fa..ded9a24 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -6185,6 +6185,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 d26dfd3..496bec0 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -1027,7 +1027,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 *cache, __u32 uid, diff --git a/lustre/obdclass/upcall_cache.c b/lustre/obdclass/upcall_cache.c index 1cdc85b..4ea1aba 100644 --- a/lustre/obdclass/upcall_cache.c +++ b/lustre/obdclass/upcall_cache.c @@ -201,7 +201,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); @@ -423,7 +424,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) { @@ -492,7 +494,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)) { @@ -515,7 +517,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) { @@ -541,7 +544,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; @@ -553,7 +556,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 */ @@ -571,6 +579,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); -- 1.8.3.1