0

On my system, I have a log file that is being rotated and uploaded every hour. This file is heavy on writes and only needs to be read when rotated and uploaded.

The cached memory on my system is raising until it allocates the entire RAM and then the OS clears some of it. I want to improve that process and I suspect that the cache is rising b/c of this log file I keep writing to all the time.

I need to find a way to clear the cache of that file after I upload it so I can tell the OS this is no longer needed and let it free up memory.

As far as I know, echo 3 > /proc/sys/vm/drop_caches clears all cached memory. Is that correct?

Is there any way to clear up cached memory for just one file?

1 Answer 1

1

In general, it's best to just leave your operating system to manage memory itself. Memory used as cache will be returned to processes when they request it.

You really only need to start taking action when your system is regularly using significant amounts of memory for processes or you have gone beyond that and are swapping. You should have monitoring in place to alert you to these issues.

The use of /proc/sys/vm/drop_caches is discouraged, unless you know what you're doing. The relevant kernel docs have this to say

Use of this file can cause performance problems. Since it discards cached objects, it may cost a significant amount of I/O and CPU to recreate the dropped objects, especially if they were under heavy use. Because of this, use outside of a testing or debugging environment is not recommended.

2
  • @lain so you're basically saying I shouldn't touch it even though I see the cached memory keeps growing until it fills the entire RAM? (I don't see any swap and my processes use constant amount of memory).
    – Rafa
    Dec 5, 2015 at 12:01
  • Yup - linuxatemyram.com, there is absolutely nothing wrong with cache using up lots of memory.
    – user9517
    Dec 5, 2015 at 12:02

You must log in to answer this question.

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