GrepBoard/Manuals
605 manuals ·

Fix systemd status=215/CPUAFFINITY

·Tested on Ubuntu 24.04 (Docker) · systemd 255 (255.4-1ubuntu8.19) · 2026-11·Test scope ↓·4 steps

Compare CPUAffinity= with the CPUs granted to the service cgroup. Fix systemd status=215/CPUAFFINITY when the requested and permitted CPU lists do not overlap.

output
    Process: 129 ExecStart=/usr/bin/true (code=exited, status=215/CPUAFFINITY)

CPUs 0-3 were online, but the container was limited to CPU 0. The journal recorded this error for the unit with CPUAffinity=1.

output
Nov 23 02:31:44 server1 (true)[129]: gb215-BkL1QpVT-fail.service: Failed to set up CPU affinity: Invalid argument

Changing the request to CPUAffinity=0 gave this status for the control unit.

output
    Process: 153 ExecStart=/usr/bin/true (code=exited, status=0/SUCCESS)

For status=215/CPUAFFINITY, start with the CPU IDs requested by the unit. Even on a machine with several online CPUs, the kernel rejects a mask if the service’s cpuset allows none of those IDs.

[1] Read the unit, its drop-ins and the journal for the failed start. Substitute your unit name for myapp.service.

console
# systemctl cat myapp.service# systemctl show myapp.service -p CPUAffinity -p Slice -p ControlGroup# journalctl -b -u myapp.service -n 40 --no-pager

The v255 source has two branches that return 215. A message containing Failed to set up CPU affinity points to the system call that applies the mask. For Failed to derive CPU affinity mask from NUMA mask, look for CPUAffinity=numa and inspect NUMAMask= first. NUMA node IDs and CPU IDs identify different things.

[2] Read the online list and the effective cgroup v2 cpuset inside the same container. The second command reads the container’s upper limit when its cgroup namespace is private.

console
# cat /sys/devices/system/cpu/online# cat /sys/fs/cgroup/cpuset.cpus.effective

If the unit’s cgroup still exists, append the reported ControlGroup path to /sys/fs/cgroup and read its cpuset.cpus.effective too. If the failed unit’s cgroup has disappeared, inspect its parent slice. The parent list gives an upper bound. If the file is missing, check the cgroup version and controller availability before interpreting the result.

[3] Find the intersection. For example, with CPUs 0-3 online and only CPU 2 granted, read the requested mask as follows.

Example requestCPUs available for the request
CPUAffinity=0 1None. The call fails with EINVAL under these conditions.
CPUAffinity=1 2CPU 2 remains. One disallowed ID in the mask does not explain a failure here.
CPUAffinity=2The entire request fits.

A quota of one CPU’s worth of time does not select one CPU ID. Use the IDs in the effective cpuset when choosing a mask.

[4] Set the unit’s mask to its assigned CPUs. This dedicated drop-in assumes CPU 2 is allocated to the service. Create the drop-in directory if needed and use a fresh filename.

/etc/systemd/system/myapp.service.d/90-cpu-placement.conf
[Service]CPUAffinity=CPUAffinity=2

The empty assignment clears earlier entries. Put the actual assigned IDs on the next line. Repeated nonempty assignments merge. Simply appending another ID can leave the old IDs available if the cpuset expands later.

console
# systemctl daemon-reload# systemctl restart myapp.service# systemctl show myapp.service -p Result -p ExecMainStatus -p MainPID

Restarting interrupts running work. For a long-running service, inspect Cpus_allowed_list in /proc/<PID>/status using the new MainPID. For a completed oneshot, inspect its exit status and latest journal entries. To roll back, remove only the new drop-in, reload and restart. Follow service failure diagnostics if the new attempt reports another code.

Analyze your syslog · journal log in the browser ↗ — nothing is uploaded.

#systemd#cpuaffinity#cpuset