Na wat geheugenproblemen op een server ben ik het eens goed gaan uitzoeken: wat betekenen de getallen in het free command in Linux/Unix eigenlijk? En ik vond het antwoord in een forum:

bf@tbwb-dt-bf:~> free -m
             total       used       free     shared    buffers     cached
Mem:          3978       3848        130          0         28       1985
-/+ buffers/cache:       1834       2144
Swap:         2055          0       2055

Wat betekenen al die getallen nu eigenlijk? Wel, de eerste rij is je fysieke RAM. Wat er dus feitelijk aan geheugenchippies in je computer zit. En daarvan wordt gemeld wat er nu eigenlijk precies in gebruik is. Dus, zowel door applicaties, buffers, kernel, caches, etc. (In dit geval in megabytes, vanwege de -m optie bij free.)

Maar, zoals we allemaal wel weten, cachet de Linux kernel dat het een lieve lust is. Alles wat ie leest en ontvangt zet ie meteen in het geheugen. Er is immers meer dan zat meestal. Dat zijn die ‘buffers’ en ‘cached’ getallen. Die zijn dus wel degelijk in gebruik in geheugen, maar als een applicatie RAM nodig heeft, zal de kernel die buffers vrijgeven. En het gevolg daarvan, staat in het regeltje eronder. Onderstaand schema toont dat:

bf@tbwb-dt-bf:~> free -m
             total       used       free     shared    buffers     cached
Mem:             T          U          F          S          B          C
-/+ buffers/cache:      U-B-C      F+B+C
Swap:           TS         US         FS

De getallen in de tweede rij zijn dus de gebruikte en vrije RAM voor applicaties. ‘used’ minus ‘buffers’ minus ‘cached” is in gebruik door applicaties; ‘free’ plus ‘buffers’ plus ‘cached’ is beschikbaar voor nieuwe. En als dat op is, dan komt de OOM-killer in actie. Maar daar zullen we het nu maar niet over hebben.After some memory problems on a server, I started to look into it: what do all those number in the output of free actually mean? And, I found the answer in a forum:

bf@tbwb-dt-bf:~> free -m
             total       used       free     shared    buffers     cached
Mem:          3978       3848        130          0         28       1985
-/+ buffers/cache:       1834       2144
Swap:         2055          0       2055

What do these numbers mean? Well, the first row is your physical RAM. That is, what is actually in chips on the motherboard of your computer. And, of that, the command shows what is actually exactly in use. In applications, buffers, caches, kernel, etc. (In this case in megabytes, because of the -m option with free.)

But, as we all know, Linux loves to cache everything. All that is read and received gets a place in the buffer memory. Most the time, there is more than enough memory available to do that. Those are the ‘buffers’ and ‘cached’ numbers. They really are in use in the system’s memory, but when an application needs RAM, the kernel will release those buffers. And the result of that, is in the line below. Following schematic shows how it works:

bf@tbwb-dt-bf:~> free -m
             total       used       free     shared    buffers     cached
Mem:             T          U          F          S          B          C
-/+ buffers/cache:      U-B-C      F+B+C
Swap:           TS         US         FS

The numbers in the second row are the used and free RAM for applications. ‘used’ minus ‘buffers’ minus ‘cached’ is in use by applications; ‘free’ plus ‘buffers’ plus ‘cached’ is available for new ones. And if the kernel runs out of that, the OOM-killer steps in. But I won’t discuss that further here.

Categorieën: Opinie

0 reacties

Geef een reactie

Avatar plaatshouder

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.