Skip to content

Scheduler Config

Linux provides several I/O schedulers to manage disk request ordering, and selecting the right one is critical for optimizing performance on HDDs and SSDs. This section explains how to configure and tune I/O schedulers using sysfs and kernel parameters, with guidance for different storage types.


Selecting the I/O Scheduler

The I/O scheduler for a block device can be dynamically changed at runtime or set at boot via kernel parameters. To check the current scheduler:

cat /sys/block/<device>/queue/scheduler

Replace <device> with the block device name (e.g., sda, nvme0n1). The output lists available schedulers, such as deadline, cfq, noop, and none.

  • HDDs: Use deadline for sequential workloads or cfq for fairness. deadline is generally preferred for rotational media.
  • SSDs: Use noop for most cases, as SSDs have low seek times and benefit from minimal scheduling overhead. deadline can be used for specific workloads like databases.
  • NVMe SSDs: noop is typically optimal, but deadline may offer better performance in some scenarios.

To switch the scheduler for a device:

echo <scheduler> > /sys/block/<device>/queue/scheduler

Note: Changes take effect immediately but may require a reboot for persistent settings.


Tuning via sysfs

Many schedulers expose tunable parameters through sysfs. For example:

Deadline Scheduler

  • io_schedule_max: Maximum number of I/O requests to schedule (default: 256).
  • deadline: Enables deadline scheduling (default: 1).

Example:

echo 512 > /sys/block/sda/queue/iosched/io_schedule_max

NOOP Scheduler

  • nr_requests: Maximum number of I/O requests to queue (default: 128). Increase for high-throughput workloads:
    echo 256 > /sys/block/nvme0n1/queue/iosched/nr_requests
    

CFQ Scheduler

  • cfq_slice_time: Time slice for I/O requests (default: 100ms). Reduce for low-latency needs:
    echo 50 > /sys/block/sda/queue/iosched/cfq_slice_time
    

Kernel Parameters

Set the default scheduler at boot by modifying kernel command-line parameters:

  1. Edit /etc/default/grub:

    GRUB_CMDLINE_LINUX="elevator=<scheduler>"
    
    Replace <scheduler> with deadline, noop, or cfq.

  2. Update GRUB:

    sudo update-grub
    sudo update-initramfs -u
    

Note: Kernel parameters apply to all block devices. Use blkdev or sysfs for device-specific tuning.


Best Practices for HDD/SSD

  • HDDs: Prioritize deadline for sequential workloads. Avoid noop unless testing shows performance gains.
  • SSDs: Use noop as the default. For NVMe SSDs, deadline may offer better performance in some cases.
  • Monitoring: Use tools like iostat, iotop, or dstat to measure I/O performance after changes.
  • Persistent Configuration: Always test changes in a non-production environment before applying them system-wide.

Key takeaways

  • Use deadline for HDDs and noop for SSDs to match storage characteristics.
  • Tune sysfs parameters like nr_requests or io_schedule_max for workload-specific needs.
  • Kernel parameters set the default scheduler, but device-specific sysfs tuning offers finer control.
  • Always validate performance changes with monitoring tools before deploying in production.