Whamcloud - gitweb
LU-17015 obdclass: make upcall cache hashtable size dynamic 28/52128/3
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 28 Aug 2023 09:37:51 +0000 (11:37 +0200)
committerOleg Drokin <green@whamcloud.com>
Wed, 13 Sep 2023 04:06:24 +0000 (04:06 +0000)
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 <sbuisson@ddn.com>
Change-Id: I53c5cb14f9a5630fc269d97cead9a5ca6a33895e
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52128
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Aurelien Degremont <adegremont@nvidia.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/upcall_cache.h
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_internal.h
lustre/obdclass/upcall_cache.c

index 572e616..42e6b7f 100644 (file)
@@ -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 */
index 5eb14dd..20cea90 100644 (file)
@@ -6335,6 +6335,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);
index 55e6062..30c6f2a 100644 (file)
@@ -1044,7 +1044,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);
index 325ccac..0a332c8 100644 (file)
@@ -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);