RDMA/mlx5: Cleanup the synchronize_srcu() from the ODP flow
Subsystems (5)
PATCH 1/1 RDMA/mlx5: Cleanup the synchronize_srcu() from the ODP flow
From: Yishai Hadas <[email protected]>
Cleanup the synchronize_srcu() from the ODP flow as it was found to be a very heavy time consumer as part of dereg_mr.
For example de-registration of 10000 ODP MRs each with size of 2M hugepage took 19.6 sec comparing de-registration of same number of non ODP MRs that took 172 ms.
The new locking scheme uses the wait_event() mechanism which follows the use count of the MR instead of using synchronize_srcu().
By that change, the time required for the above test took 95 ms which is even better than the non ODP flow.
Once fully dropped the srcu usage, had to come with a lock to protect the XA access.
As part of using the above mechanism we could also clean the num_deferred_work stuff and follow the use count instead.
---
Changelog:
v1:
* Deleted not-relevant comment implicit_get_child_mr(), I have no idea why wrong version of this patch was sent as v0.
* Deleted two new break lines added by me to make code more uniformly in before "return ..." (sometimes it has new line, sometimes doesn't).
v0: https://lore.kernel.org/linux-rdma/[email protected]
--- drivers/infiniband/hw/mlx5/devx.c | 6 +- drivers/infiniband/hw/mlx5/main.c | 5 - drivers/infiniband/hw/mlx5/mlx5_ib.h | 31 ++- drivers/infiniband/hw/mlx5/mr.c | 21 +- drivers/infiniband/hw/mlx5/odp.c | 220 ++++++++----------- drivers/net/ethernet/mellanox/mlx5/core/mr.c | 1 + include/linux/mlx5/driver.h | 2 + 7 files changed, 122 insertions(+), 164 deletions(-)
drivers/infiniband/hw/mlx5/devx.c +3 -3
@@ -1310,9 +1310,9 @@ static int devx_handle_mkey_indirect(struct devx_obj *obj, mkey->size =MLX5_GET64 (mkc, mkc, len); mkey->pd =MLX5_GET (mkc, mkc, pd); devx_mr->ndescs =MLX5_GET (mkc, mkc, translations_octword_size); +init_waitqueue_head (&mkey->wait); -return xa_err (xa_store (&dev->odp_mkeys,mlx5_base_mkey (mkey->key), mkey, -GFP_KERNEL )); +return mlx5r_store_odp_mkey (dev, mkey); } static int devx_handle_mkey_create(struct mlx5_ib_dev *dev,
@@ -1393,7 +1393,7 @@ static int devx_obj_cleanup(struct ib_uobject *uobject,*/ xa_erase (&obj->ib_dev->odp_mkeys,mlx5_base_mkey (obj->devx_mr.mmkey.key)); -synchronize_srcu (&dev->odp_srcu); +mlx5r_deref_wait_odp_mkey (&obj->devx_mr.mmkey); }if (obj->flags &DEVX_OBJ_FLAGS_DCT )
drivers/infiniband/hw/mlx5/main.c +0 -5
@@ -3953,7 +3953,6 @@ static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) {mlx5_ib_cleanup_multiport_master (dev);WARN_ON (!xa_empty (&dev->odp_mkeys)); -cleanup_srcu_struct (&dev->odp_srcu);mutex_destroy (&dev->cap_mask_mutex);WARN_ON (!xa_empty (&dev->sig_mrs));WARN_ON (!bitmap_empty (dev->dm.memic_alloc_pages,MLX5_MAX_MEMIC_PAGES ));
@@ -4005,10 +4004,6 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev) dev->ib_dev.dev.parent = mdev->device; dev->ib_dev.lag_flags =RDMA_LAG_FLAGS_HASH_ALL_SLAVES ; - err =init_srcu_struct (&dev->odp_srcu); -if (err) - goto err_mp; -mutex_init (&dev->cap_mask_mutex);INIT_LIST_HEAD (&dev->qp_list);spin_lock_init (&dev->reset_flow_resource_lock);
drivers/infiniband/hw/mlx5/mlx5_ib.h +23 -8
@@ -684,11 +684,8 @@ struct mlx5_ib_mr {u64 pi_iova;/* For ODP and implicit */ -atomic_t num_deferred_work; -wait_queue_head_t q_deferred_work;struct xarray implicit_children;union { -struct rcu_head rcu;struct list_head elm;struct work_struct work; } odp_destroy;
@@ -1063,11 +1060,6 @@ struct mlx5_ib_dev {u64 odp_max_size;struct mlx5_ib_pf_eq odp_pf_eq; -/* -* Sleepable RCU that prevents destruction of MRs while they are still -* being used by a page fault handler. -*/ -struct srcu_struct odp_srcu;struct xarray odp_mkeys;u32 null_mkey;
@@ -1592,6 +1584,29 @@ static inline bool mlx5_ib_can_reconfig_with_umr(struct mlx5_ib_dev *dev,return true; } +static inline int mlx5r_store_odp_mkey (struct mlx5_ib_dev *dev, +struct mlx5_core_mkey *mmkey) +{ +refcount_set (&mmkey->usecount,1 ); + +return xa_err (xa_store (&dev->odp_mkeys,mlx5_base_mkey (mmkey->key), + mmkey,GFP_KERNEL )); +} + +/* deref an mkey that can participate in ODP flow */ +static inline void mlx5r_deref_odp_mkey (struct mlx5_core_mkey *mmkey) +{ +if (refcount_dec_and_test (&mmkey->usecount)) +wake_up (&mmkey->wait); +} + +/* deref an mkey that can participate in ODP flow and wait for relese */ +static inline void mlx5r_deref_wait_odp_mkey (struct mlx5_core_mkey *mmkey) +{ +mlx5r_deref_odp_mkey (mmkey); +wait_event (mmkey->wait,refcount_read (&mmkey->usecount) ==0 ); +} +int mlx5_ib_test_wc (struct mlx5_ib_dev *dev);static inline bool mlx5_ib_lag_should_assign_affinity (struct mlx5_ib_dev *dev)
drivers/infiniband/hw/mlx5/mr.c +7 -14
@@ -159,6 +159,7 @@ static void create_mkey_callback(int status, struct mlx5_async_work *context) mr->mmkey.type =MLX5_MKEY_MR ; mr->mmkey.key |=mlx5_idx_to_mkey (MLX5_GET (create_mkey_out, mr->out, mkey_index)); +init_waitqueue_head (&mr->mmkey.wait);WRITE_ONCE (dev->cache.last_add, jiffies);
@@ -1558,10 +1559,7 @@ static struct ib_mr *create_user_odp_mr(struct ib_pd *pd, u64 start, u64 length, } odp->private = mr; -init_waitqueue_head (&mr->q_deferred_work); -atomic_set (&mr->num_deferred_work,0 ); - err =xa_err (xa_store (&dev->odp_mkeys,mlx5_base_mkey (mr->mmkey.key), - &mr->mmkey,GFP_KERNEL )); + err =mlx5r_store_odp_mkey (dev, &mr->mmkey);if (err) goto err_dereg_mr;
@@ -1659,10 +1657,7 @@ struct ib_mr *mlx5_ib_reg_user_mr_dmabuf(struct ib_pd *pd, u64 offset,atomic_add (ib_umem_num_pages (mr->umem), &dev->mdev->priv.reg_pages); umem_dmabuf->private = mr; -init_waitqueue_head (&mr->q_deferred_work); -atomic_set (&mr->num_deferred_work,0 ); - err =xa_err (xa_store (&dev->odp_mkeys,mlx5_base_mkey (mr->mmkey.key), - &mr->mmkey,GFP_KERNEL )); + err =mlx5r_store_odp_mkey (dev, &mr->mmkey);if (err) goto err_dereg_mr;
@@ -2343,9 +2338,7 @@ int mlx5_ib_alloc_mw(struct ib_mw *ibmw, struct ib_udata *udata) }if (IS_ENABLED (CONFIG_INFINIBAND_ON_DEMAND_PAGING )) { - err =xa_err (xa_store (&dev->odp_mkeys, -mlx5_base_mkey (mw->mmkey.key), &mw->mmkey, -GFP_KERNEL )); + err =mlx5r_store_odp_mkey (dev, &mw->mmkey);if (err) goto free_mkey; }
@@ -2368,10 +2361,10 @@ int mlx5_ib_dealloc_mw(struct ib_mw *mw)if (IS_ENABLED (CONFIG_INFINIBAND_ON_DEMAND_PAGING )) {xa_erase (&dev->odp_mkeys,mlx5_base_mkey (mmw->mmkey.key));/* -* pagefault_single_data_segment() may be accessing mmw under -* SRCU if the user bound an ODP MR to this MW. +* pagefault_single_data_segment() may be accessing mmw +* if the user bound an ODP MR to this MW. */ -synchronize_srcu (&dev->odp_srcu); +mlx5r_deref_wait_odp_mkey (&mmw->mmkey); }return mlx5_core_destroy_mkey (dev->mdev, &mmw->mmkey);
drivers/infiniband/hw/mlx5/odp.c +86 -134
541 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/mr.c +1 -0
@@ -56,6 +56,7 @@ int mlx5_core_create_mkey(struct mlx5_core_dev *dev, mkey->size =MLX5_GET64 (mkc, mkc, len); mkey->key |=mlx5_idx_to_mkey (mkey_index); mkey->pd =MLX5_GET (mkc, mkc, pd); +init_waitqueue_head (&mkey->wait);mlx5_core_dbg (dev,"out 0x%x, mkey 0x%x\n" , mkey_index, mkey->key);return 0 ;
include/linux/mlx5/driver.h +2 -0
@@ -373,6 +373,8 @@ struct mlx5_core_mkey {u32 key;u32 pd;u32 type; +struct wait_queue_head wait; +refcount_t usecount; };#define MLX5_24BIT_MASK ((1 << 24) - 1)
--
2.29.2
Jason Gunthorpe
maintainerQuoted 31 lines · Yishai Hadas
Quoted 13 lines · Saeed Mahameed
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/mr.c +2
-0+++ b/drivers/net/ethernet/mellanox/mlx5/core/mr.c@@ -56,6 +56,7 @@ int mlx5_core_create_mkey(struct mlx5_core_dev *dev, mkey->size = MLX5_GET64(mkc, mkc, len); mkey->key |= mlx5_idx_to_mkey(mkey_index); mkey->pd = MLX5_GET(mkc, mkc, pd); + init_waitqueue_head(&mkey->wait); mlx5_core_dbg(dev, "out 0x%x, mkey 0x%x\n", mkey_index, mkey-Quoted 1 line
key);
Quoted 17 lines
include/linux/mlx5/driver.h struct mlx5_core_mkey { · line 377
Quoted 11 lines
return 0;
include/linux/mlx5/driver.h +3
-0+++ b/include/linux/mlx5/driver.h@@ -373,6 +373,8 @@ struct mlx5_core_mkey { u32 key; u32 pd; u32 type; + struct wait_queue_head wait; + refcount_t usecount;
mlx5_core_mkeyis used everywhere inmlx5_coreand we don't care about odp complexity, i would like to keep the core simple and primitive as it is today.
please keep the layer separation and find a way to manage refcount and wait queue inmlx5_ibdriver..
Quoted 2 lines
The alternative could really be to come with some wrapped
mlx5_ibstructure that will hold 'mlx5_core_mkey' and will add those two fields.
Yes
struct mlx5_ib_mkey
{
struct mlx5_core_mkey mkey;
struct wait_queue_head wait;
refcount_t usecount;
}
struct mlx5_ib_mr/mw/devx
{
struct mlx5_ib_mkey mkey;
}The odp_mkeys XA will store pointers to mlx5_ib_mkey (not core_mkey) and container_of() to go back to the MW, devx or MR.
Quoted 3 lines
Having it per object (e.g.
mlx5_ib_mr,mlx5_ib_mw,mlx5_ib_devx_mr) increasing locking scope and branches on data path to find the refcount field per its 'type'. (seemlx5_core_mkey->type).
It is free, just use container_of, no change to locking/etc
Jason
Quoted 50 lines · Jason Gunthorpe
Quoted 36 lines · Yishai Hadas
Quoted 26 lines · Saeed Mahameed
Quoted 21 lines
drivers/net/ethernet/mellanox/mlx5/core/mr.c +1
-0+++ b/drivers/net/ethernet/mellanox/mlx5/core/mr.c@@ -56,6 +56,7 @@ int mlx5_core_create_mkey(struct
mlx5_core_dev
*dev,
mkey->size =MLX5_GET64(mkc, mkc, len);mkey->key|=mlx5_idx_to_mkey(mkey_index);mkey->pd=MLX5_GET(mkc, mkc, pd); + init_waitqueue_head(&mkey->wait);mlx5_core_dbg(dev, "out 0x%x, mkey 0x%x\n",
mkey_index, mkey-Quoted 1 line
key);
return 0;
include/linux/mlx5/driver.h +1
-0+++ b/include/linux/mlx5/driver.hinclude/linux/mlx5/driver.h struct mlx5_core_mkey { · line 377
Quoted 5 lines
include/linux/mlx5/driver.h +2
-0@@ -373,6 +373,8 @@ struct mlx5_core_mkey { u32 key; u32 pd; u32 type; + struct wait_queue_head wait; + refcount_t usecount;Quoted 9 lines
mlx5_core_mkeyis used everywhere inmlx5_coreand we don't care about
odp complexity, i would like to keep the core simple and primitive as
it is today.
please keep the layer separation and find a way to manage refcount and
wait queue inmlx5_ibdriver..Quoted 3 lines
The alternative could really be to come with some wrapped
mlx5_ibstructure
that will hold 'mlx5_core_mkey' and will add those two fields.Yes
struct
mlx5_ib_mkey
{
structmlx5_core_mkeymkey;
structwait_queue_headwait;
refcount_tusecount;
}
Quoted 5 lines
struct mlx5_ib_mr/mw/devx
{
structmlx5_ib_mkeymkey;
}
Yep, also i have a series internally that moves mlx5_core_mkey to mlx5_ib, in mlx5_core we don't need it we only need the u32 key :)
I will send you this series internally.
Quoted 57 lines · Saeed Mahameed
Quoted 50 lines · Jason Gunthorpe
Quoted 36 lines · Yishai Hadas
Quoted 26 lines · Saeed Mahameed
Quoted 21 lines
drivers/net/ethernet/mellanox/mlx5/core/mr.c +1
-0+++ b/drivers/net/ethernet/mellanox/mlx5/core/mr.c@@ -56,6 +56,7 @@ int mlx5_core_create_mkey(struct
mlx5_core_dev
*dev,
mkey->size =MLX5_GET64(mkc, mkc, len);mkey->key|=mlx5_idx_to_mkey(mkey_index);mkey->pd=MLX5_GET(mkc, mkc, pd); + init_waitqueue_head(&mkey->wait);mlx5_core_dbg(dev, "out 0x%x, mkey 0x%x\n",
mkey_index, mkey-Quoted 1 line
key);
return 0;
include/linux/mlx5/driver.h +1
-0+++ b/include/linux/mlx5/driver.hinclude/linux/mlx5/driver.h struct mlx5_core_mkey { · line 377
Quoted 5 lines
include/linux/mlx5/driver.h +2
-0@@ -373,6 +373,8 @@ struct mlx5_core_mkey { u32 key; u32 pd; u32 type; + struct wait_queue_head wait; + refcount_t usecount;Quoted 9 lines
mlx5_core_mkeyis used everywhere inmlx5_coreand we don't care about
odp complexity, i would like to keep the core simple and primitive as
it is today.
please keep the layer separation and find a way to manage refcount and
wait queue inmlx5_ibdriver..Quoted 3 lines
The alternative could really be to come with some wrapped
mlx5_ibstructure
that will hold 'mlx5_core_mkey' and will add those two fields.Yes
struct
mlx5_ib_mkey
{
structmlx5_core_mkeymkey;
structwait_queue_headwait;
refcount_tusecount;
}Quoted 5 lines
struct mlx5_ib_mr/mw/devx
{
structmlx5_ib_mkeymkey;
}
Quoted 4 lines
Yep, also i have a series internally that moves
mlx5_core_mkeytomlx5_ib, inmlx5_corewe don't need it we only need the u32 key :)I will send you this series internally.
Let's first finish this patch and perform "moving" later.
Thanks