irqbalance Command in Linux



The irqbalance command in Linux distributes the hardware interrupts across processors in a multiprocessor system to improve performance. Interrupt Requests (IRQs) are signals sent to a CPU by hardware devices to request immediate processing. When an IRQ is triggered, the CPU pauses its current tasks and handles the interrupt.

By default, interrupts may accumulate on a single CPU, leading to imbalanced CPU usage and potential bottlenecks. This is where the irqbalance command comes in to optimize this distribution.

Table of Contents

Here is a comprehensive guide to the options available with the irqbalance command −

Note − The irqbalance is typically run as a service rather than just a command.

Syntax of irqbalance Command

The syntax of the Linux irqbalance is as follows −

irqbalance [options]

The [options] field is used to specify options to change the command's behavior.

irqbalance Command Options

The options of the irqbalance command are listed below −

Flags Options Description
-o --oneshot Run once, then exit
-d --debug Print debug information (implies --foreground)
-f --foreground Run in the foreground
-j --journal Log output optimized for systemd-journal
-p <threshold> --powerthresh = <threshold> Set the threshold for moving CPUs to power save mode.
-i <irqnum> − --banirq = <irqnum> − Exclude specified IRQ(s) from balancing (Multiple IRQs can also be banned)
-m <module_name> --banmod = <module_name> Exclude specified module(s) from balancing
-c <integer> --deepestcache = <integer> Set cache level for balancing domains (default: 2)
-l <script> --policyscript = <script> Use a custom policy script for IRQ handling
-e <val> --migrateval = <val> Minimum improvement ratio to trigger IRQ migration
-s <file> --pid = <file> Write PID to specified file
-t <time> --interval = <time> Set sampling interval in seconds (default: 10)

Examples of irqbalance Command in Linux

This section will demonstrate the usage of the irqbalance command in Linux with examples −

Running irqbalance as Daemon

Running the irqbalance command starts its daemon and automatically distributes hardware interrupts across available CPU cores.

sudo irqbalance

To verify use the systemctl status command −

sudo systemctl status irqbalance.service
irqbalance Command in Linux1

The above command starts the irqbalance daemon and continuously monitors and balances IRQs to improve system performance.

Running irqbalance One Time

To balance IRQs just once and then exit, use the -o or --one-shot option −

sudo irqbalance -o

The above command balances IRQs once without starting the daemon. It is useful for systems where a quick balance is needed without running the daemon continuously.

Running irqbalance in Foreground with Debugging

To run the irqbalance command in the foreground with debugging information, use the -f or --foreground and -d or --debug options.

sudo irqbalance -f -d
irqbalance Command in Linux2

The above command provides real-time output with debugging information.

Banning Specific IRQs from Balancing

To exclude specific IRQs from balancing, use the -i or --banirq option followed by the IRQ numbers. To list the IRQ number use the following command −

cat /proc/interrupts
irqbalance Command in Linux3

For example, to ban IRQ numbers 53 and 54, use the irqbalance command in the following way −

sudo irqbalance -i 53 54

Banning a Specific Module from Balancing

To ban a specific module from balancing, use the -m or --banmod option with the module name. To list the modules, use the following command −

lsmod
irqbalance Command in Linux4

Note that not all the modules from the list are IRQ-specific. To ban the snd_hda_intel module from balancing, use the following command

sudo irqbalance -m snd_hda_intel

This command prevents the irqbalance daemon from modifying the affinity of all IRQs associated with the specified module

Setting the Power Threshold

Use the -p or --powerthresh option to set the power threshold after which the system will transition to power-saving mode.

sudo irqbalance -p 6

If more than 6 CPUs have low workloads, irqbalance will try to put one CPU into a power-save mode to save energy and prevent unnecessary CPU wake-ups.

Managing Sampling Intervals

To manage the sampling intervals, use the -t or --interval options with the number of seconds.

sudo irqbalance -t 6

The above command changes the default measurement interval for IRQ load sampling from 10 seconds to 6 seconds.

Specifying Deepest Cache Levels

The default deepest cache level is 2. To modify it, use the -c or --deepestcache option −

sudo irqbalance -c 3

Note that it can also lead to inefficiencies if set too high on systems where all CPUs share the deepest cache.

Using a Custom Policy Script

To use the custom policy script with the irqbalance command, use the -l or --policyscript option with the path of the script.

sudo irqbalance -l /path/to/script

The above command allows you to specify a custom script executed for each detected IRQ.

Running with Log Output

To enable logging optimized for the systemd-journal, use the -j or --journal option.

sudo irqbalance -j

It assists for easier integration with system logging on systems that use systemd.

Conclusion

The irqbalance command in Linux optimizes performance on multiprocessor systems by distributing hardware interrupts (IRQs) across CPUs, preventing bottlenecks from uneven IRQ handling. In this tutorial, we covered its syntax, options, and practical uses, such as running in daemon or one-shot mode, banning specific IRQs or modules, setting power thresholds, and adjusting sampling intervals.

Advertisements