Overview
Heavy storage operations—such as large-scale backups or archive compression—can easily saturate disk bandwidth on a Linux server, causing sluggish response times across critical services. By managing how processes compete for storage access, the ionice utility lets you keep production workloads responsive. Below, we explore the core mechanics of I/O scheduling and walk through practical ways to apply ionice in day-to-day operations.
Understanding ionice and Inspecting Current I/O Priorities
Both querying and modifying a process’s disk I/O scheduling class and priority level are handled by ionice.
When invoked with no flags, ionice reports the active scheduling class (none) and priority value (prio 0) assigned to your current shell session.
⚙️ [Key Options]
-c : Selects the I/O scheduling class (0 for none, 1 for realtime, 2 for best-effort, and 3 for idle).-n : Assigns a priority level within the chosen class (ranging from 0 to 7, where lower numbers indicate higher priority).-p : Targets one or more specific process IDs (PID) to inspect or update their I/O priority.-P : Targets processes by their process group ID (PGID) to view or modify I/O priority.-u : Targets all processes owned by a given user ID (UID) to inspect or adjust their I/O priority.-t : Ignores failures when setting the I/O priority so the specified command still executes without aborting.

Passing -p alongside the special shell variable $$ in ionice -p $$ lets you explicitly query the I/O scheduling attributes of the active shell process.
Seeing none: prio 0 confirms that the shell has not been placed into a custom scheduling class (none) and defaults to priority 0.

Launching Commands with Specific Scheduling Classes (-c) and Priorities (-n)
First, create a dedicated workspace for these exercises by running mkdir -p ~/ionice_lab.

Prefixing a dd write operation with ionice -c 2 -n 7 places it in the Best-effort class (-c 2) at its lowest possible priority (-n 7).
As low_prio.img is written to disk, standard system I/O requests take precedence, minimizing disruption to other running tasks.

Using ionice -c 3 switches the dd task to the Idle class (-c 3), restricting disk access strictly to moments when no other process needs the drive.
Because idle_prio.img only receives disk time during idle windows, heavy background writes will not degrade overall system throughput.

Verify both generated disk images in the lab directory with ls -lh ~/ionice_lab.
The listing shows idle_prio.img and low_prio.img at 20M each, confirming that 40M of test data was written successfully.

Dynamically Adjusting I/O Priority on Running Processes
Start a test background job, capture its PID in BG_PID, and check its initial scheduling state using ionice -p $BG_PID.
Here, sleep 30 & launches the background task while $! supplies its PID so you can inspect the live process’s I/O class.

Running ionice -c 3 -p $BG_PID reassigns the active background process (-p $BG_PID) to the Idle class (-c 3) on the fly without interrupting execution.
Chaining ionice -p $BG_PID immediately afterward confirms that the new I/O scheduling class took effect.

Once you have verified the dynamic update, terminate the background test job cleanly with kill $BG_PID 2>/dev/null || true.

Real-World Example: Throttling Large Backups with nice and ionice
Set up separate source and destination folders for a simulated backup job by running mkdir -p ~/ionice_lab/data ~/ionice_lab/backup.

Generate a 10M sample payload for compression testing with dd if=/dev/urandom of=~/ionice_lab/data/sample_data.bin bs=1M count=10 status=none.

Combining nice -n 19 ionice -c 3 drops CPU scheduling priority to its lowest tier (19) and confines disk activity to the Idle class (-c 3) before invoking tar.
This ensures that archiving ~/ionice_lab/data into data_backup.tar.gz consumes spare CPU cycles and disk bandwidth only, protecting latency-sensitive production services.

Confirm that the archive was built properly by running ls -lh ~/ionice_lab/backup/data_backup.tar.gz.
The output verifies that /root/ionice_lab/backup/data_backup.tar.gz exists with a size of 11M.

Finally, remove all temporary lab directories and test artifacts using rm -rf ~/ionice_lab.

By pairing ionice with CPU scheduling controls like nice, you can isolate heavy disk workloads before they impact critical applications. Whenever you schedule large backups, log rotations, or batch jobs on a Linux host, applying the right I/O class helps keep system responsiveness steady under load.