- Slow performance when copying files to and from USB devices
- 3 Answers 3
- Cause
- Why is usb file transfer so slow in 12.10?
- 5 Answers 5
- 2E0PGS / linux-usb-file-copy-fix.md
- This comment has been minimized.
- jorgeribeiro commented Oct 24, 2018
- This comment has been minimized.
- Oldbuntu commented Jan 24, 2019
- This comment has been minimized.
- Rockburner commented Feb 20, 2019 •
- How can I fix the lag when running Ubuntu installed on a USB drive?
- 4 Answers 4
- How do I get better USB transfer speeds in (X)ubuntu?
Slow performance when copying files to and from USB devices
When I copy files to and from USB devices (camera, HDD, memory card) my system becomes very slow. For example if I want to close a window I move the mouse but it takes about 2 seconds or more before the mouse cursor moves. When I finally get the cursor over the x and click it nothing happens for 10+ seconds. I’ve tried this with all desktop effects disabled but the issue persists.
Software: Linux Mint 9 KDE Hardware:
- Asus SLI motherboard
- NVidia 6600 GPU
- 2 GB Ram
- 2 GB Swap
- AMD Athlox X2 @ 3800+
To me this hardware should not have any issues running this software and it doesn’t until I copy files using USB. Where should I start looking to figure this one out? I’m kind of thinking the graphics driver may be part of the problem but I don’t know for sure.
3 Answers 3
There seems to be a problem with huge pages in linuxes memory management. It rarely occurs, but sounds like you have observed it.
Cause
This is my grossly simplified account of what, according to the article, happens.
If unlucky, a process gets stuck the moment it issues a memory access. That’s because when transparent huge pages is enabled, a memory access may trigger synchronous compaction (defragmentation of main memory,) synchronous meaning the memory access does not finish before the compaction does. This in itself is not a bad thing. But if write-back (of, e.g., buffered data to USB) happens to take place at the same time, compaction in turn is likely to stall, waiting for the write-back to finish.
So, any process could end up waiting for a slow device to finish writing buffered data.
Upgrading main memory, as the OP did, might help delay the problem. But for those who don’t consider that an option, there are two obvious workarounds. Both involve recompiling the kernel:
- disabling the transparent huge pages feature
- applying Mel’s patch as mentioned in the article
This sounds similar to my question here (where an answer pointed me to this question):
But the theory is completely different, and the solution I used is unrelated to yours, but works perfectly.
I was using rsync, so all I had to do was use the —drop-cache option. (which makes the copy a bit slower as a side effect)
If you want to try some power-user tricks, you can reduce the size of the buffer that Linux uses by setting /proc/sys/vm/dirty_bytes to something like 15728640 (15 MB). This means the application can’t get more than 15MB ahead of its actual progress.
A side effect is that your computer might have lower data-writing throughput with this setting, but on the whole, I find it helpful to see that a program is running a long time while it writes lots of data vs. the confusion of having a program appear to be done with its job but the system lagging badly as the kernel does the actual work. Setting dirty_bytes to a reasonably small value can also help prevent your system from becoming unresponsive when you’re low on free memory and run a program that suddenly writes lots of data.
But, don’t set it too small! I use 15MB as a rough estimate that the kernel can flush the buffer to a normal hard drive in 1/4 of a second or less. It keeps my system from feeling «laggy».
Источник
Why is usb file transfer so slow in 12.10?
I was getting the usual 4-8mbps in 12.04 when copying files via usb sticks. However after upgrading to 12.10, I only get 200-300kbps when I try to perform the same operation.
I have tried different usb sticks (which work flawlessly on Windows 7) and still experience the same issue. I experienced the same issue sometime ago on 11.10 but everything was normal when I upgraded to 12.04 so it might be a kernel issue.
Here’s the output of dmseg |tail :
I have updated my system with the latest updates. What could be wrong?
5 Answers 5
I fear that your problem has no solution. USB slow transfer rates are a phantom in Ubuntu history, that comes and goes away from time to time. It happens because developers in the majority of cases are not able to reproduce this problem and then no solution will be released.
You can see a phenomenon of discussions about USB transfer rates being slow in Ubuntu (and its «cousins»). For example you can see this thread, this discussion and this other thread.
Some say that enabling or disabling Legacy USB Support into the BIOS solves the problem, although it seems as specific rare cases.
There is a bug reported at LaunchPad that presents a workaround for the issue, but as it is somewhat outdated I can’t evaluate it’s effectiveness nowadays. The workaround is presented by Jean Pierre at Bug #66115 he talks about the workaround in this comment and after in this more detailed comment.
A hot discussion is about the sync mode being enabled when Nautilus mounts a device, although beyond Konqueror (KDE equivalent to Nautilus) I haven’t found anyone who got sync option disabled for Nautilus.
Some workarounds of doubtfully effectiveness are discussed in this Super User’s Question.
If you got no luck until here I shall tell you that there exists no solution for the problem currently.
There is currently a bug reported in LaunchPad and you can mark it as a problem that affects you. If your hardware differs from the one that is reported from the bug you may add a comment reporting your affected hardware.
Источник
2E0PGS / linux-usb-file-copy-fix.md
If your running a x64 bit Ubuntu or other Linux and find USB transfers hang at the end apply this fix:
I suggest you edit your /etc/rc.local file to make this change persistant across reboots.
sudo nano /etc/rc.local
Go to the bottom of the file and leave a space then paste in those two lines.
Save the file with ctrl + x then press y.
To revert the changes enter this in console and remove the lines in /etc/rc.local
This comment has been minimized.
Copy link Quote reply
jorgeribeiro commented Oct 24, 2018
It worked just fine, thank you so much!
After searching a lot in different sources, this was the only answer to actually work.
I use Linux Mint 18.
This comment has been minimized.
Copy link Quote reply
Oldbuntu commented Jan 24, 2019
Thank’s this really work for Ubuntu 18.04.Thank one’s again
This comment has been minimized.
Copy link Quote reply
Rockburner commented Feb 20, 2019 •
I tried entering these lines into the file, but now a 1Gb file that previously took less than a minute to copy, after which ‘files’ would hang for over an hour, is taking up to an hour to copy at something like 255kB/sec.
For reference the machine is an I5 with 16GbRAM running ubuntu 18.04. The USB stick is a new 256Gb SanDisk.
Are there some better byte values I can try to get a better balance between the latency and the hanging?
I can’t use the lines directly in the terminal either — I just get ‘Permission Denied’, even using sudo.
Источник
How can I fix the lag when running Ubuntu installed on a USB drive?
I recently did a fresh install of Ubuntu 12.04. I did it on a 16GB USB flash drive, with 964MB for swap and 13.97GB for ext3.
System specs:
- 2GB DDR2 RAM (800
frequency range)
This is the first time I have gotten Ubuntu installed on a USB flash drive (I had another Ubuntu installed on hard drive). The Ubuntu I had on the hard drive worked marvellously faster than my Windows 7; for example, I could be running Google Chrome with around twenty tabs and have Photoshop running without any lag. But now with the USB version I can barely have Google Chrome open with six tabs and browse my home folder at the same time without lag, and freezing of either Chrome or the home folder.
This is a picture of top being used in the terminal:
So could you please help me? Any suggestions will be helpful.
4 Answers 4
Where USB flash drives fail is in random writes to the disk. They can be hundreds of times slower than the same operation on traditional hard drives. Note that this used to be the case with SSDs too until around 2008 or 2009 when they gained new controller technologies which make them much faster than tradtional hard drives. These technologies pretty much don’t exist on USB flash drives.
Operations that will be particularly slow include:
- Installing new packages, or doing system updates. Expect these to be tens of times slower than traditional hard drives, maybe even 1000s of times slower than SSDs. Upgrading between Ubuntu versions could take several hours or more.
- General browser use, given that your browser caches files to disk all the time.
- Operations which involve copying or moving/altering hundreds of small files.
This article on phoronix compares the performance of various file systems on USB flash drives. Unfortunately, its conclusion is that it doesn’t make all that much difference. Theoretically, a log-structured file system should help, but these aren’t mainstream enough for me to recommend them for the uninitiated.
One idea is to use a read-only or hybrid file-system instead, which is exactly what you get if you copy the Ubuntu Live CD image (or use UNetBootin to set up a live USB) to your USB flash drive. Look into setting up a Live USB from the Live CD image with persistence (try to find a recent guide to doing so). Of course, you then won’t be able to upgrade to a new version of Ubuntu, but that’s not necessarily terrible.
Barring any such measures, and keeping a traditional partition type/structure, your main strategy will be to try and minimise writes to the disk at all cost. Ideas for this include:
- Disable journalling on ext4 or set your partitions to «writeback» mode. The drawback to this is that it increases the chances and severity of data loss or corruption in the case of accidental power loss, crash or simply unplugging the drive while it’s being used.
- Disable swap, though on a system with sufficient RAM this actually will have much less of an effect than you expect, and on a system with insufficient RAM may cause stability problems.
- Try to minimise on-disk caching by various programs, such as your browser. Reducing the size of the disk cache is not necessarily enough: turning it off all together and using a memory cache (if possible) is much better. If you have lots of RAM, you could try using a tmpfs mount (like a disk partition in RAM) for various tmp and cache directories.
Источник
How do I get better USB transfer speeds in (X)ubuntu?
When I connect my USB 2.0 drive to Xubuntu and try to transfer large files, transfer speeds are good at first but drop after a few seconds to 1-2 Mib/s. From what I read, the fast transfer at the beginning is just until the cache is full, then the real USB transfer speed is used.
In Windows, speed is constant at about 25Mib/s, same stick, connected to same port.
This is the output from dmesg when connecting the stick:
The stick is automounted, here is the output of «mount»:
I have to use vfat because I want to transfer files to my Playstation3 system. Althouth the test below shows, that this is not the main cause.
It seems this is a common issue in (X)ubuntu. I haven’t found a clear solution yet. It seems that the stick needs to be mounted as async instead of flush but I’m not exactly sure how to achieve this. I don’t mind if I have to unmount the stick each time before disconnecting it as long as the transfer speeds are better.
Nov 2: This bug report seems to be related: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/182931. What worries me is that the problem seems to be over 2 years old and still isn’t solved.
Nov 10: I started a read-test with palimpstest (from gnome-disk-utility project). This gives me a minimal transfer rate of 23 MBit/s. Also tried it in krusader now, the read speed is constantly > 20 MBit/s. So the problem really is just writing to the stick!
Here is an image of a read-write test in the same program:
I had to delete the filesystem completely before the test which shows that vfat is not the main cause as mentioned above.
Another hint: If I transfer a 100 MB file, once it’s at 100% it takes an unusual long time to actually finish the transfer. This again looks to me that the file is indeed in a cache but writing to the usb device is very slow.
Nov 12: «Good news». The problems seems to be memory stick itself. Trying an external harddrive (My Book Elite 1TB) gives me constant write speed of about 20 MiB/s. I first tried to reformat my memory stick so I can really compare the two (file sytems were different). After reformatting, both drives are mounted exactly the same way:
Cruzer is the stick (speed still dropping after a few seconds), My Book is the external harddrive with a constant write speed of 20 MiB/s.
Hard to say what the problem really is then. As I said, in Windows I get equally fast write speeds with the SanCruzer too.
Edit at end of bounty: Unfotunately, the problem with the stick is still not solved. However, after 7 days I want to award the bounty of course. The comment from aking1012 was really helpful as it shed a new light on the matter. However, I feel that I have to give the bounty to harrymc as he showed the most effort of getting the problem solved. Thanks all.
Источник