Separating Scheduler Run-Queue Delay from Disk Wait at P99
Application timers only tell you that a storage RPC took 42 milliseconds. They cannot distinguish whether the NVMe queue stalled or a runnable thread waited in the Linux CFS run queue after I/O completion.
During shared-host CPU contention, I/O-bound workers often exhibit a deceptive failure mode: block device hardware latency looks clean in Prometheus (`node_disk_read_time_seconds` barely budges), yet p99 read latencies inside user space jump thirty-fold.
What actually happened sits right at wakeup time: the NVMe IRQ completed in 140 microseconds, woke the sleeping worker thread, and pushed it back onto a busy CPU run queue behind batched analytics jobs or cgroup bandwidth throttling.
Sampling wakeup-to-schedule latency safely
With eBPF kernel tracepoints (sched:sched_wakeup and sched:sched_switch), sampling histograms inside the kernel adds negligible overhead (under 0.5% CPU on typical 8-core nodes) while separating true scheduler delay from storage latency.
# 1. Measure scheduler queueing latency (us) filtered by PID
sudo runqlat-bpfcc -p "$(pgrep -n postgres)" 10 3
# 2. Measure hardware block-layer latency concurrently
sudo biolatency-bpfcc -D 10 3
# 3. Check container cgroup CPU throttling counters
cat /sys/fs/cgroup/cpu.stat | grep -E 'nr_throttled|throttled_usec'
Reading the signature
When NVMe firmware garbage collection triggers, biolatency shifts rightward in the 4–16 ms buckets while runqlat stays clustered below 64 us. Conversely, when cgroup CFS quotas clamp a bursty worker, nr_throttled climbs every second and runqlat shows a flat tail stretching directly to the CFS period boundary (commonly 100 ms).
Keeping both histograms on hand turns vague "slow storage" incident hypotheses into falsifiable kernel evidence within sixty seconds.