On an Apache server of my own, logging requests to files has been enabled using a custom Apache module.

The log files can reach several GB at the end of the day. Using Nagios I have noticed memory usage higher than usual (free memory got lower by 4-5 GB) mostly because of cached memory (e.g. what is reported in buff/cache using free -m command).

enter image description here

  • 19 : log disabled
  • 20 : log enabled
  • 21 : log enabled + more VM memory

It's currently unclear why exactly it happens, but I expect Linux to temporarily keep in memory what has been written to the disk, in a case it needs to be read again later.

Does it make any sense, or is this cache mostly for what is read from the disk (not written)?

I don't think the Apache module has memory leaks because what it allocates is automatically cleaned up once the connection is closed (one possibility is to have lots of TCP/IP lingering connections) and (AFAIK) therefore it would not appear in cached memory.

2 Answers 2


I expect Linux to temporarily keep in memory what has been written to the disk, in the case it need to be read again later.

That’s correct, and that’s what you’re seeing here. It’s common for data written to disk to be read again within a short period (often by another process), and caches are used both for data read from disk and data written to disk.

As a general rule, free memory is wasted memory; using it to cache data is better.


To answer my own question: yes, it's possible.

The following commands clear the cache and then write random data to a file:

sysctl -w vm.drop_caches=3          ; drop memory cache   
free -m                             ; check memory
head -c 1G </dev/urandom >myfile    ; create a 1G random file
free -m                             ; check memory

Here are the results :

              Before : free: 474  cache: 143  avail: 450
After (100M written) : free: 371  cache: 246  avail: 428
After (  1G written) : free:  72  cache: 543  avail: 414 

The more data is written to disk, the larger cache becomes, while free memory decreases. Avail memory remains more or less the same (as expected).

You must log in to answer this question.

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