title: How can I limit the cache used by copying so there is still memory available for other caches?
body: <p><strong>Basic situation:</strong></p>
  <p>I am copying some NTFS disks in <a href="https://en.wikipedia.org/wiki/OpenSUSE" rel="nofollow noreferrer">openSUSE</a>. Each one is 2 TB. When I do this, the system runs slow.</p>
  <p><strong>My guesses:</strong></p>
  <p>I believe it is likely due to caching. Linux decides to discard useful caches (for example, <a href="https://en.wikipedia.org/wiki/KDE_Software_Compilation" rel="nofollow noreferrer">KDE 4</a> bloat, virtual machine disks, <a href="https://en.wikipedia.org/wiki/LibreOffice" rel="nofollow noreferrer">LibreOffice</a> binaries, Thunderbird binaries, etc.) and instead fill all available memory (24 GB total) with stuff from the copying disks, which will be read only once, then written and never used again. So then any time I use these applications (or KDE 4), the disk needs to be read again, and reading the bloat off the disk again makes things freeze/hiccup.</p>
  <p>Due to the cache being gone and the fact that these bloated applications need lots of cache, this makes the system horribly slow.</p>
  <p>Since it is USB, the disk and disk controller are not the bottleneck, so using <a href="https://linux.die.net/man/1/ionice" rel="nofollow noreferrer">ionice</a> does not make it faster.</p>
  <p>I believe it is the cache rather than just the motherboard going too slow, because if I stop everything copying, it still runs choppy for a while until it recaches everything.</p>
  <p>And if I restart the copying, it takes a minute before it is choppy again. But also, I can limit it to around 40 MB/s, and it runs faster again (not because it has the right things cached, but because the motherboard busses have lots of extra bandwidth for the system disks). I can fully accept a performance loss from my motherboard's I/O capability being completely consumed (which is 100% used, meaning 0% wasted power which makes me happy), but I can't accept that this caching mechanism performs so terribly in this specific use case.</p>
  <pre><code># free
               total       used       free     shared    buffers     cached
  Mem:      24731556   24531876     199680          0    8834056   12998916
  -/+ buffers/cache:    2698904   22032652
  Swap:      4194300      24764    4169536
  </code></pre>
  <p>I also tried the same thing on Ubuntu, which causes a total system hang instead. ;)</p>
  <p>And to clarify, I am not asking how to leave memory free for the &quot;system&quot;, but for &quot;cache&quot;. I know that cache memory is automatically given back to the system when needed, but my problem is that it is not reserved for caching of specific things.</p>
  <p>Is there some way to tell these copy operations to limit memory usage so some important things remain cached, and therefore any slowdowns are a result of normal disk usage and not rereading the same commonly used files? For example, is there a setting of max memory per process/user/file system allowed to be used as cache/buffers?</p>