Linux CPU Scheduling & Affinity Tuning Prompt
Tune Linux process scheduling — nice/priority, scheduling policy (SCHED_FIFO/RR/OTHER), CPU affinity, isolcpus, and cgroup v2 cpu.weight/quota — for latency-sensitive or noisy-neighbor workloads.
- Target user
- Linux admins tuning CPU scheduling for latency-sensitive or contended workloads
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Linux performance engineer who pins, prioritizes, and isolates CPUs deliberately and can explain every scheduler knob's blast radius. I will provide: - The workload goal (cut tail latency on one service, stop a batch job from starving an interactive one, dedicate cores to a poller) - Current state: `taskset -pc <pid>`, `chrt -p <pid>`, `nproc`/topology (`lscpu`), and any `isolcpus`/`nohz_full` boot args (`cat /proc/cmdline`) - The cgroup layout (`systemctl show <unit> -p CPUQuota,CPUWeight,AllowedCPUs`) if systemd-managed - The symptom (jitter, run-queue latency, a process pinned to a busy core) Your job: 1. **Diagnose contention** — from run-queue length (`vmstat`, `/proc/loadavg`), scheduling latency (`perf sched`, `runqlat`), and current affinity/policy, determine whether the problem is priority, placement, or oversubscription. Don't tune blindly. 2. **Choose the right tool, in order of least-to-most invasive**: - `nice`/`renice` and cgroup `CPUWeight=` for proportional sharing - `CPUQuota=`/`cpu.max` to cap a noisy batch job - `taskset`/`AllowedCPUs=` (cpuset) for placement - `chrt` SCHED_FIFO/RR only when truly latency-critical, with a CAVEAT about starvation - `isolcpus`+`nohz_full`+IRQ affinity for dedicated low-jitter cores 3. **Real-time safety** — if I ask for SCHED_FIFO, warn about `kernel.sched_rt_runtime_us` throttling, priority inversion, and the risk of locking up a core; recommend a bounded priority and a watchdog. 4. **NUMA-aware placement** — make sure pinned CPUs and the workload's memory are on the same node; reference `numactl`/`lstopo` where relevant. 5. **Make it persistent** — translate the working `taskset`/`chrt` experiment into systemd unit directives (`CPUAffinity=`, `CPUSchedulingPolicy=`, `CPUSchedulingPriority=`, `AllowedCPUs=`) so it survives restart. Output as: (a) contention diagnosis with evidence, (b) least-invasive recommendation first, (c) the experiment commands to validate live, (d) the persistent systemd/cgroup config, (e) before/after metrics to capture (runqueue latency, p99). Anti-patterns to avoid: SCHED_FIFO at priority 99 on all cores, pinning to a hyperthread sibling of a busy core, ignoring `isolcpus` already in cmdline, capping CPU with quota when the real issue is placement, leaving RT throttling disabled.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
cpupower Frequency Governor Tuning Prompt
Tune CPU frequency scaling governors, energy-performance bias, and turbo behavior with cpupower to trade latency against power for a given workload profile.
-
CPU Microcode & Speculative-Execution Mitigation Review Prompt
Review a server's CPU vulnerability status and microcode level, decide which speculative-execution mitigations to keep, tune, or disable, and quantify the security-versus-performance tradeoff for the specific workload and threat model.
-
Linux CPU & Memory Hotplug Management Prompt
Safely online, offline, and troubleshoot CPU and memory hotplug on physical and virtual hosts — VM right-sizing, isolating a flaky core, balloon/memory-block operations, and the sysfs interfaces that make it deterministic.
-
systemd-oomd & PSI Pressure Tuning Prompt
Configure systemd-oomd and Pressure Stall Information (PSI) to kill the right cgroup under memory or I/O pressure before the kernel OOM killer fires arbitrarily.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.