lustre: obd: convert obd_nid_hash to rhashtable
RFC PATCH 1/1 lustre: obd: convert obd_nid_hash to rhashtable
This patch converts the struct obd_export obd_nid_hash used by the servr to use rhltables. The reason is that the NID hash can have multiple obd exports using the same NID key. In the process we gain lockless lookup which should improve performance. This should also address the rare crashes:
[<ffffffffc0913388>] ? cfs_hash_bd_from_key+0x38/0xb0 [libcfs]
[74844.507416] [<ffffffffc0913425>] cfs_hash_bd_get+0x25/0x70 [libcfs] [74844.516384] [<ffffffffc09166d2>] cfs_hash_add+0x52/0x1a0 [libcfs] [74844.525211] [<ffffffffc0d8a765>] target_handle_connect+0x1fe5/0x29b0 [ptlrpc]
Pre 4.8 kernels do not support rhltables so wrappers have been created.
***
My testing has been positive so far but I do need to figure out the debugfs file mapping from the old libcfs hash to rhashtables.
***
--- libcfs/autoconf/lustre-libcfs.m4 | 21 +++ libcfs/include/libcfs/linux/linux-hash.h | 88 ++++++++++++ lustre/include/lustre_export.h | 2 +- lustre/include/obd.h | 8 +- lustre/include/obd_support.h | 3 - lustre/ldlm/ldlm_flock.c | 18 ++- lustre/ldlm/ldlm_lib.c | 14 +- lustre/mdt/mdt_lproc.c | 21 ++- lustre/obdclass/genops.c | 76 ++++++----- lustre/obdclass/lprocfs_status_server.c | 133 +++++++++++------- lustre/obdclass/obd_config.c | 225 ++++++++++++++++++------------- 11 files changed, 394 insertions(+), 215 deletions(-)
libcfs/autoconf/lustre-libcfs.m4 +21 -0
@@ -761,6 +761,26 @@ LB_CHECK_LINUX_HEADER([linux/stringhash.h], [ ]) # LIBCFS_STRINGHASH # +# LIBCFS_RHLTABLE +# Kernel version 4.8 commit ca26893f05e86497a86732768ec53cd38c0819ca +# created the rhlist interface to allow inserting duplicate objects +# into the same table. +# +AC_DEFUN([LIBCFS_RHLTABLE], [ +LB_CHECK_COMPILE([if 'struct rhltable' exist], +rhtable, [ + #include <linux/rhashtable.h> +],[ + struct rhltable *hlt = NULL; + + rhltable_destroy(hlt); +],[ + AC_DEFINE(HAVE_RHLTABLE, 1, + [struct rhltable exist]) +]) +]) # LIBCFS_RHLTABLE + +# # LIBCFS_STACKTRACE_OPS # # Kernel version 4.8 commit c8fe4609827aedc9c4b45de80e7cdc8ccfa8541b
@@ -999,6 +1019,7 @@ LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT LIBCFS_GET_USER_PAGES_6ARG LIBCFS_STRINGHASH # 4.8 +LIBCFS_RHLTABLE LIBCFS_STACKTRACE_OPS # 4.9 LIBCFS_GET_USER_PAGES_GUP_FLAGS
libcfs/include/libcfs/linux/linux-hash.h +88 -0
94 lines not on this page · raw message
lustre/include/lustre_export.h +1 -1
@@ -209,7 +209,7 @@ struct obd_export {/* Unlinked export list */ struct list_head exp_stale_list;struct hlist_node exp_uuid_hash;/** uuid-export hash*/ -struct hlist_node exp_nid_hash;/** nid-export hash */ +struct rhlist_head exp_nid_hash;/** nid-export hash */ struct hlist_node exp_gen_hash;/** last_rcvd clt gen hash */ /** * All exports eligible for ping evictor are linked into a list
lustre/include/obd.h +7 -1
@@ -639,7 +639,7 @@ struct obd_device {/* uuid-export hash body */ struct cfs_hash *obd_uuid_hash;/* nid-export hash body */ -struct cfs_hash *obd_nid_hash; +struct rhltable obd_nid_hash;/* nid stats body */ struct cfs_hash *obd_nid_stats_hash;/* client_generation-export hash body */
@@ -750,6 +750,12 @@ struct obd_device {struct completion obd_kobj_unregister; }; +int obd_nid_export_for_each (struct obd_device *obd,lnet_nid_t nid, +int cb (struct obd_export *exp,void *data), +void *data); +int obd_nid_add (struct obd_device *obd,struct obd_export *exp); +void obd_nid_del (struct obd_device *obd,struct obd_export *exp); +/* get/set_info keys */ #define KEY_ASYNC "async"#define KEY_CHANGELOG_CLEAR "changelog_clear"
lustre/include/obd_support.h +0 -3
@@ -78,9 +78,6 @@ extern char obd_jobid_var[];#define HASH_UUID_BKT_BITS 5#define HASH_UUID_CUR_BITS 7#define HASH_UUID_MAX_BITS 12 -#define HASH_NID_BKT_BITS 5 -#define HASH_NID_CUR_BITS 7 -#define HASH_NID_MAX_BITS 12#define HASH_NID_STATS_BKT_BITS 5#define HASH_NID_STATS_CUR_BITS 7#define HASH_NID_STATS_MAX_BITS 12
lustre/ldlm/ldlm_flock.c +8 -10
@@ -161,20 +161,18 @@ ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags)*/ struct ldlm_flock_lookup_cb_data { -__u64 *bl_owner; +u64 *bl_owner;struct ldlm_lock *lock;struct obd_export *exp; }; -static int ldlm_flock_lookup_cb (struct cfs_hash *hs,struct cfs_hash_bd *bd, -struct hlist_node *hnode,void *data) +static int ldlm_flock_lookup_cb (struct obd_export *exp,void *data) {struct ldlm_flock_lookup_cb_data *cb_data = data; -struct obd_export *exp =cfs_hash_object (hs, hnode);struct ldlm_lock *lock; lock =cfs_hash_lookup (exp->exp_flock_hash, cb_data->bl_owner); -if (lock ==NULL ) +if (!lock)return 0 ;/* Stop on first found lock. Same process can't sleep twice */
@@ -206,13 +204,13 @@ ldlm_flock_deadlock(struct ldlm_lock *req, struct ldlm_lock *bl_lock)struct ldlm_lock *lock =NULL ;struct ldlm_flock *flock; -if (bl_exp->exp_flock_hash !=NULL ) { -cfs_hash_for_each_key (bl_exp->exp_obd->obd_nid_hash, - &bl_exp->exp_connection->c_peer.nid, - ldlm_flock_lookup_cb, &cb_data); +if (bl_exp->exp_flock_hash) { +obd_nid_export_for_each (bl_exp->exp_obd, + bl_exp->exp_connection->c_peer.nid, + ldlm_flock_lookup_cb, &cb_data); lock = cb_data.lock; } -if (lock ==NULL ) +if (!lock)break ;class_export_put (bl_exp);
lustre/ldlm/ldlm_lib.c +5 -9
@@ -1337,11 +1337,9 @@ dont_check_exports:if (export->exp_connection !=NULL ) {/* Check to see if connection came from another NID. */ -if ((export->exp_connection->c_peer.nid != req->rq_peer.nid) && - !hlist_unhashed (&export->exp_nid_hash)) -cfs_hash_del (export->exp_obd->obd_nid_hash, - &export->exp_connection->c_peer.nid, - &export->exp_nid_hash); +if (export->exp_connection->c_peer.nid != req->rq_peer.nid && + export != export->exp_obd->obd_self_export) +obd_nid_del (export->exp_obd, export);ptlrpc_connection_put (export->exp_connection); }
@@ -1349,10 +1347,8 @@ dont_check_exports: export->exp_connection =ptlrpc_connection_get (req->rq_peer, req->rq_self, &cluuid); -if (hlist_unhashed (&export->exp_nid_hash)) -cfs_hash_add (export->exp_obd->obd_nid_hash, - &export->exp_connection->c_peer.nid, - &export->exp_nid_hash); +if (export != export->exp_obd->obd_self_export) +obd_nid_add (export->exp_obd, export);lustre_msg_set_handle (req->rq_repmsg, &conn);
lustre/mdt/mdt_lproc.c +8 -13
@@ -1009,19 +1009,17 @@ static struct lprocfs_vars lprocfs_mdt_obd_vars[] = { };static int -lprocfs_mdt_print_open_files (struct cfs_hash *hs,struct cfs_hash_bd *bd, -struct hlist_node *hnode,void *v) +lprocfs_mdt_print_open_files (struct obd_export *exp,void *v) { -struct obd_export *exp =cfs_hash_object (hs, hnode); -struct seq_file *seq = v; +struct seq_file *seq = v; -if (exp->exp_lock_hash !=NULL ) { -struct mdt_export_data *med = &exp->exp_mdt_data; -struct mdt_file_data *mfd; +if (exp->exp_lock_hash) { +struct mdt_export_data *med = &exp->exp_mdt_data; +struct mdt_file_data *mfd;spin_lock (&med->med_open_lock);list_for_each_entry (mfd, &med->med_open_head, mfd_list) { -seq_printf (seq,DFID "\n" , +seq_printf (seq,DFID "\n" ,PFID (mdt_object_fid (mfd->mfd_object))); }spin_unlock (&med->med_open_lock);
@@ -1033,12 +1031,9 @@ lprocfs_mdt_print_open_files(struct cfs_hash *hs, struct cfs_hash_bd *bd,static int lprocfs_mdt_open_files_seq_show (struct seq_file *seq,void *v) {struct nid_stat *stats = seq->private; -struct obd_device *obd = stats->nid_obd; -cfs_hash_for_each_key (obd->obd_nid_hash, &stats->nid, - lprocfs_mdt_print_open_files, seq); - -return 0 ; +return obd_nid_export_for_each (stats->nid_obd, stats->nid, + lprocfs_mdt_print_open_files, seq); }int lprocfs_mdt_open_files_seq_open (struct inode *inode,struct file *file)
lustre/obdclass/genops.c +40 -36
114 lines not on this page · raw message
lustre/obdclass/lprocfs_status_server.c +81 -52
212 lines not on this page · raw message
lustre/obdclass/obd_config.c +135 -90
276 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH 1/1 lustre: obd: convert obd_nid_hash to rhashtable
Quoted 230 lines · James Simmons
This patch converts the struct
obd_exportobd_nid_hashused by the servr to use rhltables. The reason is that the NID hash can have multiple obd exports using the same NID key. In the process we gain lockless lookup which should improve performance. This should also address the rare crashes:[<
ffffffffc0913388>] ?cfs_hash_bd_from_key+0x38/0xb0[libcfs][74844.507416] [<ffffffffc0913425>] cfs_hash_bd_get+0x25/0x70 [libcfs] [74844.516384] [<ffffffffc09166d2>] cfs_hash_add+0x52/0x1a0 [libcfs] [74844.525211] [<ffffffffc0d8a765>] target_handle_connect+0x1fe5/0x29b0 [ptlrpc]Pre 4.8 kernels do not support rhltables so wrappers have been created.
***
My testing has been positive so far but I do need to figure out the debugfs file mapping from the old libcfs hash to rhashtables.***
Signed-off-by James Simmons <[email protected]>--- libcfs/autoconf/lustre-libcfs.m4 | 21 +++ libcfs/include/libcfs/linux/linux-hash.h | 88 ++++++++++++ lustre/include/lustre_export.h | 2 +- lustre/include/obd.h | 8 +- lustre/include/obd_support.h | 3 - lustre/ldlm/ldlm_flock.c | 18 ++- lustre/ldlm/ldlm_lib.c | 14 +- lustre/mdt/mdt_lproc.c | 21 ++- lustre/obdclass/genops.c | 76 ++++++----- lustre/obdclass/lprocfs_status_server.c | 133 +++++++++++------- lustre/obdclass/obd_config.c | 225 ++++++++++++++++++------------- 11 files changed, 394 insertions(+), 215 deletions(-)libcfs/autoconf/lustre-libcfs.m4 +21
-0@@ -761,6 +761,26 @@ LB_CHECK_LINUX_HEADER([linux/stringhash.h], [ ]) # LIBCFS_STRINGHASH # +# LIBCFS_RHLTABLE +# Kernel version 4.8 commit ca26893f05e86497a86732768ec53cd38c0819ca +# created the rhlist interface to allow inserting duplicate objects +# into the same table. +# +AC_DEFUN([LIBCFS_RHLTABLE], [ +LB_CHECK_COMPILE([if 'struct rhltable' exist], +rhtable, [ + #include <linux/rhashtable.h> +],[ + struct rhltable *hlt = NULL; + + rhltable_destroy(hlt); +],[ + AC_DEFINE(HAVE_RHLTABLE, 1, + [struct rhltable exist]) +]) +]) # LIBCFS_RHLTABLE + +# # LIBCFS_STACKTRACE_OPS # # Kernel version 4.8 commit c8fe4609827aedc9c4b45de80e7cdc8ccfa8541b@@ -999,6 +1019,7 @@ LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT LIBCFS_GET_USER_PAGES_6ARG LIBCFS_STRINGHASH # 4.8 +LIBCFS_RHLTABLE LIBCFS_STACKTRACE_OPS # 4.9 LIBCFS_GET_USER_PAGES_GUP_FLAGSlibcfs/include/libcfs/linux/linux-hash.h +88
-0@@ -38,6 +38,94 @@ u64 cfs_hashlen_string(const void *salt, const char *name);#endif #endif /* !HAVE_STRINGHASH */ +#ifndef HAVE_RHLTABLE +struct rhlist_head { +struct rhash_head rhead; +struct rhlist_head __rcu *next; +}; + +struct rhltable { +struct rhashtable ht; +}; + +#define rhl_for_each_entry_rcu (tpos, pos, list, member) \ + for (pos = list; pos && rht_entry(tpos, pos, member); \ + pos = rcu_dereference_raw(pos->next)) + +static inline int rhltable_init (struct rhltable *hlt,const struct rhashtable_params *params) +{ +return rhashtable_init (&hlt->ht, params); +} + +static inline struct rhlist_head *rhltable_lookup ( +struct rhltable *hlt,const void *key, +const struct rhashtable_params params) +{ +struct rhashtable *ht = &hlt->ht; +struct rhashtable_compare_arg arg = { + .ht = ht, + .key = key, + }; +struct bucket_table *tbl; +struct rhash_head *he; +unsigned int hash; + + tbl =rht_dereference_rcu (ht->tbl, ht); +restart: + hash =rht_key_hashfn (ht, tbl, key, params); +rht_for_each_rcu (he, tbl, hash) { +if (params.obj_cmpfn ? + params.obj_cmpfn (&arg,rht_obj (ht, he)) : +rhashtable_compare (&arg,rht_obj (ht, he))) +continue ; + return he ? container_of(he, struct rhlist_head, rhead) : NULL; + } + +/* Ensure we see any new tables. */ +smp_rmb (); + + tbl =rht_dereference_rcu (tbl->future_tbl, ht); +if (unlikely (tbl)) + goto restart; + +return NULL ; +} + +static inline int rhltable_insert_key ( +struct rhltable *hlt,const void *key,struct rhlist_head *list, +const struct rhashtable_params params) +{ +return PTR_ERR (__rhashtable_insert_fast (&hlt->ht, key, &list->rhead, + params)); +} + +static inline int rhltable_remove ( +struct rhltable *hlt,struct rhlist_head *list, +const struct rhashtable_params params) +{ +return rhashtable_remove_fast (&hlt->ht, &list->rhead, params); +} + +static inline void rhltable_free_and_destroy (struct rhltable *hlt, +void (*free_fn)(void *ptr, +void *arg), +void *arg) +{ +return rhashtable_free_and_destroy (&hlt->ht, free_fn, arg); +} + +static inline void rhltable_destroy (struct rhltable *hlt) +{ +return rhltable_free_and_destroy (hlt,NULL ,NULL ); +} + +static inline void rhltable_walk_enter (struct rhltable *hlt, +struct rhashtable_iter *iter) +{ +rhashtable_walk_init (&hlt->ht, iter); +} +#endif /* !HAVE_RHLTABLE */ +#ifndef HAVE_RHASHTABLE_LOOKUP_GET_INSERT_FAST /** * rhashtable_lookup_get_insert_fast - lookup and insert object into hash table lustre/include/lustre_export.h +1
-1@@ -209,7 +209,7 @@ struct obd_export {/* Unlinked export list */ struct list_head exp_stale_list;struct hlist_node exp_uuid_hash;/** uuid-export hash*/ -struct hlist_node exp_nid_hash;/** nid-export hash */ +struct rhlist_head exp_nid_hash;/** nid-export hash */ struct hlist_node exp_gen_hash;/** last_rcvd clt gen hash */ /** * All exports eligible for ping evictor are linked into a list lustre/include/obd.h +7
-1@@ -639,7 +639,7 @@ struct obd_device {/* uuid-export hash body */ struct cfs_hash *obd_uuid_hash;/* nid-export hash body */ -struct cfs_hash *obd_nid_hash; +struct rhltable obd_nid_hash;/* nid stats body */ struct cfs_hash *obd_nid_stats_hash;/* client_generation-export hash body */ @@ -750,6 +750,12 @@ struct obd_device {struct completion obd_kobj_unregister; }; +int obd_nid_export_for_each (struct obd_device *obd,lnet_nid_t nid, +int cb (struct obd_export *exp,void *data), +void *data); +int obd_nid_add (struct obd_device *obd,struct obd_export *exp); +void obd_nid_del (struct obd_device *obd,struct obd_export *exp); +/* get/set_info keys */ #define KEY_ASYNC "async"#define KEY_CHANGELOG_CLEAR "changelog_clear"lustre/include/obd_support.h +0
-3@@ -78,9 +78,6 @@ extern char obd_jobid_var[];#define HASH_UUID_BKT_BITS 5#define HASH_UUID_CUR_BITS 7#define HASH_UUID_MAX_BITS 12 -#define HASH_NID_BKT_BITS 5 -#define HASH_NID_CUR_BITS 7 -#define HASH_NID_MAX_BITS 12#define HASH_NID_STATS_BKT_BITS 5#define HASH_NID_STATS_CUR_BITS 7#define HASH_NID_STATS_MAX_BITS 12lustre/ldlm/ldlm_flock.c +0
-0
lustre/ldlm/ldlm_flock.c ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags) · line 164
Quoted 5 lines
lustre/ldlm/ldlm_flock.c +1
-1@@ -161,20 +161,18 @@ ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags)*/ struct ldlm_flock_lookup_cb_data { -__u64 *bl_owner; +u64 *bl_owner;
Arrrggg. Please don't do this.
lustre/ldlm/ldlm_flock.c ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags) · line 175
Quoted 3 lines
lustre/ldlm/ldlm_flock.c +1
-1lock =cfs_hash_lookup (exp->exp_flock_hash, cb_data->bl_owner); -if (lock ==NULL ) +if (!lock)
Or this.
If you want to fix up this stuff, do it in a separate patch. A patch should just do one thing.
I would actually prefer that the "add compatibilty code so we can use rhltables in old kernels" was a separate patch from "use rhltables for obd_nid_hash", but at least those two are conceptually related.
It is much harder to read a patch if I keep having to say to myself "Oh, that change is irrelevant here, I can ignore it".
Thanks,
NeilBrown
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20181102/8d11f411/attachment.sig>
RFC PATCH 1/1 lustre: obd: convert obd_nid_hash to rhashtable
Quoted 245 lines
Quoted 231 lines
This patch converts the struct
obd_exportobd_nid_hashused by the servr to use rhltables. The reason is that the NID hash can have multiple obd exports using the same NID key. In the process we gain lockless lookup which should improve performance. This should also address the rare crashes:[<
ffffffffc0913388>] ?cfs_hash_bd_from_key+0x38/0xb0[libcfs][74844.507416] [<ffffffffc0913425>] cfs_hash_bd_get+0x25/0x70 [libcfs] [74844.516384] [<ffffffffc09166d2>] cfs_hash_add+0x52/0x1a0 [libcfs] [74844.525211] [<ffffffffc0d8a765>] target_handle_connect+0x1fe5/0x29b0 [ptlrpc]Pre 4.8 kernels do not support rhltables so wrappers have been created.
***
My testing has been positive so far but I do need to figure out the debugfs file mapping from the old libcfs hash to rhashtables.***
Signed-off-by James Simmons <[email protected]>--- libcfs/autoconf/lustre-libcfs.m4 | 21 +++ libcfs/include/libcfs/linux/linux-hash.h | 88 ++++++++++++ lustre/include/lustre_export.h | 2 +- lustre/include/obd.h | 8 +- lustre/include/obd_support.h | 3 - lustre/ldlm/ldlm_flock.c | 18 ++- lustre/ldlm/ldlm_lib.c | 14 +- lustre/mdt/mdt_lproc.c | 21 ++- lustre/obdclass/genops.c | 76 ++++++----- lustre/obdclass/lprocfs_status_server.c | 133 +++++++++++------- lustre/obdclass/obd_config.c | 225 ++++++++++++++++++------------- 11 files changed, 394 insertions(+), 215 deletions(-)libcfs/autoconf/lustre-libcfs.m4 +21
-0@@ -761,6 +761,26 @@ LB_CHECK_LINUX_HEADER([linux/stringhash.h], [ ]) # LIBCFS_STRINGHASH # +# LIBCFS_RHLTABLE +# Kernel version 4.8 commit ca26893f05e86497a86732768ec53cd38c0819ca +# created the rhlist interface to allow inserting duplicate objects +# into the same table. +# +AC_DEFUN([LIBCFS_RHLTABLE], [ +LB_CHECK_COMPILE([if 'struct rhltable' exist], +rhtable, [ + #include <linux/rhashtable.h> +],[ + struct rhltable *hlt = NULL; + + rhltable_destroy(hlt); +],[ + AC_DEFINE(HAVE_RHLTABLE, 1, + [struct rhltable exist]) +]) +]) # LIBCFS_RHLTABLE + +# # LIBCFS_STACKTRACE_OPS # # Kernel version 4.8 commit c8fe4609827aedc9c4b45de80e7cdc8ccfa8541b@@ -999,6 +1019,7 @@ LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT LIBCFS_GET_USER_PAGES_6ARG LIBCFS_STRINGHASH # 4.8 +LIBCFS_RHLTABLE LIBCFS_STACKTRACE_OPS # 4.9 LIBCFS_GET_USER_PAGES_GUP_FLAGSlibcfs/include/libcfs/linux/linux-hash.h +88
-0@@ -38,6 +38,94 @@ u64 cfs_hashlen_string(const void *salt, const char *name);#endif #endif /* !HAVE_STRINGHASH */ +#ifndef HAVE_RHLTABLE +struct rhlist_head { +struct rhash_head rhead; +struct rhlist_head __rcu *next; +}; + +struct rhltable { +struct rhashtable ht; +}; + +#define rhl_for_each_entry_rcu (tpos, pos, list, member) \ + for (pos = list; pos && rht_entry(tpos, pos, member); \ + pos = rcu_dereference_raw(pos->next)) + +static inline int rhltable_init (struct rhltable *hlt,const struct rhashtable_params *params) +{ +return rhashtable_init (&hlt->ht, params); +} + +static inline struct rhlist_head *rhltable_lookup ( +struct rhltable *hlt,const void *key, +const struct rhashtable_params params) +{ +struct rhashtable *ht = &hlt->ht; +struct rhashtable_compare_arg arg = { + .ht = ht, + .key = key, + }; +struct bucket_table *tbl; +struct rhash_head *he; +unsigned int hash; + + tbl =rht_dereference_rcu (ht->tbl, ht); +restart: + hash =rht_key_hashfn (ht, tbl, key, params); +rht_for_each_rcu (he, tbl, hash) { +if (params.obj_cmpfn ? + params.obj_cmpfn (&arg,rht_obj (ht, he)) : +rhashtable_compare (&arg,rht_obj (ht, he))) +continue ; + return he ? container_of(he, struct rhlist_head, rhead) : NULL; + } + +/* Ensure we see any new tables. */ +smp_rmb (); + + tbl =rht_dereference_rcu (tbl->future_tbl, ht); +if (unlikely (tbl)) + goto restart; + +return NULL ; +} + +static inline int rhltable_insert_key ( +struct rhltable *hlt,const void *key,struct rhlist_head *list, +const struct rhashtable_params params) +{ +return PTR_ERR (__rhashtable_insert_fast (&hlt->ht, key, &list->rhead, + params)); +} + +static inline int rhltable_remove ( +struct rhltable *hlt,struct rhlist_head *list, +const struct rhashtable_params params) +{ +return rhashtable_remove_fast (&hlt->ht, &list->rhead, params); +} + +static inline void rhltable_free_and_destroy (struct rhltable *hlt, +void (*free_fn)(void *ptr, +void *arg), +void *arg) +{ +return rhashtable_free_and_destroy (&hlt->ht, free_fn, arg); +} + +static inline void rhltable_destroy (struct rhltable *hlt) +{ +return rhltable_free_and_destroy (hlt,NULL ,NULL ); +} + +static inline void rhltable_walk_enter (struct rhltable *hlt, +struct rhashtable_iter *iter) +{ +rhashtable_walk_init (&hlt->ht, iter); +} +#endif /* !HAVE_RHLTABLE */ +#ifndef HAVE_RHASHTABLE_LOOKUP_GET_INSERT_FAST /** * rhashtable_lookup_get_insert_fast - lookup and insert object into hash table lustre/include/lustre_export.h +1
-1@@ -209,7 +209,7 @@ struct obd_export {/* Unlinked export list */ struct list_head exp_stale_list;struct hlist_node exp_uuid_hash;/** uuid-export hash*/ -struct hlist_node exp_nid_hash;/** nid-export hash */ +struct rhlist_head exp_nid_hash;/** nid-export hash */ struct hlist_node exp_gen_hash;/** last_rcvd clt gen hash */ /** * All exports eligible for ping evictor are linked into a list lustre/include/obd.h +7
-1@@ -639,7 +639,7 @@ struct obd_device {/* uuid-export hash body */ struct cfs_hash *obd_uuid_hash;/* nid-export hash body */ -struct cfs_hash *obd_nid_hash; +struct rhltable obd_nid_hash;/* nid stats body */ struct cfs_hash *obd_nid_stats_hash;/* client_generation-export hash body */ @@ -750,6 +750,12 @@ struct obd_device {struct completion obd_kobj_unregister; }; +int obd_nid_export_for_each (struct obd_device *obd,lnet_nid_t nid, +int cb (struct obd_export *exp,void *data), +void *data); +int obd_nid_add (struct obd_device *obd,struct obd_export *exp); +void obd_nid_del (struct obd_device *obd,struct obd_export *exp); +/* get/set_info keys */ #define KEY_ASYNC "async"#define KEY_CHANGELOG_CLEAR "changelog_clear"lustre/include/obd_support.h +0
-3@@ -78,9 +78,6 @@ extern char obd_jobid_var[];#define HASH_UUID_BKT_BITS 5#define HASH_UUID_CUR_BITS 7#define HASH_UUID_MAX_BITS 12 -#define HASH_NID_BKT_BITS 5 -#define HASH_NID_CUR_BITS 7 -#define HASH_NID_MAX_BITS 12#define HASH_NID_STATS_BKT_BITS 5#define HASH_NID_STATS_CUR_BITS 7#define HASH_NID_STATS_MAX_BITS 12lustre/ldlm/ldlm_flock.c +0
-0lustre/ldlm/ldlm_flock.c ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags) · line 164
Quoted 5 lines
lustre/ldlm/ldlm_flock.c +1
-1@@ -161,20 +161,18 @@ ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags)*/ struct ldlm_flock_lookup_cb_data { -__u64 *bl_owner; +u64 *bl_owner;Arrrggg. Please don't do this.
lustre/ldlm/ldlm_flock.c ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags) · line 175
Quoted 3 lines
lustre/ldlm/ldlm_flock.c +1
-1lock =cfs_hash_lookup (exp->exp_flock_hash, cb_data->bl_owner); -if (lock ==NULL ) +if (!lock)Or this.
Quoted 8 lines
If you want to fix up this stuff, do it in a separate patch. A patch should just do one thing.
I would actually prefer that the "add compatibilty code so we can use rhltables in old kernels" was a separate patch from "use rhltables forobd_nid_hash", but at least those two are conceptually related.It is much harder to read a patch if I keep having to say to myself "Oh, that change is irrelevant here, I can ignore it".
This is a pretty big patch for email review so I will break it up. I think it can be more than 2 and it doesn't matter for buildable from patch to patch since this us just for review.
RFC PATCH 1/1 lustre: obd: convert obd_nid_hash to rhashtable
Quoted 250 lines · James Simmons
Quoted 250 lines
Quoted 230 lines
This patch converts the struct
obd_exportobd_nid_hashused by the servr to use rhltables. The reason is that the NID hash can have multiple obd exports using the same NID key. In the process we gain lockless lookup which should improve performance. This should also address the rare crashes:[<
ffffffffc0913388>] ?cfs_hash_bd_from_key+0x38/0xb0[libcfs][74844.507416] [<ffffffffc0913425>] cfs_hash_bd_get+0x25/0x70 [libcfs] [74844.516384] [<ffffffffc09166d2>] cfs_hash_add+0x52/0x1a0 [libcfs] [74844.525211] [<ffffffffc0d8a765>] target_handle_connect+0x1fe5/0x29b0 [ptlrpc]Pre 4.8 kernels do not support rhltables so wrappers have been created.
***
My testing has been positive so far but I do need to figure out the debugfs file mapping from the old libcfs hash to rhashtables.***
Signed-off-by James Simmons <[email protected]>--- libcfs/autoconf/lustre-libcfs.m4 | 21 +++ libcfs/include/libcfs/linux/linux-hash.h | 88 ++++++++++++ lustre/include/lustre_export.h | 2 +- lustre/include/obd.h | 8 +- lustre/include/obd_support.h | 3 - lustre/ldlm/ldlm_flock.c | 18 ++- lustre/ldlm/ldlm_lib.c | 14 +- lustre/mdt/mdt_lproc.c | 21 ++- lustre/obdclass/genops.c | 76 ++++++----- lustre/obdclass/lprocfs_status_server.c | 133 +++++++++++------- lustre/obdclass/obd_config.c | 225 ++++++++++++++++++------------- 11 files changed, 394 insertions(+), 215 deletions(-)libcfs/autoconf/lustre-libcfs.m4 +21
-0@@ -761,6 +761,26 @@ LB_CHECK_LINUX_HEADER([linux/stringhash.h], [ ]) # LIBCFS_STRINGHASH # +# LIBCFS_RHLTABLE +# Kernel version 4.8 commit ca26893f05e86497a86732768ec53cd38c0819ca +# created the rhlist interface to allow inserting duplicate objects +# into the same table. +# +AC_DEFUN([LIBCFS_RHLTABLE], [ +LB_CHECK_COMPILE([if 'struct rhltable' exist], +rhtable, [ + #include <linux/rhashtable.h> +],[ + struct rhltable *hlt = NULL; + + rhltable_destroy(hlt); +],[ + AC_DEFINE(HAVE_RHLTABLE, 1, + [struct rhltable exist]) +]) +]) # LIBCFS_RHLTABLE + +# # LIBCFS_STACKTRACE_OPS # # Kernel version 4.8 commit c8fe4609827aedc9c4b45de80e7cdc8ccfa8541b@@ -999,6 +1019,7 @@ LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT LIBCFS_GET_USER_PAGES_6ARG LIBCFS_STRINGHASH # 4.8 +LIBCFS_RHLTABLE LIBCFS_STACKTRACE_OPS # 4.9 LIBCFS_GET_USER_PAGES_GUP_FLAGSlibcfs/include/libcfs/linux/linux-hash.h +88
-0@@ -38,6 +38,94 @@ u64 cfs_hashlen_string(const void *salt, const char *name);#endif #endif /* !HAVE_STRINGHASH */ +#ifndef HAVE_RHLTABLE +struct rhlist_head { +struct rhash_head rhead; +struct rhlist_head __rcu *next; +}; + +struct rhltable { +struct rhashtable ht; +}; + +#define rhl_for_each_entry_rcu (tpos, pos, list, member) \ + for (pos = list; pos && rht_entry(tpos, pos, member); \ + pos = rcu_dereference_raw(pos->next)) + +static inline int rhltable_init (struct rhltable *hlt,const struct rhashtable_params *params) +{ +return rhashtable_init (&hlt->ht, params); +} + +static inline struct rhlist_head *rhltable_lookup ( +struct rhltable *hlt,const void *key, +const struct rhashtable_params params) +{ +struct rhashtable *ht = &hlt->ht; +struct rhashtable_compare_arg arg = { + .ht = ht, + .key = key, + }; +struct bucket_table *tbl; +struct rhash_head *he; +unsigned int hash; + + tbl =rht_dereference_rcu (ht->tbl, ht); +restart: + hash =rht_key_hashfn (ht, tbl, key, params); +rht_for_each_rcu (he, tbl, hash) { +if (params.obj_cmpfn ? + params.obj_cmpfn (&arg,rht_obj (ht, he)) : +rhashtable_compare (&arg,rht_obj (ht, he))) +continue ; + return he ? container_of(he, struct rhlist_head, rhead) : NULL; + } + +/* Ensure we see any new tables. */ +smp_rmb (); + + tbl =rht_dereference_rcu (tbl->future_tbl, ht); +if (unlikely (tbl)) + goto restart; + +return NULL ; +} + +static inline int rhltable_insert_key ( +struct rhltable *hlt,const void *key,struct rhlist_head *list, +const struct rhashtable_params params) +{ +return PTR_ERR (__rhashtable_insert_fast (&hlt->ht, key, &list->rhead, + params)); +} + +static inline int rhltable_remove ( +struct rhltable *hlt,struct rhlist_head *list, +const struct rhashtable_params params) +{ +return rhashtable_remove_fast (&hlt->ht, &list->rhead, params); +} + +static inline void rhltable_free_and_destroy (struct rhltable *hlt, +void (*free_fn)(void *ptr, +void *arg), +void *arg) +{ +return rhashtable_free_and_destroy (&hlt->ht, free_fn, arg); +} + +static inline void rhltable_destroy (struct rhltable *hlt) +{ +return rhltable_free_and_destroy (hlt,NULL ,NULL ); +} + +static inline void rhltable_walk_enter (struct rhltable *hlt, +struct rhashtable_iter *iter) +{ +rhashtable_walk_init (&hlt->ht, iter); +} +#endif /* !HAVE_RHLTABLE */ +#ifndef HAVE_RHASHTABLE_LOOKUP_GET_INSERT_FAST /** * rhashtable_lookup_get_insert_fast - lookup and insert object into hash table lustre/include/lustre_export.h +1
-1@@ -209,7 +209,7 @@ struct obd_export {/* Unlinked export list */ struct list_head exp_stale_list;struct hlist_node exp_uuid_hash;/** uuid-export hash*/ -struct hlist_node exp_nid_hash;/** nid-export hash */ +struct rhlist_head exp_nid_hash;/** nid-export hash */ struct hlist_node exp_gen_hash;/** last_rcvd clt gen hash */ /** * All exports eligible for ping evictor are linked into a list lustre/include/obd.h +7
-1@@ -639,7 +639,7 @@ struct obd_device {/* uuid-export hash body */ struct cfs_hash *obd_uuid_hash;/* nid-export hash body */ -struct cfs_hash *obd_nid_hash; +struct rhltable obd_nid_hash;/* nid stats body */ struct cfs_hash *obd_nid_stats_hash;/* client_generation-export hash body */ @@ -750,6 +750,12 @@ struct obd_device {struct completion obd_kobj_unregister; }; +int obd_nid_export_for_each (struct obd_device *obd,lnet_nid_t nid, +int cb (struct obd_export *exp,void *data), +void *data); +int obd_nid_add (struct obd_device *obd,struct obd_export *exp); +void obd_nid_del (struct obd_device *obd,struct obd_export *exp); +/* get/set_info keys */ #define KEY_ASYNC "async"#define KEY_CHANGELOG_CLEAR "changelog_clear"lustre/include/obd_support.h +0
-3@@ -78,9 +78,6 @@ extern char obd_jobid_var[];#define HASH_UUID_BKT_BITS 5#define HASH_UUID_CUR_BITS 7#define HASH_UUID_MAX_BITS 12 -#define HASH_NID_BKT_BITS 5 -#define HASH_NID_CUR_BITS 7 -#define HASH_NID_MAX_BITS 12#define HASH_NID_STATS_BKT_BITS 5#define HASH_NID_STATS_CUR_BITS 7#define HASH_NID_STATS_MAX_BITS 12lustre/ldlm/ldlm_flock.c +0
-0lustre/ldlm/ldlm_flock.c ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags) · line 164
Quoted 5 lines
lustre/ldlm/ldlm_flock.c +1
-1@@ -161,20 +161,18 @@ ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags)*/ struct ldlm_flock_lookup_cb_data { -__u64 *bl_owner; +u64 *bl_owner;Arrrggg. Please don't do this.
lustre/ldlm/ldlm_flock.c ldlm_flock_destroy(struct ldlm_lock *lock, enum ldlm_mode mode, __u64 flags) · line 175
Quoted 3 lines
lustre/ldlm/ldlm_flock.c +1
-1lock =cfs_hash_lookup (exp->exp_flock_hash, cb_data->bl_owner); -if (lock ==NULL ) +if (!lock)Or this.
If you want to fix up this stuff, do it in a separate patch. A patch should just do one thing.
I would actually prefer that the "add compatibilty code so we can use rhltables in old kernels" was a separate patch from "use rhltables forobd_nid_hash", but at least those two are conceptually related.
Quoted 6 lines
Quoted 2 lines
It is much harder to read a patch if I keep having to say to myself "Oh, that change is irrelevant here, I can ignore it".
This is a pretty big patch for email review so I will break it up. I think it can be more than 2 and it doesn't matter for buildable from patch to patch since this us just for review.
I don't accept that there is a distinction between "For review" and "for use". The patches as reviewed much be exactly the patches that get applied.
It does take a little more work to make sure that you can build and test after each patch, but it is only a little. Often the early patches introduce functionality that is not immediately used, then the later patches use it. Very rarely you might need to leave off a "static" declaration, so the code will build even though the function isn't used.
Thanks,
NeilBrown
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20181105/f28fd5c1/attachment.sig>