9

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.

Braiam
  • 66,947
  • 30
  • 177
  • 264
Degru
  • 342
  • 2
  • 13
  • Shouldn't, but check if http://unix.stackexchange.com/questions/107703/why-is-my-pc-freezing-while-im-copying-a-file-to-a-pendrive helps – Rmano Nov 29 '15 at 21:58

1 Answers1

10

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"
terdon
  • 98,183
  • 15
  • 197
  • 293
Charles Green
  • 20,952
  • 21
  • 60
  • 92
  • Wow, this worked. Thanks! My system is now way more responsive while transferring, and is actually faster at loading things overall. – Degru Nov 30 '15 at 00:25
  • Glad to hear it helped. – Charles Green Nov 30 '15 at 00:26
  • 1
    > By default Ubuntu uses Deadline, but I find my system responds more quickly when I use deadline. I suspect you did want this phrase to end in '...when I use cfq'. – markus_b Nov 30 '15 at 14:48
  • I never looked for a solution to this for a reason or another. I upvoted this answer when it was posted some days ago, now I've had the chance to test it (I had to migrate a *lot* of torrents from Deluge back to Transmission, which required rechecking every single torrent) and changing the scheduler was indeed an improvement. The system still stutters, expecially when switching workspaces, but for sure it doesn't almost completely hang like it used to do. Thanks! This answer is so useful that IMO deserves a bounty (and I'm setting one). – kos Dec 03 '15 at 18:37
  • @kos It's not a complete solution, or I would certainly be much happier myself - I still stutter occasionally also, and find this to be very frustrating. – Charles Green Dec 03 '15 at 18:43
  • Yes, I noticed, but well, it works for me. I'm currently booting from an external USB 3.0 hard drive and I'm currently migrating the torrents, and I'd have been barely able to write this comment without changing the scheduler (I know because this is the third or fourth time I'm doing this). I know it's not perfect; maybe it also depends on the system, but for me personally the difference is noticeable. – kos Dec 03 '15 at 18:58
  • @kos I was researching this a bit more yesterday, and ran into an article about another scheduler (not generally available on Ubuntu) called BFQ - it makes [interesting reading](http://www.hecticgeek.com/2012/11/bfq-loads-programs-extremely-fast-under-heavy-disk-io-workloads-ubuntu/), and it would be nice to give this a shot. – Charles Green Dec 04 '15 at 19:57
  • I'll test that tomorrow and I'll let you know my impressions if you want. It seems really promising, I think it's worth the effort of reimporting everything again. – kos Dec 07 '15 at 03:27
  • Couldn't test it yet, gonna do that in the next days. I awarded the bounty since anyway that was my original intention, I'll let you know how I think that BFQ algorithm performs, so that if you want you could include that in the answer. If it outperforms CFQ like in that benchmark this answer could be just great :) – kos Dec 10 '15 at 18:01
  • @kos I've compiled BFQ into kernel 4.2.0.19-23, and it seems to be running OK. I'll be setting up some tests to try to benchmark this a little later. – Charles Green Dec 11 '15 at 21:52