Transferring large file to/from USB drive causes system to hang until transfer is done

3

I have a box running Ubuntu 16.04 server. It has an internal SATA hard drive with the OS on it, and an attached USB 3 hard drive which I use for storage of large/long term files. A lot of times, this means copying a large file or folder from the internal drive to the USB drive. However, whenever I do this, the rest of the system gets incredibly slow, if not almost completely frozen, until the file transfer completes.

I've run a few tests to make sure it wasn't due to program overhead or file type. I tried both large contiguous files and large folders of many small files, and I tried using cp, pv with pipes, tar with pipes, and rsync. In all cases, the rest of the system locks up.

I also tried running each of those commands with ionice -c 3 nice -n 20 in front of them, giving the process lowest priority for processor and IO. htop shows that the process has a nice value of 19. Don't know if that's the actual minimum or if it isn't getting set right, but regardless, most other processes, including the web services, have lower nice values than 19 anyway.

The box is running several dynamic web pages, a couple with php and couple with python. Those become basically unusable for the duration of the file transfer. I assume the slowdown is caused by the overhead from USB, since, as I understand it, all USB transfers have to go through the CPU. Is this what is actually causing the slowdown? And, more importantly, is there any way for me to mitigate this?


EDIT (answering comments):

Internal and external drives are both using native ext4, so no FUSE. Nothing should be indexing the files that I know of, except for whatever Ubuntu might do by default (this is headless Ubuntu Server). CPU doesn't seem to be under load from htop's perspective, but uptime usage reports jump from around 0.5 to 6.0-8.0. Rate-limiting pv using -L does seem to help, so that's a solution for one tool. I usually only use pv when copying single files. Is there any way to rate-limit the other programs? I'd also prefer to change prioritization rather than just limit it. Optimize based on system load.

It's a pure install of Ubuntu server. It does have xorg installed, but I don't think there's even a window manager installed with it, I just wanted X11 forwarding over ssh.

Also, while the rate-limiters on pv, rsync, etc work well for saving the system, I'd also like to maximize the transfer rate. Is there any way, other than nice/ionice which don't seem to do much, to tell the system to do the transfer as fast as possible, but give anything else on the system higher priority if it wants it? So, for example, if I have a transfer to USB that will take an hour to complete, then half an hour in someone starts using one of the python sites, it would transfer as fast as possible for the first half hour, but then the system would start limiting it when the user starts making requests to the python site. (I'm starting to think this question should have been posted on Server Fault instead, and I apologize for that.)

lpreams

Posted 2016-05-27T05:47:18.007

Reputation: 31

What is CPU load during transfer? (use e.g. top or htop). Did you try pv -L to limit transfer rate in your tests? Did it reduce the problem? What transfer rate are we talking about? – Kamil Maciorowski – 2016-05-27T06:05:18.203

Check too that you are not indexing files with something like akonadi... – Hastur – 2016-05-27T06:09:22.603

Also: what is the target filesystem? and the source one? Is any of them mounted with FUSE? – Kamil Maciorowski – 2016-05-27T06:20:57.997

Internal and external drives are both using native ext4, so no FUSE. Nothing should be indexing the files that I know of, except for whatever Ubuntu might do by default (this is headless Ubuntu Server). CPU doesn't seem to be under load from htop's perspective, but uptime usage reports jump from around 0.5 to 6.0-8.0.

Rate-limiting pv using -L does seem to help, so that's a solution for one tool. I usually only use pv when copying single files. Is there any way to rate-limit the other programs? Id also prefer to change prioritization rather than just limit it. Optimize based on system load – lpreams – 2016-05-27T06:41:47.437

Try to use iotop or atop to see the file access... BTW use rsync with -P option among the others, instead of pv, it should involve less system call if you copy many files... When you copy without pv do you have the same problem? – Hastur – 2016-05-27T08:40:22.620

PS> sometimes if you install a desktop environment you install a file indexing server system too, that can scan the files to create indexes and databases... akonadi/Nepomuk/balooo for kde, etc etc... – Hastur – 2016-05-27T08:46:25.883

See http://askubuntu.com/questions/397249/system-freezes-unresponsive-unusable-when-copying-large-file-to-usb for a possible duplicate of the issue and for a workaround.

– DrMoishe Pippik – 2016-09-01T02:07:24.300

@DrMoishePippik the article it links to says the issue was being patched in kernel 3.13, back in 2013. I'm running kernel 4.4. Either it never got patched, or I'm experiencing a different issue. – lpreams – 2016-09-05T08:16:24.153

AFAIK, it has not been patched, despite being identified long ago. There are a number of threads involving this issue, including comments by LT himself, that the whole concept of file transfer in Linux needs to be revisited now that more RAM is commonly available. – DrMoishe Pippik – 2016-09-05T23:10:47.610

No answers