From 48830f888b651c32bfe4742f3d03fd04b15638a9 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 30 Sep 2019 20:58:55 -0400 Subject: [PATCH] LU-12542 handle: discard OBD_FREE_RCU OBD_FREE_RCU and the hop_free call-back together form an overly complex mechanism equivalent to kfree_rcu() or call_rcu(...). Discard them and use the simpler approach. This removes the only use for the field h_size, so discard that too. Change-Id: I3b4135565dab6a9aa5034f42ae3f9b66851cae31 Signed-off-by: NeilBrown Reviewed-on: https://review.whamcloud.com/35797 Reviewed-by: Neil Brown Reviewed-by: Mike Pershin Reviewed-by: Andreas Dilger Reviewed-by: Shaun Tancheff Reviewed-by: Petros Koutoupis Tested-by: jenkins Tested-by: Maloo --- lustre/include/lustre_handles.h | 3 --- lustre/include/obd_support.h | 17 ++++------------- lustre/ldlm/ldlm_lock.c | 18 ++++++++++-------- lustre/mdt/mdt_open.c | 4 ++-- lustre/obdclass/genops.c | 4 ++-- lustre/obdclass/lustre_handles.c | 15 --------------- 6 files changed, 18 insertions(+), 43 deletions(-) diff --git a/lustre/include/lustre_handles.h b/lustre/include/lustre_handles.h index c7f316d..511a2f6 100644 --- a/lustre/include/lustre_handles.h +++ b/lustre/include/lustre_handles.h @@ -48,7 +48,6 @@ #include struct portals_handle_ops { - void (*hop_free)(void *object, int size); /* hop_type is used for some debugging messages */ char *hop_type; }; @@ -73,7 +72,6 @@ struct portals_handle { /* newly added fields to handle the RCU issue. -jxiong */ struct rcu_head h_rcu; spinlock_t h_lock; - unsigned int h_size:31; unsigned int h_in:1; }; @@ -84,7 +82,6 @@ void class_handle_hash(struct portals_handle *, const struct portals_handle_ops *ops); void class_handle_unhash(struct portals_handle *); void *class_handle2object(u64 cookie, const struct portals_handle_ops *ops); -void class_handle_free_cb(struct rcu_head *rcu); int class_handle_init(void); void class_handle_cleanup(void); diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h index cc154f7..b81d22a 100644 --- a/lustre/include/obd_support.h +++ b/lustre/include/obd_support.h @@ -767,8 +767,7 @@ static inline void obd_memory_sub(long size) LASSERT(ptr); \ obd_memory_sub(size); \ CDEBUG(D_MALLOC, name " '" #ptr "': %d at %p.\n", \ - (int)(size), ptr); \ - POISON(ptr, 0x5a, size) + (int)(size), ptr); #else /* !OBD_DEBUG_MEMUSAGE */ @@ -866,6 +865,7 @@ do { \ #define OBD_FREE(ptr, size) \ do { \ OBD_FREE_PRE(ptr, size, "kfreed"); \ + POISON(ptr, 0x5a, size); \ kfree(ptr); \ POISON_PTR(ptr); \ } while (0) @@ -874,6 +874,7 @@ do { \ do { \ if (is_vmalloc_addr(ptr)) { \ OBD_FREE_PRE(ptr, size, "vfreed"); \ + POISON(ptr, 0x5a, size); \ vfree(ptr); \ POISON_PTR(ptr); \ } else { \ @@ -881,17 +882,6 @@ do { \ } \ } while (0) -#define OBD_FREE_RCU(ptr, size, handle) \ -do { \ - struct portals_handle *__h = (handle); \ - \ - LASSERT(handle != NULL); \ - __h->h_cookie = (unsigned long)(ptr); \ - __h->h_size = (size); \ - call_rcu(&__h->h_rcu, class_handle_free_cb); \ - POISON_PTR(ptr); \ -} while(0) - /* we memset() the slab object to 0 when allocation succeeds, so DO NOT * HAVE A CTOR THAT DOES ANYTHING. its work will be cleared here. we'd * love to assert on that, but slab.c keeps kmem_cache_s all to itself. */ @@ -922,6 +912,7 @@ do { \ #define OBD_SLAB_FREE(ptr, slab, size) \ do { \ OBD_FREE_PRE(ptr, size, "slab-freed"); \ + POISON(ptr, 0x5a, size); \ kmem_cache_free(slab, ptr); \ POISON_PTR(ptr); \ } while(0) diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c index b8e3989..2de1815 100644 --- a/lustre/ldlm/ldlm_lock.c +++ b/lustre/ldlm/ldlm_lock.c @@ -190,6 +190,15 @@ struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock) } EXPORT_SYMBOL(ldlm_lock_get); +static void lock_handle_free(struct rcu_head *rcu) +{ + struct ldlm_lock *lock = container_of(rcu, struct ldlm_lock, + l_handle.h_rcu); + + OBD_FREE_PRE(lock, sizeof(*lock), "slab-freed"); + kmem_cache_free(ldlm_lock_slab, lock); +} + /** * Release lock reference. * @@ -234,7 +243,7 @@ void ldlm_lock_put(struct ldlm_lock *lock) ldlm_resource_putref(res); lock->l_resource = NULL; lu_ref_fini(&lock->l_reference); - OBD_FREE_RCU(lock, sizeof(*lock), &lock->l_handle); + call_rcu(&lock->l_handle.h_rcu, lock_handle_free); } EXIT; @@ -438,14 +447,7 @@ void ldlm_lock_destroy_nolock(struct ldlm_lock *lock) EXIT; } -static void lock_handle_free(void *lock, int size) -{ - LASSERT(size == sizeof(struct ldlm_lock)); - OBD_SLAB_FREE(lock, ldlm_lock_slab, size); -} - static struct portals_handle_ops lock_handle_ops = { - .hop_free = lock_handle_free, .hop_type = "ldlm", }; diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index c13fe07..c364925 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -45,7 +45,6 @@ #include static const struct portals_handle_ops mfd_open_handle_ops = { - .hop_free = NULL, .hop_type = "mdt", }; @@ -104,7 +103,8 @@ void mdt_mfd_free(struct mdt_file_data *mfd) { LASSERT(refcount_read(&mfd->mfd_open_handle.h_ref) == 1); LASSERT(list_empty(&mfd->mfd_list)); - OBD_FREE_RCU(mfd, sizeof *mfd, &mfd->mfd_open_handle); + OBD_FREE_PRE(mfd, sizeof(*mfd), "rcu"); + kfree_rcu(mfd, mfd_open_handle.h_rcu); } static int mdt_create_data(struct mdt_thread_info *info, diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 1a635f3..0d670da 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -966,12 +966,12 @@ static void class_export_destroy(struct obd_export *exp) if (exp != obd->obd_self_export) class_decref(obd, "export", exp); - OBD_FREE_RCU(exp, sizeof(*exp), &exp->exp_handle); + OBD_FREE_PRE(exp, sizeof(*exp), "rcu"); + kfree_rcu(exp, exp_handle.h_rcu); EXIT; } static struct portals_handle_ops export_handle_ops = { - .hop_free = NULL, .hop_type = "export", }; diff --git a/lustre/obdclass/lustre_handles.c b/lustre/obdclass/lustre_handles.c index 75987f1..40d69186 100644 --- a/lustre/obdclass/lustre_handles.c +++ b/lustre/obdclass/lustre_handles.c @@ -173,21 +173,6 @@ void *class_handle2object(u64 cookie, const struct portals_handle_ops *ops) } EXPORT_SYMBOL(class_handle2object); -void class_handle_free_cb(struct rcu_head *rcu) -{ - struct portals_handle *h; - void *ptr; - - h = container_of(rcu, struct portals_handle, h_rcu); - ptr = (void *)(unsigned long)h->h_cookie; - - if (h->h_ops->hop_free != NULL) - h->h_ops->hop_free(ptr, h->h_size); - else - OBD_FREE(ptr, h->h_size); -} -EXPORT_SYMBOL(class_handle_free_cb); - int class_handle_init(void) { struct handle_bucket *bucket; -- 1.8.3.1