How to check if a disk scheduler is configured in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore how to determine the configured disk scheduler in a Linux environment. Understanding the active I/O scheduler is crucial for performance tuning and optimizing storage operations.

We will achieve this by examining the /sys filesystem to directly query the scheduler configuration for block devices, verifying the scheduler information within the kernel ring buffer using the dmesg command, and inspecting udev rules which can influence device configuration, including the scheduler.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/TextProcessingGroup(["Text Processing"]) linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/TextProcessingGroup -.-> linux/grep("Pattern Searching") subgraph Lab Skills linux/ls -.-> lab-558708{{"How to check if a disk scheduler is configured in Linux"}} linux/cat -.-> lab-558708{{"How to check if a disk scheduler is configured in Linux"}} linux/grep -.-> lab-558708{{"How to check if a disk scheduler is configured in Linux"}} end

Check scheduler with cat /sys/block/*/queue/scheduler

In this step, we will explore how to check the I/O scheduler being used by your block devices in Linux. The I/O scheduler is a kernel component that decides the order in which block I/O operations are submitted to storage devices. Different schedulers are optimized for different workloads.

We can find this information by looking at files within the /sys filesystem. The /sys filesystem is a virtual filesystem that provides an interface to kernel data structures.

To check the scheduler for all block devices, we can use the cat command along with a wildcard. The * wildcard matches any characters, so /sys/block/*/queue/scheduler will match the scheduler file for every block device listed under /sys/block/.

Open your terminal if it's not already open. You can do this by clicking the Xfce Terminal icon on the left side of your desktop.

Now, type the following command and press Enter:

cat /sys/block/*/queue/scheduler

You will see output similar to this:

noop [deadline] cfq
noop [deadline] cfq

The output shows the available schedulers and the one currently in use is enclosed in square brackets []. In this example, the deadline scheduler is currently active for the block devices.

Understanding which scheduler is active can be important for performance tuning, especially in server environments or systems with specific storage requirements.

Verify scheduler in dmesg

In the previous step, we checked the currently active I/O scheduler using the /sys filesystem. Another place to find information about the kernel and device initialization is the kernel ring buffer, which can be viewed using the dmesg command.

The dmesg command prints the kernel's message buffer. This buffer contains messages produced by the kernel during boot and runtime, including information about detected hardware and device drivers.

We can use dmesg to see messages related to the block devices and their configured schedulers during the system boot process. Since the output of dmesg can be quite long, we will use the grep command to filter the output and find lines containing the word "scheduler".

Type the following command in your terminal and press Enter:

dmesg | grep scheduler

The | symbol is called a pipe. It takes the output of the command on the left (dmesg) and sends it as input to the command on the right (grep). grep scheduler then searches for lines containing the word "scheduler" in the input it receives.

You should see output similar to this:

[    X.XXXXXX] io scheduler noop registered
[    X.XXXXXX] io scheduler deadline registered
[    X.XXXXXX] io scheduler cfq registered
[    X.XXXXXX] sdX: [sd-mod] Asking for cache data failed
[    X.XXXXXX] sdX: [sd-mod] Assuming drive cache: write through
[    X.XXXXXX] sdX: [sd-mod] Enabled discard support
[    X.XXXXXX] sdX: [sd-mod] **Using deadline scheduler**

Look for lines that mention "Using [scheduler name] scheduler". This confirms which scheduler was selected for your block devices during boot. The output might vary slightly depending on the specific system configuration, but you should see mentions of registered schedulers and the one being used.

This method provides historical information from the boot process, while checking the /sys filesystem gives you the current state. Both are useful ways to understand your system's I/O configuration.

Inspect udev rules in /etc/udev/rules.d

In the previous steps, we learned how to check the active I/O scheduler using /sys and dmesg. Now, let's look at how the system might be configured to set the scheduler automatically when devices are detected. This is often handled by udev.

udev is a device manager for the Linux kernel. It manages device nodes in /dev and handles all user space events when hardware devices are added or removed from the system. udev uses rules to match devices and perform actions, such as setting permissions or configuring device parameters like the I/O scheduler.

udev rules are typically stored in the /etc/udev/rules.d/ directory. These files have a .rules extension. We can inspect these files to see if there are any rules that specifically set the I/O scheduler for certain devices.

First, let's list the files in the /etc/udev/rules.d/ directory using the ls command:

ls /etc/udev/rules.d/

You will see a list of files, potentially including some related to block devices or storage. The output might look something like this:

10-snapd.rules  50-cloudimg-settings.rules  70-snap.core.rules  70-snap.lxd.rules  70-snap.microk8s.rules  70-snap.snapd.rules  70-snap.snapd-desktop-integration.rules  99-vmware-scsi-udev.rules

Now, let's look inside one of these files to see if we can find any rules related to schedulers. We'll use the cat command to display the content of a file. For example, let's look at 99-vmware-scsi-udev.rules (the exact filename might vary slightly depending on the environment, but look for one that seems related to storage or devices):

cat /etc/udev/rules.d/99-vmware-scsi-udev.rules

You might see rules that match specific device attributes and then set properties. Look for lines that use the ATTR keyword to match device attributes and the ATTR{queue/scheduler} property to set the scheduler.

For example, a rule to set the deadline scheduler might look something like this:

## Set scheduler for VMware SCSI devices
ACTION=="add|change", SUBSYSTEM=="block", ATTRS{idVendor}=="VMware", ATTRS{idModel}=="VMware Virtual S", ATTR{queue/scheduler}="deadline"

This rule matches block devices (SUBSYSTEM=="block") with specific vendor and model attributes and sets their scheduler to deadline when they are added or changed.

By inspecting these rules, you can understand how the default I/O scheduler might be configured on your system.

Summary

In this lab, we learned how to check the configured disk scheduler in Linux using two primary methods. First, we utilized the /sys filesystem by examining the contents of /sys/block/*/queue/scheduler with the cat command. This allowed us to see the available schedulers and identify the one currently in use, indicated by square brackets.

Secondly, we explored the kernel ring buffer using the dmesg command to verify scheduler information during device initialization. This provides an alternative way to confirm the active scheduler and gain insights into kernel messages related to storage devices. Finally, we briefly touched upon inspecting udev rules in /etc/udev/rules.d as a potential location for scheduler configuration, although the detailed steps for this were not fully provided in the provided content.