Linux – Why does Linux purge the memory cache when it is nearly full

cachelinuxmemory

Here's what the memory graph looks like on a VPS running CentOS with 512MB of RAM and nginx/php-fpm/mysqld serving (mostly static) content to a couple thousand visitors per day.

Weekly memory graph

(those are days on the x-axis)

As you can see, it's quite jumpy in the cache and buffer area. The memory cache is purged at irregular intervals (ruling out a responsible cron job). It's usually, but not always, purged at the point where it can grow no larger. Sometimes it clears almost entirely, at other times only halfway down.

I'm trying to understand the logic behind these purges. I would expect file data to be cached much longer & don't see any other programs using more memory than usual when the memory cache is cleared.

Is this normal behavior, or am I missing something?

UPDATE: A memory upgrade seems to have stabilized the graph. Still seeing small drops, but nowhere as significant as it was prior to the upgrade.

After memory upgrade

Best Answer

Could be a lot of things. Maybe one of the programs you're running is occasionally and briefly using lots of RAM. If that's really weeks on the x-axis, you should sample at a much higher resolution (e.g. once per minute or even second) to get more information about what's going on that is causing the cache to get dropped. ps and top output (including load average) during that time would be useful too.

Related Question