cgroup/rdma: add MR memory size resource tracking
Subsystems (3)
v2 cover 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
PATCH v2 1/3 cgroup/rdma: extend charge/uncharge API with s64 amount parameter
From: Tao Cui <[email protected]>
Change struct rdmacg_resource fields (max, usage, peak) and all charge/uncharge function signatures from int to s64 to prepare for byte-sized resource tracking such as MR memory.
Replace match_int with a match_s64 helper that uses kstrtoll so the user-space limit tokens accept 64-bit values. All existing callers pass amount=1 (count-based), so the change is transparent for existing count-based resources.
The rpool->usage_sum counter continues to track the number of active charge operations (not the sum of charged amounts); this is correct because it governs rpool lifetime - a pool is releasable only when all charges, regardless of amount, have been released.
--- drivers/infiniband/core/cgroup.c | 10 ++-- drivers/infiniband/core/core_priv.h | 12 ++-- drivers/infiniband/core/rdma_core.c | 8 +-- drivers/infiniband/core/uverbs_cmd.c | 4 +- include/linux/cgroup_rdma.h | 7 ++- kernel/cgroup/rdma.c | 87 ++++++++++++++++++---------- 6 files changed, 83 insertions(+), 45 deletions(-)
drivers/infiniband/core/cgroup.c +6 -4
@@ -36,18 +36,20 @@ void ib_device_unregister_rdmacg(struct ib_device *device)int ib_rdmacg_try_charge (struct ib_rdmacg_object *cg_obj,struct ib_device *device, -enum rdmacg_resource_type resource_index) +enum rdmacg_resource_type resource_index, +s64 amount) {return rdmacg_try_charge (&cg_obj->cg, &device->cg_device, - resource_index); + resource_index, amount); }EXPORT_SYMBOL (ib_rdmacg_try_charge);void ib_rdmacg_uncharge (struct ib_rdmacg_object *cg_obj,struct ib_device *device, -enum rdmacg_resource_type resource_index) +enum rdmacg_resource_type resource_index, +s64 amount) {rdmacg_uncharge (cg_obj->cg, &device->cg_device, - resource_index); + resource_index, amount); }EXPORT_SYMBOL (ib_rdmacg_uncharge);
drivers/infiniband/core/core_priv.h +8 -4
@@ -159,11 +159,13 @@ void ib_device_unregister_rdmacg(struct ib_device *device);int ib_rdmacg_try_charge (struct ib_rdmacg_object *cg_obj,struct ib_device *device, -enum rdmacg_resource_type resource_index); +enum rdmacg_resource_type resource_index, +s64 amount);void ib_rdmacg_uncharge (struct ib_rdmacg_object *cg_obj,struct ib_device *device, -enum rdmacg_resource_type resource_index); +enum rdmacg_resource_type resource_index, +s64 amount);#else static inline void ib_device_register_rdmacg (struct ib_device *device) {
@@ -175,14 +177,16 @@ static inline void ib_device_unregister_rdmacg(struct ib_device *device)static inline int ib_rdmacg_try_charge (struct ib_rdmacg_object *cg_obj,struct ib_device *device, -enum rdmacg_resource_type resource_index) +enum rdmacg_resource_type resource_index, +s64 amount) {return 0 ; }static inline void ib_rdmacg_uncharge (struct ib_rdmacg_object *cg_obj,struct ib_device *device, -enum rdmacg_resource_type resource_index) +enum rdmacg_resource_type resource_index, +s64 amount) { }#endif
drivers/infiniband/core/rdma_core.c +4 -4
@@ -437,7 +437,7 @@ alloc_begin_idr_uobject(const struct uverbs_api_object *obj, goto uobj_put; ret =ib_rdmacg_try_charge (&uobj->cg_obj, uobj->context->device, -RDMACG_RESOURCE_HCA_OBJECT ); +RDMACG_RESOURCE_HCA_OBJECT ,1 );if (ret) goto remove;
@@ -526,7 +526,7 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,static void alloc_abort_idr_uobject (struct ib_uobject *uobj) {ib_rdmacg_uncharge (&uobj->cg_obj, uobj->context->device, -RDMACG_RESOURCE_HCA_OBJECT ); +RDMACG_RESOURCE_HCA_OBJECT ,1 );xa_erase (&uobj->ufile->idr, uobj->id); }
@@ -547,7 +547,7 @@ static int __must_check destroy_hw_idr_uobject(struct ib_uobject *uobj,return 0 ;ib_rdmacg_uncharge (&uobj->cg_obj, uobj->context->device, -RDMACG_RESOURCE_HCA_OBJECT ); +RDMACG_RESOURCE_HCA_OBJECT ,1 );return 0 ; }
@@ -878,7 +878,7 @@ static void ufile_destroy_ucontext(struct ib_uverbs_file *ufile, }ib_rdmacg_uncharge (&ucontext->cg_obj, ib_dev, -RDMACG_RESOURCE_HCA_HANDLE ); +RDMACG_RESOURCE_HCA_HANDLE ,1 );rdma_restrack_del (&ucontext->res);
drivers/infiniband/core/uverbs_cmd.c +2 -2
@@ -234,7 +234,7 @@ int ib_init_ucontext(struct uverbs_attr_bundle *attrs) } ret =ib_rdmacg_try_charge (&ucontext->cg_obj, ucontext->device, -RDMACG_RESOURCE_HCA_HANDLE ); +RDMACG_RESOURCE_HCA_HANDLE ,1 );if (ret) goto err;
@@ -273,7 +273,7 @@ int ib_init_ucontext(struct uverbs_attr_bundle *attrs) err_uncharge:ib_rdmacg_uncharge (&ucontext->cg_obj, ucontext->device, -RDMACG_RESOURCE_HCA_HANDLE ); +RDMACG_RESOURCE_HCA_HANDLE ,1 ); err:mutex_unlock (&file->ucontext_lock);up_read (&file->hw_destroy_rwsem);
include/linux/cgroup_rdma.h +5 -2
@@ -7,6 +7,7 @@#define _CGROUP_RDMA_H#include <linux/cgroup.h> +#include <linux/types.h> enum rdmacg_resource_type {RDMACG_RESOURCE_HCA_HANDLE ,
@@ -46,9 +47,11 @@ void rdmacg_unregister_device(struct rdmacg_device *device);/* APIs for RDMA/IB stack to charge/uncharge pool specific resources */ int rdmacg_try_charge (struct rdma_cgroup **rdmacg,struct rdmacg_device *device, -enum rdmacg_resource_type index); +enum rdmacg_resource_type index, +s64 amount);void rdmacg_uncharge (struct rdma_cgroup *cg,struct rdmacg_device *device, -enum rdmacg_resource_type index); +enum rdmacg_resource_type index, +s64 amount);#endif /* CONFIG_CGROUP_RDMA */ #endif /* _CGROUP_RDMA_H */
kernel/cgroup/rdma.c +58 -29
237 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 2/3 cgroup/rdma: add MR memory size resource tracking
In reply to Tao CuiFrom: Tao Cui <[email protected]>
Add RDMACG_RESOURCE_MR_MEM so that the cumulative memory size of registered Memory Regions can be tracked and limited independently from the aggregate hca_object counter.
Unlike count-based resources (hca_handle, hca_object) which are charged in the generic IDR allocation path, MR_MEM is byte-based and must be charged after the MR length is known. Charge in the uverbs MR registration handlers (ioctl and legacy), and uncharge in the generic destroy paths (alloc_abort_idr_uobject, destroy_hw_idr_uobject).
Store the charged byte count in uobj->rdmacg_mr_mem_bytes so that the destroy path knows how much to uncharge.
Semantic notes
~~~~~~~~~~~~~~
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 lives with the MR's creating cgroup 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: how much memory can this cgroup 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.
Guard against u64-to-s64 overflow by rejecting MR lengths that exceed S64_MAX at each registration site.
Handle MR reregistration (IB_USER_VERBS_CMD_REREG_MR with IB_MR_REREG_TRANS) by computing the delta between old and new lengths and charging or uncharging the difference. When the driver creates a new HW object (new_mr != NULL), the full new length is charged to the new uobj and the old uobj's mr_mem is released through the existing rdma_assign_uobject -> destroy_hw_idr_uobject -> rdmacg_uncharge_uobj path.
Enable MR memory limits:
echo "mlx5_0 mr_mem=1073741824" > rdma.max
--- drivers/infiniband/core/rdma_core.c | 14 ++++- drivers/infiniband/core/uverbs_cmd.c | 57 +++++++++++++++++++ drivers/infiniband/core/uverbs_std_types_mr.c | 37 ++++++++++++ include/linux/cgroup_rdma.h | 1 + include/rdma/ib_verbs.h | 1 + kernel/cgroup/rdma.c | 21 ++++++- 6 files changed, 126 insertions(+), 5 deletions(-)
drivers/infiniband/core/rdma_core.c +11 -3
@@ -523,10 +523,19 @@ struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_api_object *obj,return ret; } -static void alloc_abort_idr_uobject (struct ib_uobject *uobj) +static void rdmacg_uncharge_uobj (struct ib_uobject *uobj) {ib_rdmacg_uncharge (&uobj->cg_obj, uobj->context->device,RDMACG_RESOURCE_HCA_OBJECT ,1 ); +if (uobj->rdmacg_mr_mem_bytes) +ib_rdmacg_uncharge (&uobj->cg_obj, uobj->context->device, +RDMACG_RESOURCE_MR_MEM , + uobj->rdmacg_mr_mem_bytes); +} + +static void alloc_abort_idr_uobject (struct ib_uobject *uobj) +{ +rdmacg_uncharge_uobj (uobj);xa_erase (&uobj->ufile->idr, uobj->id); }
@@ -546,8 +555,7 @@ static int __must_check destroy_hw_idr_uobject(struct ib_uobject *uobj,if (why ==RDMA_REMOVE_ABORT )return 0 ; -ib_rdmacg_uncharge (&uobj->cg_obj, uobj->context->device, -RDMACG_RESOURCE_HCA_OBJECT ,1 ); +rdmacg_uncharge_uobj (uobj);return 0 ; }
drivers/infiniband/core/uverbs_cmd.c +57 -0
87 lines not on this page · raw message
drivers/infiniband/core/uverbs_std_types_mr.c +37 -0
@@ -32,6 +32,7 @@*/ #include "rdma_core.h" +#include "core_priv.h" #include "uverbs.h" #include <rdma/uverbs_std_types.h> #include "restrack.h"
@@ -140,6 +141,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(rdma_restrack_set_name (&mr->res,NULL );rdma_restrack_add (&mr->res); uobj->object = mr; +if (attr.length >S64_MAX ) +return -EINVAL ; + +if (attr.length) { + ret =ib_rdmacg_try_charge (&uobj->cg_obj, uobj->context->device, +RDMACG_RESOURCE_MR_MEM , attr.length); +if (ret) { +ib_dereg_mr_user (mr, &attrs->driver_udata); +return ret; + } + uobj->rdmacg_mr_mem_bytes = attr.length; + }uverbs_finalize_uobj_create (attrs,UVERBS_ATTR_REG_DM_MR_HANDLE );
@@ -254,6 +267,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_REG_DMABUF_MR)(rdma_restrack_add (&mr->res); uobj->object = mr; +if (length >S64_MAX ) +return -EINVAL ; +if (length) { + ret =ib_rdmacg_try_charge (&uobj->cg_obj, uobj->context->device, +RDMACG_RESOURCE_MR_MEM , length); +if (ret) { +ib_dereg_mr_user (mr, &attrs->driver_udata); +return ret; + } + uobj->rdmacg_mr_mem_bytes = length; + } +uverbs_finalize_uobj_create (attrs,UVERBS_ATTR_REG_DMABUF_MR_HANDLE ); ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_DMABUF_MR_RESP_LKEY,
@@ -383,6 +408,18 @@ static int UVERBS_HANDLER(UVERBS_METHOD_REG_MR)(rdma_restrack_add (&mr->res); uobj->object = mr; +if (length >S64_MAX ) +return -EINVAL ; +if (length) { + ret =ib_rdmacg_try_charge (&uobj->cg_obj, uobj->context->device, +RDMACG_RESOURCE_MR_MEM , length); +if (ret) { +ib_dereg_mr_user (mr, &attrs->driver_udata); +return ret; + } + uobj->rdmacg_mr_mem_bytes = length; + } +uverbs_finalize_uobj_create (attrs,UVERBS_ATTR_REG_MR_HANDLE ); ret = uverbs_copy_to(attrs, UVERBS_ATTR_REG_MR_RESP_LKEY,
include/linux/cgroup_rdma.h +1 -0
@@ -12,6 +12,7 @@enum rdmacg_resource_type {RDMACG_RESOURCE_HCA_HANDLE ,RDMACG_RESOURCE_HCA_OBJECT , +RDMACG_RESOURCE_MR_MEM ,RDMACG_RESOURCE_MAX , };
include/rdma/ib_verbs.h +1 -0
@@ -1569,6 +1569,7 @@ struct ib_uobject {void *object;/* containing object */ struct list_head list;/* link to context's list */ struct ib_rdmacg_object cg_obj;/* rdmacg object */ +s64 rdmacg_mr_mem_bytes;/* charged MR memory size */ int id;/* index into kernel idr */ struct kref ref;atomic_t usecnt;/* protects exclusive access */
kernel/cgroup/rdma.c +19 -2
@@ -23,14 +23,18 @@ enum rdmacg_limit_tokens {RDMACG_HCA_HANDLE_MAX ,RDMACG_HCA_OBJECT_VAL ,RDMACG_HCA_OBJECT_MAX , +RDMACG_MR_MEM_VAL , +RDMACG_MR_MEM_MAX , NR_RDMACG_LIMIT_TOKENS, };static const match_table_t rdmacg_limit_tokens = { - {RDMACG_HCA_HANDLE_VAL ,"hca_handle=%d" }, + {RDMACG_HCA_HANDLE_VAL ,"hca_handle=%d" }, {RDMACG_HCA_HANDLE_MAX ,"hca_handle=max" }, - {RDMACG_HCA_OBJECT_VAL ,"hca_object=%d" }, + {RDMACG_HCA_OBJECT_VAL ,"hca_object=%d" }, {RDMACG_HCA_OBJECT_MAX ,"hca_object=max" }, + {RDMACG_MR_MEM_VAL ,"mr_mem=%d" }, + {RDMACG_MR_MEM_MAX ,"mr_mem=max" }, {NR_RDMACG_LIMIT_TOKENS ,NULL }, };
@@ -55,6 +59,7 @@ enum rdmacg_file_type {static char const *rdmacg_resource_names[] = { [RDMACG_RESOURCE_HCA_HANDLE ] ="hca_handle" , [RDMACG_RESOURCE_HCA_OBJECT ] ="hca_object" , + [RDMACG_RESOURCE_MR_MEM ] ="mr_mem" , };/* resource tracker for each resource of rdma cgroup */
@@ -566,6 +571,18 @@ static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of, new_limits[RDMACG_RESOURCE_HCA_OBJECT ] =S64_MAX ; enables |=BIT (RDMACG_RESOURCE_HCA_OBJECT );break ; +case RDMACG_MR_MEM_VAL : +if (match_s64 (&args[0 ], &intval)) { + ret = -EINVAL ; + goto parse_err; + } + new_limits[RDMACG_RESOURCE_MR_MEM ] = intval; + enables |=BIT (RDMACG_RESOURCE_MR_MEM ); +break ; +case RDMACG_MR_MEM_MAX : + new_limits[RDMACG_RESOURCE_MR_MEM ] =S64_MAX ; + enables |=BIT (RDMACG_RESOURCE_MR_MEM ); +break ;default : ret = -EINVAL ; goto parse_err;
Signature · 1 line
2.43.0
PATCH v2 3/3 cgroup/rdma: update cgroup resource list for MR_MEM
In reply to Tao CuiFrom: Tao Cui <[email protected]>
The RDMA cgroup now supports MR memory size tracking via the new mr_mem resource. Update the cgroup-v2 documentation to describe the new resource and revise the usage examples accordingly.
The mr_mem resource tracks the cumulative size of memory registered through Memory Regions per device per cgroup, providing a DMA registration budget that is orthogonal to the existing hca_object counter.
--- Documentation/admin-guide/cgroup-v2.rst | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +11 -10
@@ -2766,15 +2766,16 @@ RDMA Interface Files The following nested keys are defined. - ========== ============================= + ========== ================================================ hca_handle Maximum number of HCA Handles hca_object Maximum number of HCA Objects - ========== ============================= + mr_mem Maximum cumulative MR memory size in bytes + ========== ================================================ An example for mlx4 and ocrdma device follows:: - mlx4_0 hca_handle=2 hca_object=2000 - ocrdma1 hca_handle=3 hca_object=max + mlx4_0 hca_handle=2 hca_object=2000 mr_mem=1073741824 + ocrdma1 hca_handle=3 hca_object=max mr_mem=max rdma.current A read-only file that describes current resource usage.
@@ -2782,8 +2783,8 @@ RDMA Interface Files An example for mlx4 and ocrdma device follows:: - mlx4_0 hca_handle=1 hca_object=20 - ocrdma1 hca_handle=1 hca_object=23 + mlx4_0 hca_handle=1 hca_object=20 mr_mem=1048576 + ocrdma1 hca_handle=1 hca_object=23 mr_mem=0 rdma.peak A read-only nested-keyed file that exists for all the cgroups
@@ -2792,8 +2793,8 @@ RDMA Interface Files An example for mlx4 and ocrdma device follows:: - mlx4_0 hca_handle=1 hca_object=20 - ocrdma1 hca_handle=0 hca_object=23 + mlx4_0 hca_handle=1 hca_object=20 mr_mem=1048576 + ocrdma1 hca_handle=0 hca_object=23 mr_mem=0 rdma.events A read-only nested-keyed file which exists on non-root
@@ -2815,7 +2816,7 @@ RDMA Interface Files An example for mlx4 device follows:: - mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=3 hca_object.max=0 hca_object.alloc_fail=0 + mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=3 hca_object.max=0 hca_object.alloc_fail=0 mr_mem.max=0 mr_mem.alloc_fail=0 rdma.events.local Similar to rdma.events but the fields in the file are local
@@ -2836,7 +2837,7 @@ RDMA Interface Files An example for mlx4 device follows:: - mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=0 hca_object.max=0 hca_object.alloc_fail=0 + mlx4_0 hca_handle.max=5 hca_handle.alloc_fail=0 hca_object.max=0 hca_object.alloc_fail=0 mr_mem.max=0 mr_mem.alloc_fail=0 DMEM ----
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH rdma-next v2 3/3] cgroup/rdma: update cgroup resource list for MR_MEM
kernel test robot noticed the following build warnings:
Hi Tao,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tj-cgroup/for-next]
[also build test WARNING on next-20260528]
[cannot apply to linus/master v7.1-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tao-Cui/cgroup-rdma-extend-charge-uncharge-API-with-s64-amount-parameter/20260529-171623 base: https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next patch link: https://lore.kernel.org/r/20260529090733.2242822-4-cui.tao%40linux.dev patch subject: [PATCH rdma-next v2 3/3] cgroup/rdma: update cgroup resource list for MR_MEM config: i386-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260529/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260529/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> Warning: kernel/cgroup/rdma.c:210 function parameter 'amount' not described in 'uncharge_cg_locked' >> Warning: kernel/cgroup/rdma.c:312 function parameter 'amount' not described in 'rdmacg_uncharge_hierarchy' >> Warning: kernel/cgroup/rdma.c:335 function parameter 'amount' not described in 'rdmacg_uncharge' >> Warning: kernel/cgroup/rdma.c:210 function parameter 'amount' not described in 'uncharge_cg_locked' >> Warning: kernel/cgroup/rdma.c:312 function parameter 'amount' not described in 'rdmacg_uncharge_hierarchy' >> Warning: kernel/cgroup/rdma.c:335 function parameter 'amount' not described in 'rdmacg_uncharge'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Michal Koutný
maintainerHi.
Quoted 11 lines · Tao Cui
The real scarce resource in multi-tenant
deployments is pinned memory: how much physical memory gets registered through MRs.
...
3. Overlap with memory cgroup:mr_memdoes 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 setmr_memlimits differently per device, which memory cgroup cannot express.
Quoted 5 lines
In particular,
mr_memtracks 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.
IIUC the pinned memory is regular RAM, i.e. it could be controlled with memcg as needed. Or is there "physical" limit of what can be assigned to a single device?
BTW, have a look at [1], it'd be good to converge to similar approach (the current proposal allows distinguishing whether charging should include or exempt memcg counting). Also it seems, that the dmem controller could be a one-stop solution for all DMA charges. Please tell me if there are any distinguishing factors between RDMA devices' memory and these dmem memory regions.
Thanks,
Michal
[1] https://lore.kernel.org/r/20260519-cgroup-dmem-memcg-double-charge-v2-0-db4d1407062b@redhat.com/
Hi Michal,
Thanks for the review and for the reference.
Quoted 3 lines
IIUC the pinned memory is regular RAM, i.e. it could be controlled with memcg as needed. Or is there "physical" limit of what can be assigned to a single device?
You are right that the pages associated with an MR are regular system RAM. However, MR registration does not allocate new pages; it registers existing pages that are already charged to the allocating process's memcg.
For that reason, mr_mem is intended to represent a different resource
dimension: not "how much memory does this cgroup own", but "how much memory may this cgroup register through a given HCA". In other words:
* memcg limits memory ownership/consumption
* mr_mem limits RDMA registration footprint
An administrator may reasonably wish to set different registration budgets per device (for example, 1G through mlx5_0 and 4G through mlx5_1) for the same cgroup. memcg has no notion of device-scoped limits; it only tracks aggregate memory consumption.
This distinction is important because memory ownership and DMA registration are not necessarily constrained by the same policy. A tenant may remain within its memcg limit while still consuming a large portion of a particular HCA's registration capacity. The existing RDMA controller already provides a per-device resource control framework, and mr_mem extends that model to cover memory registration footprint.
Quoted 1 line
Or is there "physical" limit of what can be assigned to a single device?
Yes. Real HCAs have finite resources associated with memory registration, such as MTT/MPT capacity and related DMA translation resources. In practice, administrators often need to prevent one tenant from consuming a disproportionate share of a particular HCA's registration capacity, even when sufficient system memory remains available.
It is also worth noting that mr_mem is intentionally not an attempt to account exact pinned pages. The accounting model is tied to MR object lifetime and tracks registration footprint rather than dynamic physical page state. For example, ODP MRs may have only a subset of their pages pinned at any given time, yet still consume registration resources on the HCA. This is why the proposal focuses on a stable, policy-oriented registration budget rather than precise memory ownership accounting.
Quoted 3 lines
BTW, have a look at [1], it'd be good to converge to similar approach (the current proposal allows distinguishing whether charging should include or exempt memcg counting).
I've read the related dma-buf accounting work.
My understanding is that those proposals focus on allocations that create new memory on behalf of a device, which is naturally accounted through memcg.
RDMA MR registration is different because no new memory is allocated. The MR object is an in-kernel registration of existing memory that has already been accounted elsewhere. The resource being limited is therefore the registration itself rather than the underlying memory pages.
Quoted 3 lines
Also it seems, that the dmem controller could be a one-stop solution for all DMA charges. Please tell me if there are any distinguishing factors between RDMA devices' memory and these dmem memory regions.
One distinction is that the current dmem work appears to focus on memory resources allocated on behalf of a device, whereas mr_mem is intended to limit host memory registered for DMA through RDMA MRs. RDMA NICs typically do not have large device-local memory pools; instead they provide DMA access to host RAM through memory registration. As a result, the resource being controlled here is not device memory consumption itself, but the registration footprint associated with a particular HCA.
Another difference is the accounting model itself. The proposed mr_mem accounting is tied to MR object lifetime and tracks registration footprint rather than precise physical page usage.
My understanding is that dmem is currently integrated with the DRM/TTM subsystem for device-local memory accounting, and there is no existing RDMA integration today. I have not investigated what would be required to extend that model to RDMA registration accounting.
That said, I agree that convergence would be desirable if a generic framework can naturally express per-device DMA registration budgets. My goal here is not necessarily to require RDMA-specific accounting, but to address a practical resource-control problem within the existing RDMA cgroup framework.
Thanks,
Tao
Quoted 18 lines · Tao Cui
From: Tao Cui <[email protected]>
Currently the RDMA cgroup only tracks two aggregate counters:
hca_handleandhca_object. The real scarce resource in multi-tenant deployments is pinned memory: how much physical memory gets registered through MRs. The existinghca_objectcounter is too coarse to capture this.This series adds a single new resource type:
-
mr_mem- Cumulative MR memory size in bytesThe 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_objectremains sufficient for coarse object accounting.
Quoted 4 lines
After this series, an administrator can set limits like:
echo "mlx5_0 mr_mem=1073741824" > rdma.max
Hi,
Thanks for the patchset! Introducing mr_mem to track and limit pinned memory size is a very practical enhancement for multi-tenant deployments.
I have a question regarding how this new resource type interacts with Fast Registration (FRWR / FRMR), which is widely used in production environments (e.g., NVMe-oF, iSER) to achieve high performance.
As we know, FRWR decouples the MR object allocation (ib_alloc_mr) from the actual memory page mapping (ib_map_mr_sg). The creation of FRWR Memory Regions is often managed via a pre-allocated page pool.
Could you clarify how mr_mem accounts for FRWR in the following scenarios?
1. Accounting Granularity: Does mr_mem charge the maximum capacity of
the FRWR object at its allocation time (ib_alloc_mr), or does it
dynamically track the actual mapped bytes during the fast-reg data
path? If it's the former, it represents a "static maximum budget" per pool, which seems more practical for performance.
2. Kernel-space vs Userspace: FRWR pools are frequently allocated by kernel-space drivers (like NVMe-oF target/host). If these kernel threads are not bound to a specific user cgroup, will their FRWR allocations end up in the root cgroup, potentially bypassing the per-tenant limits?
Don't you think it would be beneficial to explicitly document or consider the FRWR pattern in the design section, given its prevalence in real-world storage and networking workloads?
Thanks,
Zhu Yanjun
Quoted 69 lines
Design
~~~~~~
mr_memis 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 objectThis 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_memfollows the same semantics as the existinghca_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 tohca_handleandhca_object.mr_memdoes not introduce any new complication here.3. Overlap with memory cgroup:
mr_memdoes 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 setmr_memlimits differently per device, which memory cgroup cannot express.In particular,
mr_memtracks 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 forMR_MEMDocumentation/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_QPandRDMACG_RESOURCE_MRper-type counters following review feedback from Jason Gunthorpe [1].
- Retained onlyRDMACG_RESOURCE_MR_MEMas the sole new resource.
- Added detailed semantic notes to the commit messages addressingfork(), 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]/
Hi Yanjun,
Thanks for the thoughtful questions. FRWR is indeed a widely used pattern, and the interaction with mr_mem deserves clarification.
Quoted 4 lines
1. Accounting Granularity: Does
mr_memcharge the maximum capacity of the FRWR object at its allocation time (ib_alloc_mr), or does it dynamically track the actual mapped bytes during the fast-reg data path?
In the current proposal, mr_mem is only charged for userspace MR registrations that go through the uverbs layer (REG_MR, DM_MR, DMABUF_MR, and the legacy ioctl path). These are the paths where a concrete byte length is known at registration time.
FRWR MRs allocated via ib_alloc_mr() are not charged for mr_mem. The actual registration footprint associated with an FRWR MR is not known at allocation time: ib_alloc_mr() only specifies the maximum scatter-gather capacity of the MR, while the mapped byte range may change dynamically across successive ib_map_mr_sg() operations.
Supporting FRWR accounting would therefore require a separate accounting model, since the registration footprint is established dynamically rather than by a fixed length parameter supplied at MR creation. This is outside the scope of the current proposal.
Quoted 5 lines
2. Kernel-space vs Userspace: FRWR pools are frequently allocated by kernel-space drivers (like NVMe-oF target/host). If these kernel threads are not bound to a specific user cgroup, will their FRWR allocations end up in the root cgroup, potentially bypassing the per-tenant limits?
The RDMA cgroup's resource control is primarily designed for userspace consumers. Kernel-space consumers (NVMe-oF target, SRP initiator, rtrs, iSER, etc.) allocate resources through kernel APIs (ib_alloc_mr, ib_create_qp, etc.). These resources do not currently participate in RDMA cgroup accounting and therefore are not subject to per-cgroup limits.
Kernel-space FRWR pools are typically managed by the administrator rather than subject to per-tenant limits.
This behavior is consistent with the current RDMA cgroup model, which tracks resources associated with userspace RDMA objects. If accounting were extended to kernel-allocated FRWR MRs, ownership semantics would become an open question: simply charging against the current task or the root cgroup may not accurately represent the tenant that ultimately benefits from the resource.
Quoted 3 lines
Don't you think it would be beneficial to explicitly document or consider the FRWR pattern in the design section, given its prevalence in real-world storage and networking workloads?
Agreed. I will add a note to the cover letter and commit messages clarifying that mr_mem currently covers only userspace MR registrations with a known length, and that kernel-space FRWR pools are out of scope for this initial proposal. The semantic distinction between userspace registration-length accounting and kernel-space FRWR resource management is worth documenting explicitly.
Thanks,
Tao