3

My understanding of the output of free is that buffer/cache values are a true reflection of available memory.

I have assigned 512M to PHP APC opcode cache and although it is utilising all of this the output of free remains the same.

I know that the issue lies in my understanding (or lack thereof) of memory management. Can someone please give me some insight into this?

UPDATE:

My understanding of memory comes from the studying of assembly that I've done. What (at least I think) I don't know about is how the Linux kernel manages the memory.

Since posting the question I've read more and my understanding is that, at the simplest level, they are as their names suggest - cache is the kernel mirroring files to RAM for faster access and that buffers are transient bits of information being used by individual processes.

APC running (512M fully utilised):

              total       used       free     shared    buffers     cached
Mem:           1498       1452         46          0         36        796
-/+ buffers/cache:         619        879

Immediately after restarting PHP FPM with APC disabled:

              total       used       free     shared    buffers     cached
Mem:           1498        776        721          0         36        285
-/+ buffers/cache:         454       1043

Ignoring swap space as it remained unchanged:

Line one makes sense to me, memory is freed from both APC (512M) and the PHP workers (721-46-512 = 163M). Memory assigned for cache no longer has APC to deal with and reduces by 796-285 = ~512M (or is this just a coincidence?).

It's the second line that is confusing me. Are these numbers just how much the kernel has reserved for buffers and the rest is allocated to caching even if not actually used currently? This would make sense because it drops by the same amount I calculated as being used by PHP, reflecting the PHP workers.

If I am correct then another question arises. What is reflected by "buffers" on line one?

  • It's not really clear from your question what your understanding of the memory stats is, nor why your experience doesn't match your expectations - perhaps if you provided the output of free on a cold system and once APC is populated we would understand beter. – symcbean Sep 10 '12 at 12:55

1 Answers1

0
              total       used       free     shared    buffers     cached
Mem:           1498        776        721          0         36        285
-/+ buffers/cache:         454       1043

The second line, 454 = used(776) - (buffers(36)+cached(285))

1043 = free(721) + (buffres(36)+cached(285))

The values will be approximated.

What is buffer?

https://stackoverflow.com/questions/6345020/linux-memory-buffer-vs-cache

Minto Joseph
  • 146
  • 3