Ubuntu – System locks up when disk I/O is saturated

hard driveioperformance

When I do a large file transfer from my external USB3 hard drive to my internal hard drive (or vice versa), be it via Nautilus or via terminal, Ubuntu (Unity) will almost completely lock up. Things like alt-tab take 20 seconds or more to complete while the file transfer is running. This is not the case when there are lots of random reads/writes to the disk, such as when installing packages.

When I was running Windows, I could run a file transfer in the background and still be able to do things, albeit more slowly when something needed to access the disk. I could still alt-tab just fine.

It seems that Ubuntu prioritizes the file transfer above all other disk I/O, which is why it locks up. In Windows it appears that file transfers have a lower priority, which means the system can stay responsive while the disk is saturated.

How can I fix this? It's rather annoying, as the computer becomes completely unusable when copying files. This issue happens in both 14.04 and 15.10. I'm forced to plug my hard drive into a USB2 port to prevent this issue, and that results in much longer transfer times.

Best Answer

I have had the same issue on my laptop, which has a fairly slow disk system as compared to the remainder of the computer.

I was able to make this much better, by changing the scheduling algorithm used for disk transfers. By default Ubuntu uses Deadline, but I find my system responds more quickly when I use cfq.

To see what scheduler you are using, issue the command

cat /sys/class/block/sda/queue/scheduler    

To do a one-time change (until reboot) issue the command

echo cfq | sudo tee /sys/class/block/sda/queue/scheduler

Note that it is important that the change be made to whatever it is that you have for your external hard drive; Mine usually loads up as sdb. so I would issue the command echo cfq | sudo tee /sys/class/block/sdb/queue/scheduler

I make my change permanent for all drives attached to my computer, by adding the kernel parameter elevator=cfq in my grub file, which looks like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash noautogroup elevator=cfq"
Related Question