Skip to content

cgroup/rdma: add MR memory size resource tracking

Tao Cui cgroups linux-rdma oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest3 patches 4 repliesIn review

Changes in v2 from the cover letter

- Removed RDMACG_RESOURCE_QP and RDMACG_RESOURCE_MR per-type counters following review feedback from Jason Gunthorpe [1].
- Retained only RDMACG_RESOURCE_MR_MEM as the sole new resource.
- Added detailed semantic notes to the commit messages addressing fork(), cgroup migration, and overlap with memory cgroup [2].
- Renamed patches to reflect the narrower scope.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3cgroup/rdma: extend charge/uncharge API with s64 amount parameterdrivers/infiniband/core/cgroup.c drivers/infiniband/core/core_priv.h drivers/infiniband/core/rdma_core.c +3 more+83 -450 replies
2/3cgroup/rdma: add MR memory size resource trackingdrivers/infiniband/core/rdma_core.c drivers/infiniband/core/uverbs_cmd.c drivers/infiniband/core/uverbs_std_types_mr.c +3 more+126 -50 replies
3/3cgroup/rdma: update cgroup resource list for MR_MEMDocumentation/admin-guide/cgroup-v2.rst+11 -100 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH rdma-next v2 0/3] cgroup/rdma: add MR memory size resource tracking

From: Tao Cui <[email protected]>

Currently the RDMA cgroup only tracks two aggregate counters:
hca_handle and hca_object. The real scarce resource in multi-tenant deployments is pinned memory: how much physical memory gets registered through MRs. The existing hca_object counter is too coarse to capture this.

This series adds a single new resource type:

- mr_mem - Cumulative MR memory size in bytes

The per-object-type counters (qp, mr) from RFC v1 have been removed per review feedback [1]: modern NICs pool objects from the same memory pool so the distinction between QP count and MR count is not meaningful for resource limiting. hca_object remains sufficient for coarse object accounting.

After this series, an administrator can set limits like:

    echo "mlx5_0 mr_mem=1073741824" > rdma.max

Design
~~~~~~

mr_mem is not page-level ownership tracking; it is object-based accounting tied to the MR lifetime:

- charged at MR registration time
- uncharged at MR destruction time
- the charge is pinned to the cgroup that created the MR for the entire lifetime of the MR object

This model intentionally defines accounting semantics around MR object lifetime rather than page ownership:

1. fork(): fork() does not duplicate MR objects. Even though the child inherits the uverbs fd and can access the parent's ucontext, the MR remains a single kernel object. The charge is tied to the MR object, not to the number of processes that can reach it, so no splitting or re-accounting is needed.

2. Cgroup migration: mr_mem follows the same semantics as the existing hca_object; charge at creation time against the invoking task's cgroup, uncharge at destruction time. The RDMA cgroup does not implement can_attach/attach callbacks today, so charges do not migrate with the task. This is a known limitation that applies equally to hca_handle and hca_object. mr_mem does not introduce any new complication here.

3. Overlap with memory cgroup: mr_mem does not count process memory usage; it represents a per-device DMA registration budget: the amount of memory this cgroup may register through a given HCA. This is a different dimension from what memory cgroup tracks. An administrator might set mr_mem limits differently per device, which memory cgroup cannot express.

In particular, mr_mem tracks the registered memory range associated with the MR rather than exact dynamically pinned pages (e.g. for ODP MRs). This is a stable, policy-oriented approximation of registration footprint, not an attempt at precise physical page accounting.

Tao Cui (3):
cgroup/rdma: extend charge/uncharge API with s64 amount parameter cgroup/rdma: add MR memory size resource tracking cgroup/rdma: update cgroup resource list for MR_MEM

 Documentation/admin-guide/cgroup-v2.rst       |  21 ++--
 drivers/infiniband/core/cgroup.c              |  10 +-
 drivers/infiniband/core/core_priv.h           |  12 +-
 drivers/infiniband/core/rdma_core.c           |  20 +++-
 drivers/infiniband/core/uverbs_cmd.c          |  61 +++++++++-
 drivers/infiniband/core/uverbs_std_types_mr.c |  37 ++++++
 include/linux/cgroup_rdma.h                   |   8 +-
 include/rdma/ib_verbs.h                       |   1 +
 kernel/cgroup/rdma.c                          | 108 +++++++++++++-----
 9 files changed, 219 insertions(+), 59 deletions(-)

---
Changes from RFC v1:

- Removed RDMACG_RESOURCE_QP and RDMACG_RESOURCE_MR per-type counters following review feedback from Jason Gunthorpe [1].
- Retained only RDMACG_RESOURCE_MR_MEM as the sole new resource.
- Added detailed semantic notes to the commit messages addressing fork(), cgroup migration, and overlap with memory cgroup [2].
- Renamed patches to reflect the narrower scope.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Signature · 1 line
2.43.0