RDMA/mlx5: Switch MR cache to use RB-tree
Subsystems (3)
v2 cover RDMA/mlx5: Switch MR cache to use RB-tree
This series moves the MR cache to use RB tree to store the entries of the cache. By doing so, enabling more flexibility when managing the cache entries.
The MR cache will now cache mkeys returned by the user even if they are not from one of the predefined pools, by that allowing restarting applications to reuse their released mkey and improve restart times.
v1->v2:
- Rearrange patch order to first introduce the RB-tree and only then introduce the caching of previously non-cachable mkeys
v0->v1:
- Fix rb tree search from memcmp to dedicated cmp function
- Rewording of some commit messages
Aharon Landau (2):
RDMA/mlx5: Don't keep umrable 'page_shift' in cache entries RDMA/mlx5: Remove explicit ODP cache entry
Michael Guralnik (4):
RDMA/mlx5: Change the cache structure to an RB-tree RDMA/mlx5: Introduce mlx5r_cache_rb_key
RDMA/mlx5: Cache all user cacheable mkeys on dereg MR flow RDMA/mlx5: Add work to remove temporary entries from the cache
drivers/infiniband/hw/mlx5/mlx5_ib.h | 42 ++- drivers/infiniband/hw/mlx5/mr.c | 445 +++++++++++++++++++++------ drivers/infiniband/hw/mlx5/odp.c | 37 +-- include/linux/mlx5/driver.h | 1 - 4 files changed, 394 insertions(+), 131 deletions(-)
Signature · 1 line
2.17.2
PATCH v2 1/6 RDMA/mlx5: Don't keep umrable 'page_shift' in cache entries
From: Aharon Landau <[email protected]>
mkc.log_page_size can be changed using UMR. Therefore, don't treat it as a cache entry property.
Removing it from struct mlx5_cache_ent.
All cache mkeys will be created with default PAGE_SHIFT, and updated with the needed page_shift using UMR when passing them to a user.
--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 1 - drivers/infiniband/hw/mlx5/mr.c | 3 +-- drivers/infiniband/hw/mlx5/odp.c | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-)
drivers/infiniband/hw/mlx5/mlx5_ib.h +0 -1
@@ -739,7 +739,6 @@ struct mlx5_cache_ent {char name[4 ];u32 order;u32 access_mode; -u32 page;unsigned int ndescs; u8 disabled:1;
drivers/infiniband/hw/mlx5/mr.c +1 -2
@@ -297,7 +297,7 @@ static void set_cache_mkc(struct mlx5_cache_ent *ent, void *mkc)MLX5_SET (mkc, mkc, translations_octword_size,get_mkc_octo_size (ent->access_mode, ent->ndescs)); -MLX5_SET (mkc, mkc, log_page_size, ent->page); +MLX5_SET (mkc, mkc, log_page_size,PAGE_SHIFT ); }/* Asynchronously schedule new MRs to be populated in the cache. */
@@ -765,7 +765,6 @@ int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev)if (ent->order >mkey_cache_max_order (dev))continue ; - ent->page =PAGE_SHIFT ; ent->ndescs =1 << ent->order; ent->access_mode =MLX5_MKC_ACCESS_MODE_MTT ; if ((dev->mdev->profile.mask & MLX5_PROF_MASK_MR_CACHE) &&
drivers/infiniband/hw/mlx5/odp.c +0 -2
@@ -1595,14 +1595,12 @@ void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent)switch (ent->order -2 ) {case MLX5_IMR_MTT_CACHE_ENTRY : - ent->page =PAGE_SHIFT ; ent->ndescs =MLX5_IMR_MTT_ENTRIES ; ent->access_mode =MLX5_MKC_ACCESS_MODE_MTT ; ent->limit =0 ;break ;case MLX5_IMR_KSM_CACHE_ENTRY : - ent->page =MLX5_KSM_PAGE_SHIFT ; ent->ndescs = mlx5_imr_ksm_entries; ent->access_mode =MLX5_MKC_ACCESS_MODE_KSM ; ent->limit =0 ;
Signature · 1 line
2.17.2
PATCH v2 2/6 RDMA/mlx5: Remove explicit ODP cache entry
In reply to Michael GuralnikFrom: Aharon Landau <[email protected]>
Explicit ODP mkey doesn't have unique properties. There is no need to devote to it a special entry. Removing it.
--- drivers/infiniband/hw/mlx5/odp.c | 19 ++++--------------- include/linux/mlx5/driver.h | 1 - 2 files changed, 4 insertions(+), 16 deletions(-)
drivers/infiniband/hw/mlx5/odp.c +4 -15
@@ -406,6 +406,7 @@ static void mlx5_ib_page_fault_resume(struct mlx5_ib_dev *dev,static struct mlx5_ib_mr *implicit_get_child_mr (struct mlx5_ib_mr *imr,unsigned long idx) { +int order =order_base_2 (MLX5_IMR_MTT_ENTRIES );struct mlx5_ib_dev *dev =mr_to_mdev (imr);struct ib_umem_odp *odp;struct mlx5_ib_mr *mr;
@@ -418,7 +419,7 @@ static struct mlx5_ib_mr *implicit_get_child_mr(struct mlx5_ib_mr *imr,if (IS_ERR (odp))return ERR_CAST (odp); - mr =mlx5_mr_cache_alloc (dev, &dev->cache.ent[MLX5_IMR_MTT_CACHE_ENTRY ], + mr =mlx5_mr_cache_alloc (dev, &dev->cache.ent[order], imr->access_flags);if (IS_ERR (mr)) {ib_umem_odp_release (odp);
@@ -1592,20 +1593,8 @@ void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent) {if (!(ent->dev->odp_caps.general_caps &IB_ODP_SUPPORT_IMPLICIT ))return ; - -switch (ent->order -2 ) { -case MLX5_IMR_MTT_CACHE_ENTRY : - ent->ndescs =MLX5_IMR_MTT_ENTRIES ; - ent->access_mode =MLX5_MKC_ACCESS_MODE_MTT ; - ent->limit =0 ; -break ; - -case MLX5_IMR_KSM_CACHE_ENTRY : - ent->ndescs = mlx5_imr_ksm_entries; - ent->access_mode =MLX5_MKC_ACCESS_MODE_KSM ; - ent->limit =0 ; -break ; - } + ent->ndescs = mlx5_imr_ksm_entries; + ent->access_mode =MLX5_MKC_ACCESS_MODE_KSM ; }static const struct ib_device_ops mlx5_ib_dev_odp_ops = {
include/linux/mlx5/driver.h +0 -1
@@ -736,7 +736,6 @@ enum {enum {MKEY_CACHE_LAST_STD_ENTRY =20 , -MLX5_IMR_MTT_CACHE_ENTRY ,MLX5_IMR_KSM_CACHE_ENTRY ,MAX_MKEY_CACHE_ENTRIES };
Signature · 1 line
2.17.2
Jason Gunthorpe
maintainerRe: [PATCH v2 rdma-next 2/6] RDMA/mlx5: Remove explicit ODP cache entry
Quoted 4 lines · Michael Guralnik
From: Aharon Landau <[email protected]>
Explicit ODP mkey doesn't have unique properties. There is no need to devote to it a special entry. Removing it.
This isn't quite true, the purpose of this entry to is to create a cache block of order 30, which is higher than the usual max of 22
Though, I'm not really sure we should even be caching such huge MRs, I can understand why ODP would want this cache, at least for fairly short term.
At the end of this do we still have caching for order 30 MRs?
Also, is the MTT vs KSM access_mode UMRable?
Jason
Jason Gunthorpe
maintainerRe: [PATCH v2 rdma-next 2/6] RDMA/mlx5: Remove explicit ODP cache entry
In reply to Michael GuralnikQuoted 16 lines · Michael Guralnik
From: Aharon Landau <[email protected]>
Explicit ODP mkey doesn't have unique properties. There is no need to devote to it a special entry. Removing it.
Signed-off-by Aharon Landau <[email protected]>--- drivers/infiniband/hw/mlx5/odp.c | 19 ++++--------------- include/linux/mlx5/driver.h | 1 - 2 files changed, 4 insertions(+), 16 deletions(-)drivers/infiniband/hw/mlx5/odp.c +0
-0
drivers/infiniband/hw/mlx5/odp.c static void mlx5_ib_page_fault_resume(struct mlx5_ib_dev *dev, · line 409
Quoted 4 lines
drivers/infiniband/hw/mlx5/odp.c +1
-0@@ -406,6 +406,7 @@ static void mlx5_ib_page_fault_resume(struct mlx5_ib_dev *dev,static struct mlx5_ib_mr *implicit_get_child_mr (struct mlx5_ib_mr *imr,unsigned long idx) { +int order =order_base_2 (MLX5_IMR_MTT_ENTRIES );
unsigned int
drivers/infiniband/hw/mlx5/odp.c static struct mlx5_ib_mr *implicit_get_child_mr(struct mlx5_ib_mr *imr, · line 422
Quoted 9 lines
drivers/infiniband/hw/mlx5/odp.c +1
-1struct mlx5_ib_dev *dev =mr_to_mdev (imr);struct ib_umem_odp *odp;struct mlx5_ib_mr *mr;@@ -418,7 +419,7 @@ static struct mlx5_ib_mr *implicit_get_child_mr(struct mlx5_ib_mr *imr,if (IS_ERR (odp))return ERR_CAST (odp); - mr = mlx5_mr_cache_alloc(dev, &dev->cache.ent[MLX5_IMR_MTT_CACHE_ENTRY], + mr = mlx5_mr_cache_alloc(dev, &dev->cache.ent[order],
Okay, I get it now, this is actually just order 18, so it is covered by the existing order. You should clarify the commit message that it is the same as the order 18 entry.
Also add a compile time assertion here:
static_assert(order < MKEY_CACHE_LAST_STD_ENTRY);
Jason
PATCH v2 3/6 RDMA/mlx5: Change the cache structure to RB-tree
In reply to Michael GuralnikCurrently, the cache structure is a static linear array. Therefore, his size is limited to the number of entries in it and is not expandable. The entries are dedicated to mkeys of size 2^x and no access_flags. Mkeys with different properties are not cacheable.
In this patch, we change the cache structure to an RB-tree. This will allow to extend the cache to support more entries with different mkey properties.
--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 13 ++- drivers/infiniband/hw/mlx5/mr.c | 160 ++++++++++++++++++++------- drivers/infiniband/hw/mlx5/odp.c | 8 +- 3 files changed, 133 insertions(+), 48 deletions(-)
drivers/infiniband/hw/mlx5/mlx5_ib.h +10 -3
@@ -741,6 +741,8 @@ struct mlx5_cache_ent {u32 access_mode;unsigned int ndescs; +struct rb_node node; + u8 disabled:1; u8 fill_to_high_water:1;
@@ -770,8 +772,9 @@ struct mlx5r_async_create_mkey {struct mlx5_mkey_cache {struct workqueue_struct *wq; -struct mlx5_cache_ent ent[MAX_MKEY_CACHE_ENTRIES ]; -struct dentry *root; +struct rb_root rb_root; +struct mutex rb_lock; +struct dentry *fs_root;unsigned long last_add; };
@@ -1316,11 +1319,15 @@ void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);int mlx5_ib_get_cqe_size (struct ib_cq *ibcq);int mlx5_mkey_cache_init (struct mlx5_ib_dev *dev);int mlx5_mkey_cache_cleanup (struct mlx5_ib_dev *dev); +struct mlx5_cache_ent *mlx5r_cache_create_ent (struct mlx5_ib_dev *dev, +int order);struct mlx5_ib_mr *mlx5_mr_cache_alloc (struct mlx5_ib_dev *dev,struct mlx5_cache_ent *ent,int access_flags); +struct mlx5_ib_mr *mlx5_mr_cache_alloc_order (struct mlx5_ib_dev *dev,u32 order, +int access_flags);int mlx5_ib_check_mr_status (struct ib_mr *ibmr,u32 check_mask,struct ib_mr_status *mr_status); struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd,
@@ -1362,7 +1369,7 @@ static inline int mlx5r_odp_create_eq(struct mlx5_ib_dev *dev,static inline void mlx5_ib_odp_cleanup_one (struct mlx5_ib_dev *ibdev) {}static inline int mlx5_ib_odp_init (void ) {return 0 ; }static inline void mlx5_ib_odp_cleanup (void ) {} -static inline void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) {} +void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) {}static inline void mlx5_odp_populate_xlt (void *xlt,size_t idx,size_t nentries,struct mlx5_ib_mr *mr,int flags) {}
drivers/infiniband/hw/mlx5/mr.c +120 -40
240 lines not on this page · raw message
drivers/infiniband/hw/mlx5/odp.c +3 -5
@@ -419,8 +419,7 @@ static struct mlx5_ib_mr *implicit_get_child_mr(struct mlx5_ib_mr *imr,if (IS_ERR (odp))return ERR_CAST (odp); - mr =mlx5_mr_cache_alloc (dev, &dev->cache.ent[order], - imr->access_flags); + mr =mlx5_mr_cache_alloc_order (dev, order, imr->access_flags);if (IS_ERR (mr)) {ib_umem_odp_release (odp);return mr;
@@ -494,9 +493,8 @@ struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd,if (IS_ERR (umem_odp))return ERR_CAST (umem_odp); - imr =mlx5_mr_cache_alloc (dev, - &dev->cache.ent[MLX5_IMR_KSM_CACHE_ENTRY ], - access_flags); + imr =mlx5_mr_cache_alloc_order (dev,MLX5_IMR_KSM_CACHE_ENTRY , + access_flags);if (IS_ERR (imr)) {ib_umem_odp_release (umem_odp);return imr;
Signature · 1 line
2.17.2
Jason Gunthorpe
maintainerRe: [PATCH v2 rdma-next 3/6] RDMA/mlx5: Change the cache structure to RB-tree
drivers/infiniband/hw/mlx5/mlx5_ib.h static inline int mlx5r_odp_create_eq(struct mlx5_ib_dev *dev, · line 1372
Quoted 6 lines · Michael Guralnik
drivers/infiniband/hw/mlx5/mlx5_ib.h +1
-1@@ -1362,7 +1369,7 @@ static inline int mlx5r_odp_create_eq(struct mlx5_ib_dev *dev,static inline void mlx5_ib_odp_cleanup_one (struct mlx5_ib_dev *ibdev) {}static inline int mlx5_ib_odp_init (void ) {return 0 ; }static inline void mlx5_ib_odp_cleanup (void ) {} -static inline void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) {} +void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) {}
Why?
Jason
PATCH v2 4/6 RDMA/mlx5: Introduce mlx5r_cache_rb_key
In reply to Michael GuralnikSwitch from using the mkey order to using the new struct as the key to the RB tree of cache entries.
The key is all the mkey properties that UMR operations can't modify. Using this key to define the cache entries and to search and create cache mkeys.
--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 32 +++-- drivers/infiniband/hw/mlx5/mr.c | 196 +++++++++++++++++++-------- drivers/infiniband/hw/mlx5/odp.c | 26 ++-- 3 files changed, 180 insertions(+), 74 deletions(-)
drivers/infiniband/hw/mlx5/mlx5_ib.h +22 -10
@@ -731,17 +731,26 @@ struct umr_common {unsigned int state; }; +struct mlx5r_cache_rb_key { +u8 ats:1 ; +unsigned int access_mode; +unsigned int access_flags; +/* +* keep ndescs as the last member so entries with about the same ndescs +* will be close in the tree +*/ +unsigned int ndescs; +}; +struct mlx5_cache_ent {struct xarray mkeys;unsigned long stored;unsigned long reserved;char name[4 ]; -u32 order; -u32 access_mode; -unsigned int ndescs;struct rb_node node; +struct mlx5r_cache_rb_key rb_key;u8 disabled:1 ;u8 fill_to_high_water:1 ;
@@ -1320,14 +1329,13 @@ int mlx5_ib_get_cqe_size(struct ib_cq *ibcq);int mlx5_mkey_cache_init (struct mlx5_ib_dev *dev);int mlx5_mkey_cache_cleanup (struct mlx5_ib_dev *dev);struct mlx5_cache_ent *mlx5r_cache_create_ent (struct mlx5_ib_dev *dev, -int order); +struct mlx5r_cache_rb_key rb_key, +bool debugfs);struct mlx5_ib_mr *mlx5_mr_cache_alloc (struct mlx5_ib_dev *dev, -struct mlx5_cache_ent *ent, -int access_flags); +int access_flags,int access_mode, +int ndescs); -struct mlx5_ib_mr *mlx5_mr_cache_alloc_order (struct mlx5_ib_dev *dev,u32 order, -int access_flags);int mlx5_ib_check_mr_status (struct ib_mr *ibmr,u32 check_mask,struct ib_mr_status *mr_status); struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd,
@@ -1350,7 +1358,7 @@ int mlx5r_odp_create_eq(struct mlx5_ib_dev *dev, struct mlx5_ib_pf_eq *eq);void mlx5_ib_odp_cleanup_one (struct mlx5_ib_dev *ibdev);int __init mlx5_ib_odp_init (void );void mlx5_ib_odp_cleanup (void ); -void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent); +struct mlx5_cache_ent *mlx5_odp_init_mkey_cache_entry (struct mlx5_ib_dev *dev);void mlx5_odp_populate_xlt (void *xlt,size_t idx,size_t nentries,struct mlx5_ib_mr *mr,int flags);
@@ -1369,7 +1377,11 @@ static inline int mlx5r_odp_create_eq(struct mlx5_ib_dev *dev,static inline void mlx5_ib_odp_cleanup_one (struct mlx5_ib_dev *ibdev) {}static inline int mlx5_ib_odp_init (void ) {return 0 ; }static inline void mlx5_ib_odp_cleanup (void ) {} -void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) {} +static inline struct mlx5_cache_ent * +mlx5_odp_init_mkey_cache_entry (struct mlx5_ib_dev *dev) +{ +return NULL ; +}static inline void mlx5_odp_populate_xlt (void *xlt,size_t idx,size_t nentries,struct mlx5_ib_mr *mr,int flags) {}
drivers/infiniband/hw/mlx5/mr.c +141 -55
342 lines not on this page · raw message
drivers/infiniband/hw/mlx5/odp.c +17 -9
@@ -406,7 +406,6 @@ static void mlx5_ib_page_fault_resume(struct mlx5_ib_dev *dev,static struct mlx5_ib_mr *implicit_get_child_mr (struct mlx5_ib_mr *imr,unsigned long idx) { -int order =order_base_2 (MLX5_IMR_MTT_ENTRIES );struct mlx5_ib_dev *dev =mr_to_mdev (imr);struct ib_umem_odp *odp;struct mlx5_ib_mr *mr;
@@ -419,7 +418,9 @@ static struct mlx5_ib_mr *implicit_get_child_mr(struct mlx5_ib_mr *imr,if (IS_ERR (odp))return ERR_CAST (odp); - mr =mlx5_mr_cache_alloc_order (dev, order, imr->access_flags); + mr =mlx5_mr_cache_alloc (dev, imr->access_flags, +MLX5_MKC_ACCESS_MODE_MTT , +MLX5_IMR_MTT_ENTRIES );if (IS_ERR (mr)) {ib_umem_odp_release (odp);return mr;
@@ -493,8 +494,8 @@ struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd,if (IS_ERR (umem_odp))return ERR_CAST (umem_odp); - imr =mlx5_mr_cache_alloc_order (dev,MLX5_IMR_KSM_CACHE_ENTRY , - access_flags); + imr =mlx5_mr_cache_alloc (dev, access_flags,MLX5_MKC_ACCESS_MODE_KSM , + mlx5_imr_ksm_entries);if (IS_ERR (imr)) {ib_umem_odp_release (umem_odp);return imr;
@@ -1587,12 +1588,19 @@ mlx5_ib_odp_destroy_eq(struct mlx5_ib_dev *dev, struct mlx5_ib_pf_eq *eq)return err; } -void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) +struct mlx5_cache_ent *mlx5_odp_init_mkey_cache_entry (struct mlx5_ib_dev *dev) { -if (!(ent->dev->odp_caps.general_caps &IB_ODP_SUPPORT_IMPLICIT )) -return ; - ent->ndescs = mlx5_imr_ksm_entries; - ent->access_mode =MLX5_MKC_ACCESS_MODE_KSM ; +struct mlx5r_cache_rb_key rb_key = { + .ats =0 , + .access_mode =MLX5_MKC_ACCESS_MODE_KSM , + .access_flags =0 , + .ndescs = mlx5_imr_ksm_entries, + }; + +if (!(dev->odp_caps.general_caps &IB_ODP_SUPPORT_IMPLICIT )) +return NULL ; + +return mlx5r_cache_create_ent (dev, rb_key, true); }static const struct ib_device_ops mlx5_ib_dev_odp_ops = {
Signature · 1 line
2.17.2
Jason Gunthorpe
maintainerRe: [PATCH v2 rdma-next 4/6] RDMA/mlx5: Introduce mlx5r_cache_rb_key
Quoted 19 lines · Michael Guralnik
Switch from using the mkey order to using the new struct as the key to the RB tree of cache entries.
The key is all the mkey properties that UMR operations can't modify. Using this key to define the cache entries and to search and create cache mkeys.Signed-off-by Michael Guralnik <[email protected]>--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 32 +++-- drivers/infiniband/hw/mlx5/mr.c | 196 +++++++++++++++++++-------- drivers/infiniband/hw/mlx5/odp.c | 26 ++-- 3 files changed, 180 insertions(+), 74 deletions(-)drivers/infiniband/hw/mlx5/mlx5_ib.h +0
-0@@ -731,17 +731,26 @@ struct umr_common {unsigned int state;
drivers/infiniband/hw/mlx5/mlx5_ib.h struct umr_common { · line 741
Quoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +8
-0}; +struct mlx5r_cache_rb_key { +u8 ats:1 ; +unsigned int access_mode; +unsigned int access_flags; +/* +* keep ndescs as the last member so entries with about the same ndescs +* will be close in the tree +*/
? How does this happen? The compare function doesn't use memcmp..
I think this comment should go in the compare function because the search function does this:
drivers/infiniband/hw/mlx5/mlx5_ib.h struct umr_common { · line 747
Quoted 7 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +6
-1-return smallest; +return (smallest && + smallest->rb_key.access_mode == rb_key.access_mode && + smallest->rb_key.access_flags == rb_key.access_flags && + smallest->rb_key.ats == rb_key.ats) ? + smallest : +NULL ;
So it isn't that they have to be close in the tree, it is that "smallest" has to find a matching mode/flags/ats before finding the smallest ndescs of the matching list. Thus ndescs must always by the last thing in the compare ladder.
drivers/infiniband/hw/mlx5/mlx5_ib.h struct umr_common {
Quoted 11 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +11
-0+struct mlx5_ib_mr *mlx5_mr_cache_alloc (struct mlx5_ib_dev *dev, +int access_flags,int access_mode, +int ndescs) +{ +struct mlx5r_cache_rb_key rb_key = { + .ndescs = ndescs, + .access_mode = access_mode, + .access_flags =get_unchangeable_access_flags (dev, access_flags) + }; +struct mlx5_cache_ent *ent =mkey_cache_ent_from_rb_key (dev, rb_key); +if (!ent)
Missing newline
Quoted 8 lines
struct
mlx5_cache_ent*mlx5r_cache_create_ent(structmlx5_ib_dev*dev,drivers/infiniband/hw/mlx5/mlx5_ib.h +2
-1- int order) + struct mlx5r_cache_rb_key rb_key, + bool debugfs) {struct mlx5_cache_ent *ent;int ret;
drivers/infiniband/hw/mlx5/mlx5_ib.h struct mlx5_cache_ent *mlx5r_cache_create_ent(struct mlx5_ib_dev *dev, · line 879
Quoted 8 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +4
-1@@ -808,7 +873,10 @@ struct mlx5_cache_ent *mlx5r_cache_create_ent(struct mlx5_ib_dev *dev,return ERR_PTR (-ENOMEM );xa_init_flags (&ent->mkeys,XA_FLAGS_LOCK_IRQ ); - ent->order = order; + ent->rb_key.ats = rb_key.ats; + ent->rb_key.access_mode = rb_key.access_mode; + ent->rb_key.access_flags = rb_key.access_flags; + ent->rb_key.ndescs = rb_key.ndescs;
ent->rb_key = rb_key
Quoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +3
-0int mlx5_mkey_cache_init (struct mlx5_ib_dev *dev) { +struct mlx5r_cache_rb_key rb_key = { + .access_mode =MLX5_MKC_ACCESS_MODE_MTT , + };struct mlx5_mkey_cache *cache = &dev->cache;struct mlx5_cache_ent *ent;int i;@@ -838,19 +913,26 @@ int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev)
drivers/infiniband/hw/mlx5/mlx5_ib.h int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) · line 919
Quoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +2
-4mlx5_cmd_init_async_ctx (dev->mdev, &dev->async_ctx);timer_setup (&dev->delay_timer, delay_time_func,0 ); +mlx5_mkey_cache_debugfs_init (dev);for (i =0 ; i <MAX_MKEY_CACHE_ENTRIES ; i++) { - ent =mlx5r_cache_create_ent (dev, i); - -if (i >MKEY_CACHE_LAST_STD_ENTRY ) { -mlx5_odp_init_mkey_cache_entry (ent); +if (i >mkey_cache_max_order (dev))continue ;
This is goofy, just make the for loop go from 2 to mkey_cache_max_order() + 2 (and probably have the function do the + 2 internally)
Get rid of MAX_MKEY_CACHE_ENTRIES
drivers/infiniband/hw/mlx5/mlx5_ib.h int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) · line 924
Quoted 5 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +5
-0+ +if (i ==MLX5_IMR_KSM_CACHE_ENTRY ) { + ent =mlx5_odp_init_mkey_cache_entry (dev); +if (!ent) +continue ;
This too, just call mlx5_odp_init_mkey_cache_entry() outside the loop
And rename it to something like mlx5_odp_init_mkey_cache(), and don't return ent.
Set ent->limit inside mlx5r_cache_create_ent()
And run over the whole rbtree in a final loop to do the final queue_adjust_cache_locked() step.
drivers/infiniband/hw/mlx5/mlx5_ib.h int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) · line 931
Quoted 12 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +6
-5-void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) +struct mlx5_cache_ent *mlx5_odp_init_mkey_cache_entry (struct mlx5_ib_dev *dev) { -if (!(ent->dev->odp_caps.general_caps &IB_ODP_SUPPORT_IMPLICIT )) -return ; - ent->ndescs = mlx5_imr_ksm_entries; - ent->access_mode =MLX5_MKC_ACCESS_MODE_KSM ; +struct mlx5r_cache_rb_key rb_key = { + .ats =0 , + .access_mode =MLX5_MKC_ACCESS_MODE_KSM , + .access_flags =0 , + .ndescs = mlx5_imr_ksm_entries,
Don't need to zero init things here
Jason
Re: [PATCH v2 rdma-next 4/6] RDMA/mlx5: Introduce mlx5r_cache_rb_key
Quoted 35 lines · Jason Gunthorpe
Quoted 19 lines · Michael Guralnik
Switch from using the mkey order to using the new struct as the key to the RB tree of cache entries.
The key is all the mkey properties that UMR operations can't modify. Using this key to define the cache entries and to search and create cache mkeys.Signed-off-by Michael Guralnik <[email protected]>--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 32 +++-- drivers/infiniband/hw/mlx5/mr.c | 196 +++++++++++++++++++-------- drivers/infiniband/hw/mlx5/odp.c | 26 ++-- 3 files changed, 180 insertions(+), 74 deletions(-)drivers/infiniband/hw/mlx5/mlx5_ib.h +0
-0@@ -731,17 +731,26 @@ struct umr_common {unsigned int state;drivers/infiniband/hw/mlx5/mlx5_ib.h struct umr_common { · line 741
Quoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +8
-0}; +struct mlx5r_cache_rb_key { +u8 ats:1 ; +unsigned int access_mode; +unsigned int access_flags; +/* +* keep ndescs as the last member so entries with about the same ndescs +* will be close in the tree +*/ ? How does this happen? The compare function doesn't use memcmp..
I think this comment should go in the compare function because the search function does this:
Quoted 11 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h struct umr_common { · line 747
Quoted 7 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +6
-1-return smallest; +return (smallest && + smallest->rb_key.access_mode == rb_key.access_mode && + smallest->rb_key.access_flags == rb_key.access_flags && + smallest->rb_key.ats == rb_key.ats) ? + smallest : +NULL ;So it isn't that they have to be close in the tree, it is that "smallest" has to find a matching mode/flags/ats before finding the smallest ndescs of the matching list. Thus ndescs must always by the last thing in the compare ladder.
Correct, I'll move the comment to the compare function.
We've had a previous version of the compare that used memcmp but we've changed it so now the comment is not relevant in the struct anymore I'll fix this and rest of the comments in v3.
Thanks
Michael
Quoted 87 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h struct umr_common {
Quoted 12 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +11
-0+struct mlx5_ib_mr *mlx5_mr_cache_alloc (struct mlx5_ib_dev *dev, +int access_flags,int access_mode, +int ndescs) +{ +struct mlx5r_cache_rb_key rb_key = { + .ndescs = ndescs, + .access_mode = access_mode, + .access_flags =get_unchangeable_access_flags (dev, access_flags) + }; +struct mlx5_cache_ent *ent =mkey_cache_ent_from_rb_key (dev, rb_key); +if (!ent)Missing newline
Quoted 8 lines
struct
mlx5_cache_ent*mlx5r_cache_create_ent(structmlx5_ib_dev*dev,drivers/infiniband/hw/mlx5/mlx5_ib.h +2
-1- int order) + struct mlx5r_cache_rb_key rb_key, + bool debugfs) {struct mlx5_cache_ent *ent;int ret;drivers/infiniband/hw/mlx5/mlx5_ib.h struct mlx5_cache_ent *mlx5r_cache_create_ent(struct mlx5_ib_dev *dev, · line 879
Quoted 8 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +4
-1@@ -808,7 +873,10 @@ struct mlx5_cache_ent *mlx5r_cache_create_ent(struct mlx5_ib_dev *dev,return ERR_PTR (-ENOMEM );xa_init_flags (&ent->mkeys,XA_FLAGS_LOCK_IRQ ); - ent->order = order; + ent->rb_key.ats = rb_key.ats; + ent->rb_key.access_mode = rb_key.access_mode; + ent->rb_key.access_flags = rb_key.access_flags; + ent->rb_key.ndescs = rb_key.ndescs;
ent->rb_key=rb_keyQuoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +3
-0int mlx5_mkey_cache_init (struct mlx5_ib_dev *dev) { +struct mlx5r_cache_rb_key rb_key = { + .access_mode =MLX5_MKC_ACCESS_MODE_MTT , + };struct mlx5_mkey_cache *cache = &dev->cache;struct mlx5_cache_ent *ent;int i;@@ -838,19 +913,26 @@ int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev)drivers/infiniband/hw/mlx5/mlx5_ib.h int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) · line 919
Quoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +2
-4mlx5_cmd_init_async_ctx (dev->mdev, &dev->async_ctx);timer_setup (&dev->delay_timer, delay_time_func,0 ); +mlx5_mkey_cache_debugfs_init (dev);for (i =0 ; i <MAX_MKEY_CACHE_ENTRIES ; i++) { - ent =mlx5r_cache_create_ent (dev, i); - -if (i >MKEY_CACHE_LAST_STD_ENTRY ) { -mlx5_odp_init_mkey_cache_entry (ent); +if (i >mkey_cache_max_order (dev))continue ;This is goofy, just make the for loop go from 2 to
mkey_cache_max_order()+ 2 (and probably have the function do the + 2 internally)Get rid of
MAX_MKEY_CACHE_ENTRIESdrivers/infiniband/hw/mlx5/mlx5_ib.h int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) · line 924
Quoted 5 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +5
-0+ +if (i ==MLX5_IMR_KSM_CACHE_ENTRY ) { + ent =mlx5_odp_init_mkey_cache_entry (dev); +if (!ent) +continue ;This too, just call
mlx5_odp_init_mkey_cache_entry()outside the loopAnd rename it to something like
mlx5_odp_init_mkey_cache(), and don't return ent.Set
ent->limitinsidemlx5r_cache_create_ent()And run over the whole rbtree in a final loop to do the final
queue_adjust_cache_locked()step.drivers/infiniband/hw/mlx5/mlx5_ib.h int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) · line 931
Quoted 12 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +6
-5-void mlx5_odp_init_mkey_cache_entry (struct mlx5_cache_ent *ent) +struct mlx5_cache_ent *mlx5_odp_init_mkey_cache_entry (struct mlx5_ib_dev *dev) { -if (!(ent->dev->odp_caps.general_caps &IB_ODP_SUPPORT_IMPLICIT )) -return ; - ent->ndescs = mlx5_imr_ksm_entries; - ent->access_mode =MLX5_MKC_ACCESS_MODE_KSM ; +struct mlx5r_cache_rb_key rb_key = { + .ats =0 , + .access_mode =MLX5_MKC_ACCESS_MODE_KSM , + .access_flags =0 , + .ndescs = mlx5_imr_ksm_entries,Don't need to zero init things here
Jason
PATCH v2 5/6 RDMA/mlx5: Cache all user cacheable mkeys on dereg MR flow
In reply to Michael GuralnikCurrently, when dereging an MR, if the mkey doesn't belong to a cache entry, it will be destroyed.
As a result, the restart of applications with many non-cached mkeys is not efficient since all the mkeys are destroyed and then recreated. This process takes a long time (for 100,000 MRs, it is ~20 seconds for dereg and ~28 seconds for re-reg).
To shorten the restart runtime, insert all cacheable mkeys to the cache. If there is no fitting entry to the mkey properties, create a temporary entry that fits it.
After a predetermined timeout, the cache entries will shrink to the initial high limit.
The mkeys will still be in the cache when consuming them again after an application restart. Therefore, the registration will be much faster (for 100,000 MRs, it is ~4 seconds for dereg and ~5 seconds for re-reg).
The temporary cache entries created to store the non-cache mkeys are not exposed through sysfs like the default cache entries.
--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 24 ++++++------ drivers/infiniband/hw/mlx5/mr.c | 55 +++++++++++++++++++++------- 2 files changed, 55 insertions(+), 24 deletions(-)
drivers/infiniband/hw/mlx5/mlx5_ib.h +13 -11
@@ -617,12 +617,25 @@ enum mlx5_mkey_type { MLX5_MKEY_INDIRECT_DEVX, }; +struct mlx5r_cache_rb_key { +u8 ats:1 ; +unsigned int access_mode; +unsigned int access_flags; +/* +* keep ndescs as the last member so entries with about the same ndescs +* will be close in the tree +*/ +unsigned int ndescs; +}; +struct mlx5_ib_mkey {u32 key;enum mlx5_mkey_type type;unsigned int ndescs;struct wait_queue_head wait;refcount_t usecount; +/* User Mkey must hold either a cache_key or a cache_ent. */ +struct mlx5r_cache_rb_key rb_key;struct mlx5_cache_ent *cache_ent; };
@@ -731,17 +744,6 @@ struct umr_common {unsigned int state; }; -struct mlx5r_cache_rb_key { -u8 ats:1 ; -unsigned int access_mode; -unsigned int access_flags; -/* -* keep ndescs as the last member so entries with about the same ndescs -* will be close in the tree -*/ -unsigned int ndescs; -}; -struct mlx5_cache_ent {struct xarray mkeys;unsigned long stored;
drivers/infiniband/hw/mlx5/mr.c +42 -13
85 lines not on this page · raw message
Signature · 1 line
2.17.2
Jason Gunthorpe
maintainerRe: [PATCH v2 rdma-next 5/6] RDMA/mlx5: Cache all user cacheable mkeys on dereg MR flow
Quoted 44 lines · Michael Guralnik
Currently, when dereging an MR, if the mkey doesn't belong to a cache entry, it will be destroyed.
As a result, the restart of applications with many non-cached mkeys is not efficient since all the mkeys are destroyed and then recreated. This process takes a long time (for 100,000 MRs, it is ~20 seconds for dereg and ~28 seconds for re-reg).To shorten the restart runtime, insert all cacheable mkeys to the cache. If there is no fitting entry to the mkey properties, create a temporary entry that fits it.
After a predetermined timeout, the cache entries will shrink to the initial high limit.
The mkeys will still be in the cache when consuming them again after an application restart. Therefore, the registration will be much faster (for 100,000 MRs, it is ~4 seconds for dereg and ~5 seconds for re-reg).
The temporary cache entries created to store the non-cache mkeys are not exposed through sysfs like the default cache entries.
Signed-off-by Michael Guralnik <[email protected]>--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 24 ++++++------ drivers/infiniband/hw/mlx5/mr.c | 55 +++++++++++++++++++++------- 2 files changed, 55 insertions(+), 24 deletions(-)drivers/infiniband/hw/mlx5/mlx5_ib.h +9
-0@@ -617,12 +617,25 @@ enum mlx5_mkey_type { MLX5_MKEY_INDIRECT_DEVX, }; +struct mlx5r_cache_rb_key { +u8 ats:1 ; +unsigned int access_mode; +unsigned int access_flags; +/* +* keep ndescs as the last member so entries with about the same ndescs +* will be close in the tree +*/ +unsigned int ndescs;
drivers/infiniband/hw/mlx5/mlx5_ib.h enum mlx5_mkey_type { · line 638
Quoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +4
-0+}; +struct mlx5_ib_mkey {u32 key;enum mlx5_mkey_type type;unsigned int ndescs;struct wait_queue_head wait;refcount_t usecount; +/* User Mkey must hold either a cache_key or a cache_ent. */ +struct mlx5r_cache_rb_key rb_key;
What is a cache_key?
Why do we now have ndecs and rb_key.ndescs in the same struct?
Quoted 7 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +0
-0struct mlx5_cache_ent *cache_ent; };@@ -731,17 +744,6 @@ struct umr_common {unsigned int state; };
drivers/infiniband/hw/mlx5/mlx5_ib.h struct umr_common { · line 743
Quoted 10 lines
drivers/infiniband/hw/mlx5/mlx5_ib.h +0
-10-struct mlx5r_cache_rb_key { -u8 ats:1 ; -unsigned int access_mode; -unsigned int access_flags; -/* -* keep ndescs as the last member so entries with about the same ndescs -* will be close in the tree -*/ -unsigned int ndescs; -};
Don't move this, put it where it needs to be in the earlier patch
Quoted 13 lines
drivers/infiniband/hw/mlx5/mr.c +2
-2@@ -1096,15 +1096,14 @@ static struct mlx5_ib_mr *alloc_cacheable_mr(struct ib_pd *pd, rb_key.access_flags =get_unchangeable_access_flags (dev, access_flags); ent =mkey_cache_ent_from_rb_key (dev, rb_key);/* -* Matches access in alloc_cache_mr(). If the MR can't come from the -* cache then synchronously create an uncached one. +* If the MR can't come from the cache then synchronously create an uncached +* one. */
drivers/infiniband/hw/mlx5/mr.c static struct mlx5_ib_mr *alloc_cacheable_mr(struct ib_pd *pd, · line 1108
Quoted 10 lines
drivers/infiniband/hw/mlx5/mr.c +2
-3-if (!ent || ent->limit ==0 || - !mlx5r_umr_can_reconfig (dev,0 , access_flags) || -mlx5_umem_needs_ats (dev, umem, access_flags)) { +if (!ent) {mutex_lock (&dev->slow_path_mutex); mr =reg_create (pd, umem, iova, access_flags, page_size, false);mutex_unlock (&dev->slow_path_mutex); + mr->mmkey.rb_key = rb_key;return mr; }
Does this belong in this patch? Maybe these cleanups need their own patch
Jason
PATCH v2 6/6 RDMA/mlx5: Add work to remove temporary entries from the cache
In reply to Michael GuralnikThe non-cache mkeys are stored in the cache only to shorten restarting application time. Don't store them longer than needed.
Configure cache entries that store non-cache MRs as temporary entries. If 30 seconds have passed and no user reclaimed the temporarily cached mkeys, an asynchronous work will destroy the mkeys entries.
--- drivers/infiniband/hw/mlx5/mlx5_ib.h | 8 ++- drivers/infiniband/hw/mlx5/mr.c | 93 ++++++++++++++++++++++------ drivers/infiniband/hw/mlx5/odp.c | 2 +- 3 files changed, 80 insertions(+), 23 deletions(-)
drivers/infiniband/hw/mlx5/mlx5_ib.h +5 -3
@@ -754,6 +754,7 @@ struct mlx5_cache_ent {struct rb_node node;struct mlx5r_cache_rb_key rb_key; + u8 is_tmp:1; u8 disabled:1; u8 fill_to_high_water:1;
@@ -787,6 +788,7 @@ struct mlx5_mkey_cache {struct mutex rb_lock;struct dentry *fs_root;unsigned long last_add; +struct delayed_work remove_ent_dwork; };struct mlx5_ib_port_resources {
@@ -1330,9 +1332,9 @@ void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);int mlx5_ib_get_cqe_size (struct ib_cq *ibcq);int mlx5_mkey_cache_init (struct mlx5_ib_dev *dev);int mlx5_mkey_cache_cleanup (struct mlx5_ib_dev *dev); -struct mlx5_cache_ent *mlx5r_cache_create_ent (struct mlx5_ib_dev *dev, -struct mlx5r_cache_rb_key rb_key, -bool debugfs); +struct mlx5_cache_ent * +mlx5r_cache_create_ent_locked (struct mlx5_ib_dev *dev, +struct mlx5r_cache_rb_key rb_key,bool debugfs); struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, int access_flags, int access_mode,
drivers/infiniband/hw/mlx5/mr.c +74 -19
209 lines not on this page · raw message
drivers/infiniband/hw/mlx5/odp.c +1 -1
@@ -1600,7 +1600,7 @@ struct mlx5_cache_ent *mlx5_odp_init_mkey_cache_entry(struct mlx5_ib_dev *dev)if (!(dev->odp_caps.general_caps &IB_ODP_SUPPORT_IMPLICIT ))return NULL ; -return mlx5r_cache_create_ent (dev, rb_key, true); +return mlx5r_cache_create_ent_locked (dev, rb_key, true); }static const struct ib_device_ops mlx5_ib_dev_odp_ops = {
Signature · 1 line
2.17.2