Solving Linux system lock up when intensive disk I/O are performed
When a system lock up occurs, we often blame applications but when you look carefully you may see that despite your multi-core CPU, your applications are sleeping! No cpu activity! So what happens then? Check the I/Os, it could be the root cause!
With Ubuntu 10.04, my desktop computer was freezing when the ReadyNAS Bacula backup was running. Indeed, the Bacula daemon was performing intensive disk operations (on a fast SATA hard disk). The situation was such that it was impossible to use the system, the interface was freezing for a several seconds then working for a few seconds and freezing again.
Linux I/O Scheduler
The I/O scheduler is responsible for organizing the order in which disk operations are performed. Some algorithms allow to minimize the disk head moves, other algorithms tend to anticipate read operations,
When I/O operations are not scheduled correctly, an interactive application such as a desktop or a browser
can be blocked until its I/O operations are scheduled and executed (the situation can be even worse for
those applications that use the
O_SYNC writing mode).
By default, the Linux kernel is configured to use the Completely Fair Queuing scheduler. This I/O scheduler does not provide any time guarantee but it gives in general good performances. Linux provides other I/O schedulers such as the Noop scheduler, the Anticipatory scheduler and the Deadline scheduler.
The deadline scheduler puts an execution time limit to requests to make sure the I/O operation is executed before an expiration time. Typically, a read operation will wait at most 500 ms. This is the I/O scheduler we need to avoid the system lock up.
Checking the I/O Scheduler
To check which I/O scheduler you are using, you can use the following command:
$ cat /sys/block/sda/queue/scheduler noop anticipatory deadline [cfq]
sda is the device name of your hard disk (or try
The result indicates the list of supported I/O scheduler as well as the current scheduler used (here the Completely Fair Queuing ).
Changing the I/O Scheduler
To change the scheduler, you can
echo the desired scheduler name to activate it (you must be root):
# echo deadline > /sys/block/sda/queue/scheduler
To make sure the I/O scheduler is configured after each system startup, you can
add the following lines to your
/etc/rc.local startup script:
test -f /sys/block/sda/queue/scheduler && echo deadline > /sys/block/sda/queue/scheduler test -f /sys/block/sdb/queue/scheduler && echo deadline > /sys/block/sdb/queue/scheduler test -f /sys/block/hda/queue/scheduler && echo deadline > /sys/block/hda/queue/scheduler
You may have to change the
hdb if you have an IDE hard disk.
After changing the I/O scheduler to use the Deadline scheduler, the desktop was not freezing any more when backups are running.