RDMA/mlx5: Use a union inside mlx5_ib_mr
authorJason Gunthorpe <jgg@nvidia.com>
Thu, 4 Mar 2021 12:07:43 +0000 (14:07 +0200)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 12 Mar 2021 00:03:25 +0000 (20:03 -0400)
commitf18ec422311767738ef4033b61e91cae07163b22
tree2a4d1819ee658da19438dbc9c62cf643a7cc7eaf
parenta639e66703ee45745dc4057c7c2013ed9e1963a7
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>
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/infiniband/hw/mlx5/mr.c