Flush Memory On A Server?

Home » CentOS » Flush Memory On A Server?
CentOS 9 Comments

Hi,

A few days ago I checked the health of my main public server running CentOS 7, a quad-core machine with 16 GB RAM. It had been running non-stop for 65 days, hosting only a handful of services (BIND, NTP, Apache, Postfix, Dovecot) for two domains.

I was surprised to see that RAM consumption was relatively high, and apparently, the machine even had to swap at some time.

I read up a bit on RAM consumption, and now I wonder if flushing the memory cache regularly is a good idea.

How To Flush Memory Cache on Linux Server

Any suggestions?

Niki

Microlinux – Solutions informatiques durables
7, place de l’église – 30730 Montpezat Web : http://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32

9 thoughts on - Flush Memory On A Server?

  • Why were you surprised? Linux systems use the available RAM, surely you understand that?

    Of course there is the possibility that you have discovered a bug and there is a memory leak on your system, building up over time. I suggest you show the list full memory usage details if you feel this is the case.

    Did you read the kernel documentation on the subject linked in comments section of that article?

  • Le 09/09/2017 à 14:41, Phil Perry a écrit :

    I’m surprised because my system used the available RAM and then it even began to swap.

    Minimal CentOS 7 installation with BIND, Apache, MySQL, Postfix and Dovecot, regularly updated.

    Hence my post. Wondering if other CentOS users experienced something similar.

    Niki Kovacs


    Microlinux – Solutions informatiques durables
    7, place de l’église – 30730 Montpezat Web : http://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32

  • Every system that runs continuously for more that a few days will have some pages that were used once when some long-running process started and were never referenced again. Those pages will eventually migrate out to swap, and that’s the best place for them. Right now, I see that this system has been up for 16 days and has ~270MB of swap used. I typically see ~500MB of swap used when the system has been running a while longer.


    Bob Nichols “NOSPAM” is really part of my email address.
    Do NOT delete it.

  • Le 09/09/2017 à 15:14, Robert Nichols a écrit :

    So, in other words, there’s no need to worry if a little swap is used when the system’s been running non-stop for a couple months?

    Niki


    Microlinux – Solutions informatiques durables
    7, place de l’église – 30730 Montpezat Web : http://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32

  • Nicolas Kovacs wrote:

    It´s nothing unusual and a good thing when it means that stuff not needed in memory is swapped out.

    What is the advantage of emptying the cache supposed to be? I´ve had servers with the uptime-counter flowing over after years of uptime and never flushed the cache.

  • Typically, no.  Whatever pages of memory the system has swapped out are pages that the kernel’s counters indicate are less often used than the pages that are in RAM.

    The presence of pages in swap isn’t necessarily bad.  If, on the other hand, you were seeing pages actively swapped in and out of swap, that might indicate that the system needs more RAM than it has.

    You can tune how conservative the system is about swapping memory in exchange for file cache by setting the “vm.swappiness” system parameter.

  • As long as your system isn’t thrashing swap it’s totally fine. From what you’ve written it doesn’t sound like you’re thrashing.

    –keith

  • I should have mentioned earlier:  Run “vmstat 1” and watch the “si” and
    “so” columns to watch paging activity.