Skip to content

Configuring I/O Schedulers for Improved SD Card Performance

This guide explains how to optimize your Raspberry Pi's SD card performance by configuring the Linux kernel's I/O schedulers. Proper I/O scheduler selection can significantly improve read/write speeds and extend the lifespan of your SD card.

1. Understanding I/O Schedulers

1.1 What is an I/O Scheduler?

The I/O scheduler determines how and when block I/O operations (reads and writes) are submitted to storage devices. It can significantly impact performance, especially on slower devices like SD cards.

1.2 Available I/O Schedulers

  • mq-deadline: Default on modern Linux systems; balances throughput and latency
  • kyber: Latency-oriented scheduler for fast devices
  • bfq: Budget Fair Queueing - good for interactive workloads
  • none/noop: Minimal scheduling, often good for flash-based storage

2. Checking Current I/O Scheduler Configuration

2.1 Identify Your Storage Device

First, identify your SD card device (typically mmcblk0):

lsblk

2.2 Check the Current Scheduler

View the currently active scheduler:

cat /sys/block/mmcblk0/queue/scheduler
Output will appear similar to:
[mq-deadline] kyber none
The scheduler in brackets is the one currently in use.

3. Testing Different I/O Schedulers

3.1 Temporarily Change the Scheduler

To temporarily set a different scheduler (until reboot):

echo "none" | sudo tee /sys/block/mmcblk0/queue/scheduler
Replace "none" with your preferred scheduler.

3.2 Benchmark Performance

Measure the performance with a simple benchmark:

sudo apt install -y hdparm
sudo hdparm -t /dev/mmcblk0

For more thorough testing, use dd:

1
2
3
4
5
6
# Write test
sync && sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
dd if=/dev/zero of=test.file bs=4M count=100 conv=fsync
# Read test
sync && sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
dd if=test.file of=/dev/null bs=4M count=100

Repeat these tests with different schedulers to determine which performs best for your specific workload.

4. Permanent Configuration

4.1 Using Kernel Command Line Parameters

Edit the kernel command line:

sudo nano /boot/cmdline.txt
Add the following at the end of the existing line:
elevator=none
Replace none with your preferred scheduler.

Note: For newer kernels with multi-queue I/O scheduler framework, use:

sdhci.debug_quirks2=4

4.2 Using udev Rules

For a more flexible approach, create a udev rule:

sudo nano /etc/udev/rules.d/60-scheduler.rules
Add the following line:
ACTION=="add|change", KERNEL=="mmcblk[0-9]", ATTR{queue/scheduler}="none"
Replace "none" with your preferred scheduler.

4.3 Reboot to Apply Changes

sudo reboot

5. Optimizing Other I/O Parameters

5.1 Read-ahead Buffer Size

Increase the read-ahead buffer for better sequential read performance:

sudo blockdev --setra 2048 /dev/mmcblk0

To make it permanent, add to /etc/rc.local before the exit 0 line:

blockdev --setra 2048 /dev/mmcblk0

5.2 Queue Parameters

For write-heavy workloads, adjust the queue depth:

echo 1024 | sudo tee /sys/block/mmcblk0/queue/nr_requests

6.1 General Purpose / Desktop Use

  • Scheduler: mq-deadline
  • Read-ahead: 1024

6.2 Database / Server Workloads

  • Scheduler: bfq
  • Read-ahead: 2048

6.3 Media Center / Read-heavy Applications

  • Scheduler: none (or noop on older kernels)
  • Read-ahead: 2048

6.4 Log Servers / Write-heavy Applications

  • Scheduler: kyber
  • Read-ahead: 128

7. Monitoring Performance

Use iostat to monitor disk performance in real-time:

sudo apt install -y sysstat
iostat -d -x /dev/mmcblk0 1

Key metrics to watch: - %util: Utilization percentage - r/s and w/s: Read and write operations per second - await: Average wait time in milliseconds

✅ Summary

  • Different I/O schedulers offer varying performance characteristics for SD card operations
  • Testing is essential as the optimal configuration depends on your specific workload
  • none or noop often perform best for SD cards as they minimize unnecessary operations
  • Additional tuning parameters like read-ahead and queue depth can further enhance performance
  • For most Raspberry Pi use cases, the none scheduler provides the best balance of performance and SD card lifespan