ionice Command in Linux with Examples

Last Updated : 15 Oct, 2024

CFQ I/O disk elevator incorporates a tool called ionice which encourages the director to dole out needs on a process cycle level to accelerate or to confine the disk subsystem use of a particular cycle. For instance if you need to run a rsync order or content to reinforce your documents either locally or distantly use ionice alone with the rsync language structure to accelerate or confine the rsync cycle. 

Note: ionice is stuffed with util-Linux rpm.

Key Scheduling Classes in ionice

  • IDLE: A cycle with the allotted I/O need inactive may be conceded admittance to the disk subsystems if no different cycles with a need for best-exertion or higher solicitation admittance to information. Extremely helpful to run assignments suck as updatedb.
  • BEST-EFFORT: As a default, all cycles that don't demand a particular I/O need are appointed to this class. Cycles will acquire 8 degrees of the need of their particular CPU decent level to the I/O needs a class.
  • Constant: The most noteworthy accessible I/O need is contiguous implying that the individual cycle will consistently be given need admittance to the disk subsystem. The continuous need setting can likewise acknowledge 8 need levels.

Syntax

ionice -c scheduling_class -n priority_nice_value command

where,

  • -c scheduling_class: Defines the scheduling class (0 for None, 1 for Real-Time, 2 for Best-Effort, 3 for Idle).
  • -n priority_nice_value: Sets the priority level (0-7, with 0 being the highest priority).
  • command: The command or process you want to run.

Common Options for ionice Command

The ionice device acknowledges the accompanying alternatives:

OptionDescription
-c, --class classDetermine the name or number of the scheduling class to utilize; 0 for none, 1 for real-time, 2 for best-exertion, 3 for inactive. 
-n, --classdata levelDetermine the scheduling of class information. This possibly has an impact if the class acknowledges a contention. For constant and best-exertion, 0-7 are legitimate information (need levels), and 0 speaks to the most noteworthy need level. 
-p, --pid PID...Indicate the cycle IDs of running cycles for which to get or set the scheduling boundaries. 
-P, --pgid PGID...Indicate the cycle bunch IDs of running cycles for which to get or set the scheduling boundaries. 
-t, --ignoreOverlook the inability to set the mentioned need. On the off chance that an order was determined, run it even in the event that it was unrealistic to set the ideal scheduling need, which can occur because of deficient benefits or an old piece form. 
 -h, --helpShow help text and exit. 
-u, --uid UID...Indicate the client IDs of running cycles for which to get or set the scheduling boundaries. 
-V, --versionShow variant data and exit.

Working with ionice command

1. Running a Process with Idle I/O Priority

To set a process, say having PID as 1 to be an idle I/O process.

sudo ionice -c 3 -p 1
set a process with pid ionjice

Here, the "sudo" prefix is used as without it, the operation would not be permitted due to privileges.

2. Running a Program with Best-Effort Scheduling

To run 'bash' or any other program as a best-effort program.

ionice -c 2 bash
best efforts program

Here, the bash program would be executed with the scheduling class to be as best-exertion.

3. Running a Process with Real-Time Scheduling and Highest Priority

To run a program with scheduling class, and the priority level.

sudo ionice -c 1 -n 0 bash
scheduling class and priority level

After, the execution of the above command, the user will be logged in as the superuser. Here, the "0" specifies the highest priority.

4. Displaying the Scheduling Class and Priority of Running Processes

To print the class and priority of the processes have the PID's like 1 and 2.

ionice -p 1 2
Displaying the Scheduling Class and Priority of Running Processes

Here, the priorities of the processes with PID 1 and 2 are both idle.

5. Checking I/O Scheduling Parameters for a Specific User

To get the IDs of the running processes.

sudo ionice -u 1
Checking I/O Scheduling Parameters for a Specific User

Here, the above command will show an error as the process with PID as 1 is listed as an idle process.

6. Getting Help Information

To get the help text related to the command.

ionice -h
Getting Help Information

7. Getting Version Information

To show the ionice's version and the metadata.

ionice -V
Getting Version Information

8. Ignoring Failures When Setting Priority

To overlook the inability related to the process.

sudo ionice -t 
Ignoring Failures When Setting Priority

After the execution of the above command, the failures will be ignored.

Note: Linux supports I/O scheduling priorities and classes since 2.6.13 with the CFQ I/O scheduler.

Conclusion

The ionice command is an essential tool for managing disk I/O priorities in Linux. By using the three scheduling classes—Idle, Best-Effort, and Real-Time—you can control how processes interact with the disk subsystem. This can help improve the performance of critical tasks, reduce disk contention, and ensure that background jobs run efficiently without impacting the system’s responsiveness.

Comment

Explore