Linux Internals

Linux Softirqs and ksoftirqd Explained for High Network Load

By NileVPS Team · Published · 5 min read

اقرأ المقال بالعربي

When a packet arrives at your server, the network card raises an interrupt and the CPU stops whatever it was doing to deal with it. If the kernel did all the packet processing right there, with further interrupts blocked, the system would become unresponsive under heavy traffic. Linux avoids this by splitting interrupt handling into a tiny urgent part and a larger deferred part. The deferred part very often runs as a softirq. If you have ever seen ksoftirqd/0 near the top of top during a traffic spike, or a high si value in the CPU line, this article explains what is happening and how to read it.

Top halves and bottom halves

A hardware interrupt handler (the "top half") runs with that interrupt line masked on the current CPU and must finish quickly. It typically acknowledges the device, notes that work is pending, and returns. The heavy lifting, such as parsing protocol headers, running netfilter rules or completing block I/O, is pushed to a "bottom half". Linux has several bottom-half mechanisms: softirqs, tasklets (built on softirqs) and workqueues (which run in normal kernel threads and may sleep).

What a softirq is

Softirqs are a small, fixed set of deferred-work types compiled into the kernel. You cannot add new ones from a module. The current list, in priority order, is:

  • HI – high-priority tasklets
  • TIMER – timer wheel expiry
  • NET_TX and NET_RX – network transmit and receive
  • BLOCK – block-device completion
  • IRQ_POLL – polled block I/O
  • TASKLET – normal tasklets
  • SCHED – scheduler load balancing
  • HRTIMER – high-resolution timers
  • RCU – RCU callback processing

A softirq is raised per CPU by setting a bit in a pending mask, and it runs on the same CPU that raised it. This keeps data hot in that CPU's cache and avoids locking, but it also means that if one CPU receives all the network interrupts, that CPU also does all the network softirq work.

When softirqs run

Pending softirqs are processed at a few well-defined points:

  1. On return from a hardware interrupt (irq_exit()).
  2. When kernel code re-enables bottom halves with local_bh_enable().
  3. In the per-CPU kernel thread ksoftirqd/N.

The main loop, __do_softirq(), handles every pending type, and new ones may be raised while it runs. To stop softirqs from monopolising a CPU, the loop gives up after about 2 milliseconds or 10 restarts, or when the current task needs to reschedule. Whatever remains is handed to ksoftirqd, which is a normal scheduled thread competing with user processes.

That is the key insight: seeing `ksoftirqd` busy means softirq work is arriving faster than it can be drained in interrupt context, and the kernel has shifted it to a thread so user tasks still get a turn. On PREEMPT_RT kernels the model differs again, with softirq processing running in thread context almost entirely.

Reading /proc/softirqs

The file /proc/softirqs shows cumulative counts per type and per CPU:

cat /proc/softirqs
watch -d -n1 cat /proc/softirqs

The absolute numbers matter less than the rate and the distribution. If NET_RX grows quickly on CPU0 and barely moves elsewhere, receive processing is concentrated on one core. TIMER and RCU increasing steadily on every CPU is normal background activity.

For time rather than counts, use:

mpstat -P ALL 1      # %soft column per CPU
top                  # press 1, then read "si" per CPU

Softirqs under heavy network load

For receive traffic, the NET_RX softirq runs net_rx_action(), which polls the network driver through NAPI and pushes packets up the stack. It has a budget of packets and time per run; when the budget runs out with work still pending, the kernel counts a "time squeeze" and re-raises the softirq. The details of that polling model are covered in our NAPI article.

The per-CPU counters live in /proc/net/softnet_stat, one line per CPU, in hexadecimal:

cat /proc/net/softnet_stat

The first column is packets processed, the second is packets dropped because the backlog queue was full, and the third is time squeezes. A growing second column means you are losing packets inside the kernel; consider raising net.core.netdev_max_backlog. A growing third column means the softirq repeatedly ran out of budget.

sysctl net.core.netdev_max_backlog
sudo sysctl -w net.core.netdev_max_backlog=5000

How this affects your VPS

On a VPS, your NIC is usually a virtio-net device. Each queue has its own interrupt, and the number of queues determines how many vCPUs can share receive work:

ethtool -l eth0                 # combined channels available and in use
grep virtio /proc/interrupts    # which CPUs take which queue interrupts

If there is only one queue, or all interrupts land on CPU0, enable Receive Packet Steering so softirq work is spread across other CPUs in software:

echo f | sudo tee /sys/class/net/eth0/queues/rx-0/rps_cpus   # CPUs 0-3

Make sure irqbalance is running, or pin queue interrupts manually through /proc/irq/<N>/smp_affinity_list. Remember that softirq time is real CPU time: a small plan handling hundreds of thousands of packets per second may simply need more vCPUs, which you can compare on the pricing page. Also keep in mind that CPU steal makes softirq backlogs worse, because the vCPU that should drain them is not running.

To see which kernel functions dominate, profile system-wide:

sudo perf top -g
sudo perf record -a -g -- sleep 10 && sudo perf report

Functions such as net_rx_action, __netif_receive_skb_core, ip_rcv and netfilter hooks indicate network softirq cost; large nf_hook_slow time points to an expensive firewall ruleset.

FAQ

Is high ksoftirqd CPU usage a bug?

Usually not. It means softirq work exceeded what could be processed at interrupt exit, so the kernel moved it to a schedulable thread. Investigate traffic volume, interrupt distribution and firewall rules before suspecting a kernel problem.

What is the difference between softirqs and tasklets?

Softirqs are a fixed set of types and the same type can run concurrently on several CPUs, so their handlers must be fully reentrant. Tasklets are built on top of softirqs, can be created dynamically by drivers, and a given tasklet never runs on two CPUs at once, which makes them simpler but less scalable.

Can I disable softirqs to save CPU?

No. Networking, timers, block I/O and RCU depend on them. What you can do is reduce the work they do, for example by simplifying iptables or nftables rules, enabling GRO, spreading load with RSS or RPS, and choosing enough vCPUs for your traffic.

Related guides