Bali, Indonesia
Insights

Pinning Memory Past the Limit: Why InfiniBand ibv_reg_mr Defeats cgroups v2 Isolation

October 14, 2026
0:00
A quick look through current infrastructure listings—where hundreds of open postings for InfiniBand network engineers dominate teams at Tesla, NVIDIA, and AMD—reveals a clear pattern: AI data centers are no longer constrained just by raw GPU availability, but by the subtle, brutal failure modes of low-level networking fabrics. When thousands of GPUs exchange tensor gradients over InfiniBand via NCCL, software abstraction layers strip away every millisecond of overhead. Everything relies on kernel bypass and zero-copy Remote Direct Memory Access (RDMA). But stripping away the operating system kernel's arbitration comes at a steep price: standard Linux isolation primitives, specifically cgroups v2 memory controllers, frequently fall blind to pinned host memory, inviting catastrophic host kernel panics.
To achieve wire-speed RDMA throughput at 400Gbps or 800Gbps, the Host Channel Adapter (HCA) must execute Direct Memory Access (DMA) transactions straight into user-space host buffers without involving the CPU. In standard POSIX memory management, pages are dynamic: the kernel page daemon (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:latest
In standard enterprise microservices, setting 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.
When the Linux kernel does finally terminate a container that has pinned gigabytes of memory, another problem emerges: asynchronous hardware teardown. Unlike a conventional socket that cleanly resets on 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.
Isolating multi-tenant workloads in high-performance GPU clusters requires bridging the gap between hardware bypass and Linux kernel enforcement:
  1. Abolish Unbounded RLIMIT_MEMLOCK: Never set memlock to unlimited in 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]).
  2. 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.
  3. Use eBPF to Track Unregistered MR Leaks: Deploy eBPF probes attached to the ibv_reg_mr and ibv_dereg_mr entry points (tracepoints in the mlx5_ib driver). 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.
High-speed fabrics are engineered to remove the operating system from the fast path, but production stability still lives and dies inside the kernel's memory management code. Treating RDMA memory registration as an opaque host permission rather than a strictly metered system resource will inevitably take down entire clusters.