Skip to content

Tune NIC IRQ affinity and RSS queues on a busy Linux server

Prove that one CPU is absorbing every network interrupt, then fix it: size RSS queues with ethtool -L, pin queue IRQs with smp_affinity_list, keep irqbalance out of the way, and use RPS when the NIC has a single queue.

When a Linux server stops scaling with packet rate, the usual cause is that all of the network interrupt work has collapsed onto one CPU: a single core pegged in softirq time while the other thirty-one idle, and packets dropping even though the box looks mostly idle in aggregate. This guide shows how to prove that from /proc/interrupts, /proc/softirqs and /proc/net/softnet_stat, then how to fix it by giving the NIC more receive queues and pinning each queue’s interrupt to its own CPU on the right NUMA node. It also covers RPS for single-queue NICs, the latency that interrupt coalescing costs you, and the far more common case where none of this is the answer.

What you’ll accomplish

  • Prove from three independent counters whether one CPU is absorbing every network interrupt, before touching anything.
  • Count and resize the NIC’s hardware receive queues with ethtool -l and ethtool -L.
  • Pin each queue’s IRQ to a CPU on the NIC’s own NUMA node, and stop irqbalance silently undoing it.
  • Fall back to RPS and XPS when the hardware offers only one queue.
  • Tell ring-buffer drops apart from backlog drops and NAPI time squeezes, so you turn the knob that matches the symptom.

Prerequisites

  • root or sudo on the host that owns the NIC. This is host-level tuning: a container cannot do it, and inside a VM you are tuning the virtual NIC, not the physical one.
  • ethtool, sysstat for mpstat, and gawk for hex arithmetic: apt install ethtool sysstat gawk or dnf install ethtool sysstat gawk.
  • Any current kernel. The paths used here — /proc/irq/<n>/, /sys/class/net/<iface>/queues/ — have been stable for a decade.
  • A baseline: today’s packet rate, drop count and softirq CPU time. Without it you cannot tell whether a change helped.
  • Honest caveats. Many drivers use kernel-managed interrupt vectors, and writing to smp_affinity on those returns an error by design. Virtual NICs vary: virtio-net exposes real per-queue IRQs when the hypervisor gave it several, while some cloud NICs refuse affinity changes entirely.

How it works

A packet arriving on a multi-queue NIC is hashed by the card itself. Receive Side Scaling hashes the flow’s addresses and ports, indexes an indirection table, and drops the packet into one of several hardware receive queues. Each queue owns a distinct MSI-X vector with its own entry under /proc/irq/, and that entry’s affinity mask decides which CPU runs the handler — and therefore which CPU runs the NET_RX softirq where NAPI polls the queue and pushes packets up to a socket.

Diagram of the packet receive path: a packet arrives, the NIC RSS hash selects a receive queue, that queue raises its own MSI-X interrupt, and the IRQ smp_affinity_list setting picks which CPU runs NAPI; below, a badly pinned setup with every queue landing on CPU0 is contrasted with a spread setup with one queue per CPU

That chain is where the imbalance hides. RSS can spread traffic across eight queues and still buy you nothing if all eight IRQs point at CPU0 — the hardware fanned out, then the software funnelled it straight back in. Because most monitoring averages across cores, this reads as “the server is fine” right up until it isn’t.

Two properties of the affinity mask matter. /proc/irq/<n>/smp_affinity is a hexadecimal bitmask while /proc/irq/<n>/smp_affinity_list is the same thing as a CPU list — smp_affinity of 10 means CPU 4, whereas smp_affinity_list of 10 means CPU 10. And a mask may name several CPUs while the interrupt controller delivers to exactly one; /proc/irq/<n>/effective_affinity_list reports which. Pin to a single CPU and there is nothing to guess about.

NUMA is the other half. On a two-socket machine the NIC hangs off one socket’s PCIe root complex, and an interrupt handled on the other socket drags every descriptor and header across the interconnect. /sys/class/net/<iface>/device/numa_node names the NIC’s node and local_cpulist names the CPUs on it. The same reasoning that governs CPU pinning and NUMA alignment for VMs applies: keep the work next to the memory it touches.

Step-by-step

  1. Prove the imbalance before you touch anything. Watch per-core softirq time under real load. The %soft column is the one that matters.

    mpstat -P ALL 1 5

    Success signal: one row per CPU. If a single CPU shows %soft in the tens of percent while every other CPU is near zero, you have found the problem. If softirq time is already spread, stop here — the bottleneck is elsewhere and pinning will not help.

  2. Confirm it in the interrupt counters. /proc/interrupts gives one row per IRQ and one column per CPU; the last column is the device name the driver registered.

    grep -E 'eth0|CPU0' /proc/interrupts

    Success signal: one row per NIC queue, named something like eth0-TxRx-0 through eth0-TxRx-7. Sample it twice a second apart; if every increment lands in the same CPU column, the IRQs are stacked. Driver naming varies — Intel uses i40e-eth0-TxRx-0, Mellanox mlx5_comp0@pci:..., AWS ENA eth0-Tx-Rx-0 — so adjust the pattern to what your file actually contains.

  3. Cross-check the softirq side. Interrupt counts tell you where the handler ran; /proc/softirqs tells you where the packet processing ran.

    grep -E 'NET_RX|NET_TX' /proc/softirqs

    Success signal: two rows of per-CPU counters. A hot NET_RX column matching the hot column in /proc/interrupts confirms the diagnosis. Disagreement usually means RPS is already redistributing work, which changes what you should fix.

  4. Find out how many queues the NIC actually has. You cannot spread across queues that do not exist.

    ethtool -l eth0

    Expected output:

    Channel parameters for eth0:
    Pre-set maximums:
    RX:		n/a
    TX:		n/a
    Other:		1
    Combined:	16
    Current hardware settings:
    RX:		n/a
    TX:		n/a
    Other:		1
    Combined:	4

    Combined under Pre-set maximums is the ceiling; the one under Current hardware settings is live. A card reporting a maximum of 1 has no RSS to tune — skip to step 9. Some cards separate RX and TX instead of using Combined; tune whichever field is not n/a.

  5. Locate the NIC’s NUMA node and its local CPUs. Do this before choosing which CPUs to pin to.

    cat /sys/class/net/eth0/device/numa_node
    cat /sys/class/net/eth0/device/local_cpulist

    Success signal: a node number such as 0 and a CPU list such as 0-15,32-47. A numa_node of -1 means the platform did not report locality — common on single-socket machines and in VMs — in which case ignore NUMA and pin to any CPUs.

  6. Set the queue count. One queue per CPU you intend to dedicate is the usual target. Do not exceed the number of CPUs on the NIC’s NUMA node.

    sudo ethtool -L eth0 combined 8

    Success signal: the command returns silently and ethtool -l eth0 reports Combined: 8 under current settings. Expect the link to bounce on many drivers, and expect IRQ numbers to be reallocated — any affinity you set earlier is gone. Operation not supported means the driver needs a module parameter at load time instead.

  7. Stop irqbalance from fighting you, without disabling it. irqbalance periodically rewrites affinity masks, so a manual pin can survive for seconds and then quietly revert. The blunt fix is to stop the daemon, but it is also balancing storage and NVMe interrupts. Ban the specific NIC IRQs instead.

    for irq in $(grep -E 'eth0-(TxRx|Tx-Rx|rx)-' /proc/interrupts | cut -d: -f1 | tr -d ' '); do
      printf ' --banirq=%s' "$irq"
    done; echo

    That prints the argument list. Put it in the daemon’s option file — /etc/default/irqbalance on Debian and Ubuntu (OPTIONS=), /etc/sysconfig/irqbalance on the RHEL family (IRQBALANCE_ARGS=) — then restart it.

    sudo systemctl restart irqbalance
    systemctl show -p ExecStart irqbalance

    Success signal: ExecStart echoes the --banirq arguments you added. On hosts with many NICs, IRQBALANCE_BANNED_CPULIST scales better: it tells the daemon to leave a set of CPUs alone entirely. Keeping userspace off those same cores is a separate lever — see cgroup v2 resource control.

  8. Pin one queue IRQ per CPU. Write to smp_affinity_list, not smp_affinity, so you are writing CPU numbers rather than a bitmask.

    IFACE=eth0
    # CPUs on the NIC's own NUMA node, taken from local_cpulist above
    CPUS=(0 1 2 3 4 5 6 7)
    i=0
    for irq in $(grep -E "${IFACE}-(TxRx|Tx-Rx|rx)-" /proc/interrupts | cut -d: -f1 | tr -d ' '); do
      echo "${CPUS[$i]}" | sudo tee /proc/irq/${irq}/smp_affinity_list >/dev/null
      i=$(( (i + 1) % ${#CPUS[@]} ))
    done

    Verify what actually took effect, which is not always what you wrote:

    for irq in $(grep -E 'eth0-(TxRx|Tx-Rx|rx)-' /proc/interrupts | cut -d: -f1 | tr -d ' '); do
      printf 'irq %s requested=%s effective=%s\n' "$irq" \
        "$(cat /proc/irq/$irq/smp_affinity_list)" \
        "$(cat /proc/irq/$irq/effective_affinity_list 2>/dev/null)"
    done

    Success signal: each IRQ maps to a distinct CPU and effective matches requested. A write that fails with Input/output error means the driver uses kernel-managed vectors — see Troubleshooting.

  9. If the NIC has only one queue, use RPS instead. Receive Packet Steering hashes in software after the interrupt and hands packets to other CPUs’ backlogs. It costs an inter-processor interrupt per batch, so it is a fallback, not a first choice. rps_cpus takes a hexadecimal mask, not a list.

    # spread to CPUs 1-7 on an 8-core box, leaving CPU0 for the interrupt itself
    echo fe | sudo tee /sys/class/net/eth0/queues/rx-0/rps_cpus

    Success signal: reading the file back returns fe. Pair it with Receive Flow Steering so packets follow the CPU the application runs on, and set XPS so transmits use the queue matching the sending CPU:

    sudo sysctl -w net.core.rps_sock_flow_entries=32768
    echo 32768 | sudo tee /sys/class/net/eth0/queues/rx-0/rps_flow_cnt
    echo 1 | sudo tee /sys/class/net/eth0/queues/tx-0/xps_cpus
  10. Adjust coalescing last, and only if you have a reason. Coalescing makes the NIC wait before raising an interrupt, trading latency for fewer interrupts and lower CPU.

    ethtool -c eth0

    Success signal: a block listing Adaptive RX: on TX: on, then rx-usecs, rx-frames and their transmit counterparts. If adaptive mode is on, the driver is already varying these with load; usually leave it alone. To raise the holdoff manually:

    sudo ethtool -C eth0 adaptive-rx off rx-usecs 100 rx-frames 64

    Every microsecond of rx-usecs is added latency for a packet arriving just after the timer resets. On a throughput-bound batch pipeline that is a fine trade; on a latency-sensitive RPC service it is exactly the wrong one. Many drivers support only a subset of these fields and return Operation not supported for the rest.

  11. Make it survive a reboot. IRQ numbers are allocated when the driver brings the interface up, so persistence means re-running the pinning, not writing a static file.

    sudo tee /usr/local/sbin/nic-irq-affinity.sh >/dev/null <<'EOF'
    #!/bin/bash
    # re-pin NIC queue IRQs; IRQ numbers change on every driver load
    IFACE=eth0
    CPUS=(0 1 2 3 4 5 6 7)
    i=0
    for irq in $(grep -E "${IFACE}-(TxRx|Tx-Rx|rx)-" /proc/interrupts | cut -d: -f1 | tr -d ' '); do
      echo "${CPUS[$i]}" > /proc/irq/${irq}/smp_affinity_list
      i=$(( (i + 1) % ${#CPUS[@]} ))
    done
    EOF
    sudo chmod 755 /usr/local/sbin/nic-irq-affinity.sh

    Wire it to a systemd oneshot ordered after the network comes up, and re-run it any time you change the queue count with ethtool -L.

Validate it works

Re-run the same three measurements under the same load, and compare against the baseline you took in step 1.

mpstat -P ALL 1 5

Expected: %soft now appears on several CPUs at a fraction of the previous peak, with no single core dominating.

Read the software-side counters. In /proc/net/softnet_stat there is one hexadecimal line per CPU: column 1 is packets processed, column 2 is packets dropped because the backlog was full, and column 3 is time_squeeze — how often NAPI exhausted its budget with work still pending.

gawk '{printf "cpu%-3d processed=%d dropped=%d squeezed=%d\n", NR-1, strtonum("0x"$1), strtonum("0x"$2), strtonum("0x"$3)}' /proc/net/softnet_stat

Expected: processed spread across CPUs rather than concentrated on one, dropped static, and time_squeeze growing slowly or not at all. Then the hardware side, where the driver reports what the card itself saw:

ethtool -S eth0 | grep -Ei 'drop|miss|err|no_buf'

Expected: counters like rx_missed_errors, rx_no_buffer_count or rx_dropped holding steady. Finish with the protocol counters, where TcpExtTCPBacklogDrop and UdpRcvbufErrors should be stable (netstat -s prints the same information in prose):

nstat -az | grep -Ei 'drop|error|prune'

The decision path below maps each of these symptoms onto the one knob that addresses it.

Decision diagram mapping each symptom to a single lever: one CPU pegged in softirq time leads to checking the Combined queue count and either setting queues with ethtool -L or enabling RPS; ethtool -S drops with idle CPUs lead to growing the rx ring; a rising time_squeeze leads to raising netdev_budget; a latency regression leads to lowering rx-usecs

Troubleshooting

  • Writing to smp_affinity_list returns Input/output error. The driver requested kernel-managed interrupt vectors, and the kernel spread them across CPUs itself at probe time. This is not a permissions problem and sudo will not help. Read /proc/irq/<n>/effective_affinity_list: usually it is already distributed, because the kernel did by design the job you were about to do by hand.
  • The pinning reverted a few seconds later. irqbalance rewrote it. Confirm your --banirq arguments are in the running command line via systemctl show -p ExecStart irqbalance. The common mistakes are editing the option file without restarting the daemon, and banning IRQ numbers from before an ethtool -L reallocated them.
  • Queues are pinned correctly but one CPU is still hot. RSS is hashing your traffic into a single queue: one large flow, encapsulated traffic whose outer headers repeat for every inner flow (GRE, and VXLAN on cards that do not parse inner headers), or a hash covering addresses only. Check with ethtool -n eth0 rx-flow-hash udp4; if ports are absent, add them with ethtool -N eth0 rx-flow-hash udp4 sdfn, and inspect the indirection table with ethtool -x eth0.
  • Drops continue with every CPU idle. The CPUs were never the constraint. Rising rx_no_buffer_count or rx_missed_errors in ethtool -S means descriptors ran out between polls: grow the ring with ethtool -G eth0 rx 4096, or reduce the holdoff so the card is serviced sooner. Rising time_squeeze means the opposite — NAPI is cut off mid-poll — and net.core.netdev_budget (default 300) plus net.core.netdev_budget_usecs are the knobs. A rising column 2 points at net.core.netdev_max_backlog.
  • Latency got worse after the change. Almost always coalescing. Check ethtool -c eth0 for a large rx-usecs and either lower it or turn adaptive-rx on. If you changed coalescing and pinning in the same window, revert the coalescing first — pinning does not add latency, holdoff timers do.

When this is the wrong approach

Most servers should never do any of this. Modern drivers allocate one queue per CPU and let the kernel place the vectors, and irqbalance handles the rest competently. If your server is not measurably saturating a CPU in softirq time, hand-pinning IRQs buys nothing and costs you a brittle boot-time script that stops matching reality the first time the NIC is replaced or the driver renumbers its vectors.

Inside a VM you are tuning the guest’s virtual NIC, which can help when the hypervisor gave it several queues — but the physical NIC’s queues belong to the host. In a container it is worse: /proc/irq is not yours to write, and the fix belongs on the node.

If the traffic is one heavy flow, RSS cannot help by construction: a single 5-tuple hashes to one queue, and splitting it would reorder packets. Scale the number of connections instead. And if the box drops packets because the application is not reading its sockets fast enough, the drops land in UdpRcvbufErrors or TcpExtTCPBacklogDrop rather than in the driver, and no interrupt tuning will touch them.

Where this pays off is a narrow band: bare-metal hosts pushing millions of packets per second — routers, load balancers, packet capture, high-rate telemetry ingest — where a single core saturating in softirq time is the measured ceiling. The kernel’s own Scaling in the Linux Networking Stack document is the reference for these mechanisms and is worth reading before you commit to a layout.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.