Skip to main content

Resource Pinning and Limits

When running Steam Headless alongside other homelab services or hosting multiple gaming sessions on a single server, allocating host resources effectively is essential. Under Linux, container engines use kernel control groups (cgroups v2) to control how CPU time, CPU cores, system memory, and GPU access are partitioned.

This guide explains how resource pinning and limits interact with gaming workloads, why rigid constraints often degrade performance, and how to configure elastic boundaries that protect critical host services without compromising gameplay smoothness.

Performance Finding: Avoid Over-Constraining Gaming Containers

In multi-seat and multi-game performance benchmarking, hard resource pinning and artificial limits provided minimal real-world performance benefit and frequently degraded gameplay. Modern Linux kernel schedulers (such as CFS and EEVDF) and graphics drivers dynamically arbitrate CPU cycles, GPU execution queues, and memory with exceptional efficiency. Games are inherently bursty workloads: during scene transitions, level loading, and shader compilation, a game benefits substantially from borrowing temporarily idle CPU cores and available system memory. For dedicated gaming environments, leaving CPU and GPU scheduling unconstrained allows the kernel to burst threads across all available cores, delivering smoother 1% low frame rates and lower loading times.


When should resource limits be used?​

While gaming containers perform best when allowed to burst freely, resource constraints are valuable when you need to protect non-gaming host workloads from being starved of resources:

  • Storage integrity operations: Background tasks such as Unraid array parity checks, TrueNAS ZFS pool scrubs, and ZFS pool resilvering require continuous disk throughput and CPU cycles. An unconstrained game running 100% CPU across all cores can significantly prolong these maintenance jobs.
  • Media and streaming servers: If your server hosts Plex, Jellyfin, or Emby, sudden CPU or memory spikes from a game could interrupt real-time video transcoding streams for other household users.
  • Core infrastructure services: Home automation controllers (Home Assistant), host databases (PostgreSQL, MariaDB), and network-attached storage daemons (NFS, Samba) require predictable low-latency response times that should not be compromised by a game compiling shaders.

In these environments, isolating one or two CPU cores for the host operating system and configuring elastic soft memory reservations guarantees host stability while preserving an excellent gaming experience.


CPU core pinning and affinity (cpuset)​

CPU pinning binds a container's processes to specific physical or logical processor cores using the Linux kernel cpuset cgroup controller (cpuset.cpus). When assigned a core set, container threads are restricted to those cores and will not be migrated elsewhere by the scheduler.

Cache hierarchy and NUMA topology​

Modern processors organise cores into hierarchical groups sharing Level 3 (L3) caches. Multi-die processors—such as AMD Ryzen 9 (5900X, 7900X, 5950X, 7950X), AMD Threadripper, and multi-socket Intel Xeon systems—partition cores across multiple Core Complex (CCX) chiplets or Non-Uniform Memory Access (NUMA) nodes:

  • Intra-CCX communication: Cores within the same CCX communicate via high-speed, shared L3 cache with minimal latency.
  • Inter-CCX communication: Communicating across CCX or NUMA boundaries requires data to traverse the AMD Infinity Fabric or Intel Ultra Path Interconnect (UPI), introducing measurable latency penalties.
Keep Cores Within the Same CCX

If you choose to pin CPU cores, ensure all cores allocated to a single container reside within the same physical CCX or NUMA node. For example, on a 12-core AMD Ryzen 9 5900X (two 6-core CCXs), assign cores 0-5 (CCX0) to Container A and cores 6-11 (CCX1) to Container B. Avoid splitting a container across CCX boundaries (such as assigning cores 3-8), as this incurs cross-fabric cache synchronisation overhead. Inspect your host's cache layout using lscpu --extended or lstopo.

Why hard CPU pinning can hurt 1% low frame rates​

While CPU pinning prevents containers from contending for the exact same physical cores, rigid core pinning often harms real-world game pacing:

  1. Bursty asset decompression and shader compilation: Modern games rarely execute an even, predictable number of threads. While the main game logic and render submission loop might utilise only two to four cores, background worker threads frequently spin up dozens of short-lived tasks to decompress textures and compile graphics pipelines.
  2. Main thread contention under strict pinning: When a container is confined to a rigid four-core allocation, background asset streaming threads are forced to time-share those same four cores with the primary render loop. This leads to scheduler preemption, delaying frame dispatch and causing noticeable 1% and 0.1% low frametime spikes (micro-stutter).
  3. Kernel scheduling advantages: Without artificial pinning, the Linux kernel scheduler (CFS or EEVDF) immediately spills background asset decompression threads onto temporarily idle sibling cores across the host, leaving the game's critical render threads uninterrupted.

System memory limits: Soft limits vs hard limits​

Memory allocation under Docker cgroups v2 supports two distinct throttling models: hard limits (mem_limit / memory) and soft limits (mem_reservation / memory-reservation). Understanding the difference between these boundaries is critical for gaming stability.

Limit TypeCompose DirectiveDocker CLI FlagLinux Kernel MechanismConsequence When Exceeded
Hard Limitmem_limit--memorymemory.maxImmediate process termination by the kernel OOM killer (SIGKILL).
Soft Limitmem_reservation--memory-reservationmemory.low / memory.highElastic threshold: Container can burst freely; kernel reclaims memory only under host contention.

The danger of hard memory limits​

A hard memory limit sets an absolute physical ceiling on the container's memory consumption. If the total allocated memory—including Proton/Wine runtimes, game heaps, Mesa shader caches, and desktop compositor buffers—exceeds this boundary by even a single byte:

  • The Linux kernel Out-Of-Memory (OOM) killer is invoked instantly.
  • The kernel selects the highest-consuming process (almost always steam, wine64-preloader, or the game executable itself) and terminates it immediately with SIGKILL.
  • The user experiences an abrupt game crash with zero warning or error dialogue, or KWin terminates and drops the stream session entirely.

Because modern 3D games frequently allocate large temporary working buffers during level loads or asset streaming, setting a rigid hard limit that accommodates average gameplay will inevitably cause crashes during peak allocation bursts.

The safety of soft memory reservations​

A soft memory limit establishes an elastic reservation rather than a rigid ceiling:

  1. Unrestricted bursting: When the host has surplus unallocated physical RAM, the gaming container is permitted to consume as much memory as it needs beyond its soft reservation.
  2. Contention-driven reclamation: If the host operating system experiences memory pressure (for instance, when a scheduled ZFS pool scrub begins or a backup job launches), the kernel memory manager prioritises reclaiming memory from containers exceeding their reservation first.
  3. Graceful page trimming: The kernel reclaims clean file caches and inactive anonymous memory before considering process termination. Games continue executing smoothly without triggering sudden OOM terminations.
Memory Configuration Recommendation

For optimal gaming reliability, avoid setting hard memory limits on Steam Headless containers. Instead, set a generous soft memory reservation (mem_reservation: 12g to 16g). This guarantees the container access to baseline memory while allowing it to burst during demanding gameplay sequences, leaving the host operating system protected against total memory exhaustion.


GPU dedicated video memory (VRAM / DMEM) constraints​

Certain container environments and GPU runtime configurations offer mechanisms to constrain video memory (DMEM / VRAM) or compute quotas, particularly when using the NVIDIA Container Toolkit.

Do Not Apply Synthetic VRAM or GPU Memory Limits

Extensive testing has established that synthetic GPU memory and VRAM constraints provide virtually no performance value and frequently trigger catastrophic game crashes. Graphics APIs (Vulkan, DXVK, and VKD3D-Proton) and modern game engines expect direct, unconstrained visibility into the physical graphics adapter's memory heaps. Games query VRAM availability using vkGetPhysicalDeviceMemoryProperties and design their texture streaming budgets accordingly. When synthetic container boundaries intercept GPU memory requests, the graphics driver returns VK_ERROR_OUT_OF_DEVICE_MEMORY. Because games rarely implement graceful fallbacks for unexpected device memory errors, the game crashes to desktop immediately.

How Linux graphics drivers manage VRAM naturally​

Linux Direct Rendering Manager (DRM) drivers (amdgpu, i915, xe, and NVIDIA) and kernel memory managers (such as the Translation Table Manager, or TTM) already provide sophisticated memory arbitration:

  • Automatic buffer eviction: When physical VRAM becomes fully saturated, the GPU memory manager automatically evicts inactive texture and vertex buffers to host system RAM (GTT memory) across the PCIe bus.
  • Hardware-level queue scheduling: The GPU hardware scheduler shares compute and 3D render pipelines dynamically across concurrent contexts without requiring container-level intervention.
  • Resilience over crashing: While spilling textures into GTT system memory can introduce minor frametime dips when accessing evicted buffers, the game continues running reliably rather than crashing with device memory errors.

If you require strict VRAM isolation between concurrent gaming sessions, assign dedicated physical GPUs to individual containers (as detailed in the separate rendering and encoding GPUs guide) rather than attempting to enforce synthetic VRAM limits.


Configuration examples​

The following examples demonstrate how to apply CPU pinning alongside soft and hard memory limits. Adjust the core masks and memory values to match your host hardware configuration.

In your docker-compose.yml, define CPU pinning via cpuset and memory boundaries using mem_reservation (soft limit) and mem_limit (hard limit):

docker-compose.yml
services:
desktop-a:
image: josh5/steam-headless:2
container_name: steam-headless-a
hostname: steam-headless-a
restart: unless-stopped
privileged: false

# CPU core pinning: Binds container to physical cores 0, 1, 2, and 3
cpuset: '0-3'

# Elastic soft memory reservation: Guarantees 12 GiB under host pressure
mem_reservation: 12g

# Optional hard memory ceiling: Only use if strictly necessary to protect the host
# mem_limit: 20g

# Standard container security, devices, and shared memory
shm_size: 2gb
pids_limit: 8192
cap_add:
- DAC_READ_SEARCH
- NET_ADMIN
- SYS_ADMIN
- SYS_NICE
- SYS_PTRACE
security_opt:
- seccomp=unconfined
- systempaths=unconfined
- writable-cgroups=true
devices:
- /dev/dri/renderD128:/dev/dri/renderD128
- /dev/fuse:/dev/fuse
- /dev/uinput:/dev/uinput
- /dev/uhid:/dev/uhid
device_cgroup_rules:
- 'c 13:* rwm'
tmpfs:
- /run
- /run/lock
- /tmp
- /dev/input:rw,dev,mode=0755

Platform-specific considerations​

Depending on your host operating system and orchestration tooling, the mechanism for applying CPU and memory constraints varies.

Unraid​

On Unraid servers, resource settings are split between the graphical template interface and manual arguments:

  1. CPU Pinning via WebGUI:
    • In the Unraid WebGUI, navigate to the Docker tab and click on your Steam Headless container template.
    • Expand the CPU Pinning section.
    • Check the boxes corresponding to the CPU cores you wish to assign to the container. Unraid groups logical threads by physical core, allowing you to select paired hyperthreaded cores easily.
  2. Memory Limits via Extra Parameters:
    • Unraid's default container template does not provide dedicated input fields for memory thresholds.
    • Toggle the template view to Advanced View (top-right toggle switch).
    • In the Extra Parameters field, enter your memory reservation flags alongside any other runtime arguments (such as --runtime=nvidia):
      --memory-reservation=12g
    • Click Apply to recreate the container with the specified parameters.

TrueNAS SCALE​

TrueNAS SCALE provides native Docker Compose application management (either through custom Compose applications or external management tools such as DockHand or Portainer):

  • Direct Compose compatibility: Because TrueNAS SCALE relies on standard Docker Compose definitions, you can apply the cpuset, mem_reservation, and mem_limit directives directly in your application's Compose YAML as shown in the Compose example above.
  • Accounting for ZFS ARC: TrueNAS SCALE uses the OpenZFS Adaptive Replacement Cache (ARC), which dynamically consumes host physical RAM to cache filesystem reads (often consuming up to 50% or more of available host memory by default). When setting soft memory reservations for Steam Headless containers, ensure the host retains sufficient unreserved RAM for ZFS ARC operations. Setting soft reservations rather than rigid hard limits allows ZFS and gaming sessions to dynamically balance memory without triggering kernel OOM faults during intense storage activity.

Summary recommendations​

To achieve the best balance between gaming performance and host stability:

  1. Default to unpinned CPU scheduling: Allow the Linux kernel scheduler to dynamically distribute threads across all cores unless specific host maintenance tasks suffer from starvation.
  2. Respect CCX boundaries if pinning: When CPU pinning is required, allocate cores within a single CCX or NUMA node to eliminate inter-core fabric latency.
  3. Favour soft memory reservations: Use mem_reservation to safeguard host infrastructure, and avoid rigid mem_limit settings that cause sudden OOM game crashes during allocation bursts.
  4. Leave GPU VRAM unconstrained: Allow GPU DRM kernel drivers to manage VRAM eviction naturally, avoiding synthetic GPU limits that break Vulkan and DXVK allocators.