Skip to content

Commit f18ec42

Browse files
committed
RDMA/mlx5: Use a union inside mlx5_ib_mr
The struct mlx5_ib_mr can be used for three different things, but only one at a time: - In the user MR cache - As a kernel MR - As a user MR Overlay the three things into a single union with the following rules: - If the mr is found on the cache_ent->head list then it is a cache MR and umem == NULL. The entire union is zero after the MR is removed from the cache. - If umem != NULL or type == IB_MR_TYPE_USER then it is a user MR. - If umem == NULL then it is a kernel MR This reduces the size of struct mlx5_ib_mr to 552 bytes from 702. The only place the three flows overlap in the code is during dereg, so add a few extra checks along there. Link: https://lore.kernel.org/r/20210304120745.1090751-3-leon@kernel.org Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent a639e66 commit f18ec42

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ struct mlx5_ib_mr {
657657
struct ib_umem *umem;
658658

659659
/* This is zero'd when the MR is allocated */
660-
struct {
660+
union {
661661
/* Used only while the MR is in the cache */
662662
struct {
663663
u32 out[MLX5_ST_SZ_DW(create_mkey_out)];

drivers/infiniband/hw/mlx5/mr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ mlx5_alloc_priv_descs(struct ib_device *device,
19291929
static void
19301930
mlx5_free_priv_descs(struct mlx5_ib_mr *mr)
19311931
{
1932-
if (mr->descs) {
1932+
if (!mr->umem && mr->descs) {
19331933
struct ib_device *device = mr->ibmr.device;
19341934
int size = mr->max_descs * mr->desc_size;
19351935
struct mlx5_ib_dev *dev = to_mdev(device);
@@ -1943,7 +1943,7 @@ mlx5_free_priv_descs(struct mlx5_ib_mr *mr)
19431943

19441944
static void clean_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
19451945
{
1946-
if (mr->sig) {
1946+
if (mr->ibmr.type == IB_MR_TYPE_INTEGRITY) {
19471947
if (mlx5_core_destroy_psv(dev->mdev,
19481948
mr->sig->psv_memory.psv_idx))
19491949
mlx5_ib_warn(dev, "failed to destroy mem psv %d\n",

0 commit comments

Comments
 (0)