1

Background

My question is basically a follow-up to this question and answer, and in particular, this comment.

Whenever I have to copy or rsync large amounts of files, the memory on my system tends to fill up, so I run a script like this (as root):

while true ; do echo "syncing" && sync && echo 3 > /proc/sys/vm/drop_caches && echo "done" && sleep 60 ; done ;

Questions

  • Could this harm the system in any way, or cause any negative effects? (In particular, what are the "risks" mentioned in the referenced comment?)
  • If the answer is "no" (which is what I suspect), then why does not Linux run this command automatically by default? (I don't see any noticeable change due to this, I only notice that I don't run out of memory...)
Attilio
  • 355
  • 1
  • 3
  • 12
  • 2
  • No risks of data loss, but decreased system performances 2. It does dump caches as needed, when the ram is needed for other things. https://www.linuxatemyram.com/
  • – jordanm Mar 10 '20 at 15:57
  • Yeah, I read that page, still what happens on my machine is that: 1. system gets slow 2. Linux dumps caches 3. system is fast again for some time. Whereas with my script it continues to run smoothly – Attilio Mar 10 '20 at 16:06
  • 1
    I suspect there is something significant on your machine affecting memory usage. Linux does automatically free memory used for cache and buffering. It does it on a page by page basis instead of clearing it all at once. – virullius Mar 10 '20 at 17:25
  • https://discuss.aerospike.com/t/how-to-tune-the-linux-kernel-for-memory-performance/4195 – ron Mar 10 '20 at 18:25
  • https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-memory-tunables – ron Mar 10 '20 at 18:26
  • It is advised to either reduce swappiness to 0 or not use swap. For low-latency operations, using swap to any extent will drastically slow down performance. – ron Mar 10 '20 at 18:28