Skip to content

Commit 19591f1

Browse files
aharonl-nvidiajgunthorpe
authored andcommitted
RDMA/mlx5: Store the number of in_use cache mkeys instead of total_mrs
total_mrs is used only to calculate the number of mkeys currently in use. To simplify things, replace it with a new member called "in_use" and directly store the number of mkeys currently in use. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Aharon Landau <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 86457a9 commit 19591f1

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,10 @@ struct mlx5_cache_ent {
755755
u8 fill_to_high_water:1;
756756

757757
/*
758-
* - total_mrs is stored mkeys plus all in use MRs that could be
759-
* returned to the cache.
760758
* - limit is the low water mark for stored mkeys, 2* limit is the
761759
* upper water mark.
762760
*/
763-
u32 total_mrs;
761+
u32 in_use;
764762
u32 limit;
765763

766764
/* Statistics */

drivers/infiniband/hw/mlx5/mr.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ static void create_mkey_callback(int status, struct mlx5_async_work *context)
268268

269269
xa_lock_irqsave(&ent->mkeys, flags);
270270
push_to_reserved(ent, mr);
271-
ent->total_mrs++;
272271
/* If we are doing fill_to_high_water then keep going. */
273272
queue_adjust_cache_locked(ent);
274273
xa_unlock_irqrestore(&ent->mkeys, flags);
@@ -391,9 +390,6 @@ static struct mlx5_ib_mr *create_cache_mr(struct mlx5_cache_ent *ent)
391390
init_waitqueue_head(&mr->mmkey.wait);
392391
mr->mmkey.type = MLX5_MKEY_MR;
393392
WRITE_ONCE(ent->dev->cache.last_add, jiffies);
394-
xa_lock_irq(&ent->mkeys);
395-
ent->total_mrs++;
396-
xa_unlock_irq(&ent->mkeys);
397393
kfree(in);
398394
return mr;
399395
free_mr:
@@ -411,7 +407,6 @@ static void remove_cache_mr_locked(struct mlx5_cache_ent *ent)
411407
if (!ent->stored)
412408
return;
413409
mr = pop_stored_mkey(ent);
414-
ent->total_mrs--;
415410
xa_unlock_irq(&ent->mkeys);
416411
mlx5_core_destroy_mkey(ent->dev->mdev, mr->mmkey.key);
417412
kfree(mr);
@@ -467,11 +462,11 @@ static ssize_t size_write(struct file *filp, const char __user *buf,
467462
* mkeys.
468463
*/
469464
xa_lock_irq(&ent->mkeys);
470-
if (target < ent->total_mrs - ent->stored) {
465+
if (target < ent->in_use) {
471466
err = -EINVAL;
472467
goto err_unlock;
473468
}
474-
target = target - (ent->total_mrs - ent->stored);
469+
target = target - ent->in_use;
475470
if (target < ent->limit || target > ent->limit*2) {
476471
err = -EINVAL;
477472
goto err_unlock;
@@ -495,7 +490,7 @@ static ssize_t size_read(struct file *filp, char __user *buf, size_t count,
495490
char lbuf[20];
496491
int err;
497492

498-
err = snprintf(lbuf, sizeof(lbuf), "%d\n", ent->total_mrs);
493+
err = snprintf(lbuf, sizeof(lbuf), "%ld\n", ent->stored + ent->in_use);
499494
if (err < 0)
500495
return err;
501496

@@ -689,13 +684,19 @@ struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev,
689684
return ERR_PTR(-EOPNOTSUPP);
690685

691686
xa_lock_irq(&ent->mkeys);
687+
ent->in_use++;
688+
692689
if (!ent->stored) {
693690
queue_adjust_cache_locked(ent);
694691
ent->miss++;
695692
xa_unlock_irq(&ent->mkeys);
696693
mr = create_cache_mr(ent);
697-
if (IS_ERR(mr))
694+
if (IS_ERR(mr)) {
695+
xa_lock_irq(&ent->mkeys);
696+
ent->in_use--;
697+
xa_unlock_irq(&ent->mkeys);
698698
return mr;
699+
}
699700
} else {
700701
mr = pop_stored_mkey(ent);
701702
queue_adjust_cache_locked(ent);
@@ -716,7 +717,6 @@ static void clean_keys(struct mlx5_ib_dev *dev, int c)
716717
xa_lock_irq(&ent->mkeys);
717718
while (ent->stored) {
718719
mr = pop_stored_mkey(ent);
719-
ent->total_mrs--;
720720
xa_unlock_irq(&ent->mkeys);
721721
mlx5_core_destroy_mkey(dev->mdev, mr->mmkey.key);
722722
kfree(mr);
@@ -1642,13 +1642,13 @@ int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
16421642

16431643
/* Stop DMA */
16441644
if (mr->cache_ent) {
1645+
xa_lock_irq(&mr->cache_ent->mkeys);
1646+
mr->cache_ent->in_use--;
1647+
xa_unlock_irq(&mr->cache_ent->mkeys);
1648+
16451649
if (mlx5r_umr_revoke_mr(mr) ||
1646-
push_mkey(mr->cache_ent, false, mr)) {
1647-
xa_lock_irq(&mr->cache_ent->mkeys);
1648-
mr->cache_ent->total_mrs--;
1649-
xa_unlock_irq(&mr->cache_ent->mkeys);
1650+
push_mkey(mr->cache_ent, false, mr))
16501651
mr->cache_ent = NULL;
1651-
}
16521652
}
16531653
if (!mr->cache_ent) {
16541654
rc = destroy_mkey(to_mdev(mr->ibmr.device), mr);

0 commit comments

Comments
 (0)