Group 5: Cryptic messages explained
Much memory – but still completely used up?
Each system admittedly is in need of memory for its administrative tasks.
However, when you have a look how things look like under Linux, you are getting
a mind-boggling picture: Almost all of the available physical memory is
occupied, but the programs that have been launched absolutely don't justify
this memory usage!
Invoking the program free in a terminal is going to
produce this, for example:
In this example only 65 Mbyte are readily available, with 3.8 Gbyte being
occupied (see the line marked with Mem)!
But appearances are deceptive. That which has been “reserved” consists of disk
buffers and cache: Here almost 200 Mbyte are reserved for disk buffers and 2.5
Gbyte for cache.
Deducting this figure from the memory usage (see the line below), you are
obtaining an entirely different picture: There are 2.8 Gbyte of memory
available and only 1 Gbyte is occupied. But what is going to happen behind the
scenes when a program requests a new block of memory?
Here Linux checks first whether or not the reserve suffices to satisfy the
request. In this case the system doesn't have to do anything, and the block can
be reserved.
In case the reserve doesn't suffice the system core starts releasing its
buffers and cache in order to free up enough memory to satisfy the request.
Initially only those are cleared whose contents have been read, i. e. that are
in sync with the data on disk, and once enough memory has been cleared, it is
reserved. Caches and buffers containing modified data would have to be written
back to disk before being freed, which always incurs a time penalty – however,
if there are no other options, these caches and buffers have to be cleared as
well in order to release enough memory.
Linux, however, won't go so far as to free up all buffers and cache, because it
still requires some buffers in order to facilitate any disk access. Here Linux
would eventually start to swap out data to disk in case it runs
too short of memory.
You see that Linux doesn't “eat up” the free memory, but instead uses it only temporarily, and when a program requests a chunk of memory it gets one assigned without problems – except when the entire memory (that is, both main memory and swap space) is stuffed. Any memory request is going to fail in this case, and no programs can be spawned, either. In this case you are required to terminate some programs in order to open others – and especially in conjunction with virtual machines that get their main memory assigned dynamically Linux is going to kill processes when the hypervisor exempts some of its memory.
to the top