12

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.

8
  • 2
    check that the USB ports are USB 2.0 capable. some USB ports, particularly on the front of desktops used to be USB 1.0 only. Also check that your BIOS settings are optimal for USB performance. There may be some USB speed settings, and/or USB legacy settings that may affect your performance. Commented Oct 20, 2011 at 20:06
  • Is the device formatted as NTFS? If it is, I'd try reformatting it as FAT32 (or EXT4 if you're only planning to use it on Linux).
    – RobinJ
    Commented Nov 6, 2011 at 9:14
  • 3
    There seems to be a problem with huge pages in linux' memory management. It rarely occurs, but sounds like you have observed it.
    – wnrph
    Commented Nov 18, 2011 at 15:59
  • @artistoex - That article completely sums up the behavior I was experiencing. Too bad there is no concrete fix. Anyone know if this is fixed in later versions? Time for an upgrade anyway.
    – John
    Commented Nov 25, 2011 at 16:39
  • as the article says, recompile your kernel with the transparent huge pages feature disabled.
    – wnrph
    Commented Nov 26, 2011 at 11:22

3 Answers 3

7

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.

Cure

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
3
  • 1
    There's no need to recompile kernel, you can just run echo never > /sys/kernel/mm/transparent_hugepage/enabled as root. Commented Jul 8, 2021 at 10:07
  • @MikkoRantalainen Thank you for that hint. I will update my answer
    – wnrph
    Commented Jul 15, 2021 at 7:26
  • See also: stackoverflow.com/a/65560328/334451 Commented Jul 15, 2021 at 7:45
2

This sounds similar to my question here (where an answer pointed me to this question):

https://stackoverflow.com/questions/10105203/how-can-i-limit-the-cache-used-by-copying-so-there-is-still-memory-available-for

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)

0

The only trick I found that really works: Gnome, nautilus copy files to USB stops at 100% or near

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".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .