The Mechanics of ibv_reg_mr and Page Pinning
kswapd) can reclaim, compress, or migrate physical pages across NUMA nodes, modifying the page tables at will. If an HCA initiated a PCI Express DMA read or write against a virtual memory address that had been paged out or migrated, physical host memory would be silently corrupted.
To prevent this, RDMA user-space libraries (libibverbs) expose the Memory Region registration primitive, ibv_reg_mr. Beneath the userland call, the Mellanox/NVIDIA OFED driver issues a pin_user_pages() or pin_user_pages_fast() invocation inside the Linux memory management subsystem. This increments the page reference count (page_ref_inc) and marks the backing struct page structures as permanently unevictable. The kernel guarantees that physical frame addresses mapped into the HCA's internal Memory Translation Table (MTT) remain frozen in physical RAM until explicitly released by ibv_dereg_mr.
BASH
# Standard HPC container profile granting unrestricted physical pinning
docker run --security-opt seccomp=unconfined \
--ulimit memlock=-1:-1 \
--device=/dev/infiniband/uverbs0 \
-m 64g --memory-swap 64g pytorch-nccl:latestThe Cgroups v2 Accounting Blind Spot
memory.max in a cgroups v2 slice provides hard boundaries. If an application attempts to allocate past this ceiling, the kernel invokes local cgroup reclamation. If anonymous pages and page caches cannot be purged, the in-cgroup Out-Of-Memory (OOM) killer terminates a task inside that slice, preserving host stability.
However, the interaction between pinned RDMA pages and cgroup accounting is fraught with historical edge cases. Because distributed AI practitioners routinely encounter cannot allocate memory errors when initializing NCCL ring buffers, the reflexive fix across the industry has been granting containers ulimit -l unlimited (RLIMIT_MEMLOCK). Once a containerized process pins hundreds of gigabytes of registered memory, those pages are immune to reclamation.
While modern Linux kernels (5.19+) have increasingly moved pinned RDMA pages under cgroup charge paths via mm_struct accounting, the kernel's memory reclaim algorithms still cannot move or evict a pinned page. When a container approaches its memory.max threshold, the kernel's memory controller enters synchronous reclaim (try_to_free_mem_cgroup_pages). It scans the Least Recently Used (LRU) lists, only to find that the overwhelming majority of resident physical frames are locked into hardware MTTs. The scanning loops burn 100% CPU time in kernel space trying to reclaim un-reclaimable pages, creating massive soft-lockups. Worse, if the host memory pressure spills over before the local cgroup OOM killer can resolve the allocation debt, the global host OOM killer wakes up and frequently terminates sshd, kubelet, or the fabric monitoring daemons instead of the compute payload.
Queue Pair Corruption and Fabric Domino Effects
SIGKILL, an active InfiniBand Queue Pair (QP) maintains in-flight Remote Memory Access reads, writes, and Atomic operations directly across the PCIe bus.
If the host kernel abruptly tears down the process address space while an HCA has work requests queued in its Completion Queue (CQ) or Send Queue (SQ), the hardware attempts to write completion status entries to virtual addresses that have been invalidated. In poorly orchestrated orchestrators, this manifests as a PCIe Completion Timeout (CTO) or fatal HCA firmware assert. The Mellanox driver logs an unrecoverable error (mlx5_core: cmd[0]: DEREG_MR(0x...) failed), requiring a full host PCIe reset or cold reboot. A single misbehaving training script does not just fail in its own container; it poisons the physical HCA, rendering the node unreachable on the InfiniBand subnet and halting the entire multi-node training job.
Hardening Multi-Tenant RDMA Isolation
-
Abolish Unbounded RLIMIT_MEMLOCK: Never set
memlocktounlimitedin orchestration templates. Determine the exact pin requirements for the communication buffers. For NCCL, this is typically proportional to the ring buffer size multiplied by the number of channels and local GPUs (rarely exceeding 8GB to 16GB), plus any pinned CUDA host memory. Set hard boundaries in the container specification (rlimits.memlock = [max_expected_pinned_bytes]). -
Align Memory Headroom with Cgroups v2: When calculating
memory.max, enforce a minimum buffer of at least 20% between the peak registered memory footprint and the cgroup threshold. Because pinned pages cannot be evicted, the cgroup must have enough reclaimable space (such as standard page caches and unpinned anonymous heap) to allow the kernel's memory subsystem to handle normal lifecycle allocations without spiraling into spinlock contention. -
Use eBPF to Track Unregistered MR Leaks: Deploy eBPF probes attached to the
ibv_reg_mrandibv_dereg_mrentry points (tracepoints in themlx5_ibdriver). Track the cumulative delta of registered memory against the process cgroup ID. When an engine fails to deregister regions or exhibits runaway registration loops, orchestrators can detect the degradation early and trigger graceful draining via NCCL abort handlers before the kernel is forced to invoke a destructive global OOM.
