Is cached memory on a Linux server “free”, i.e. free to be used by other applications?
I’m aware that Linux memory is used differently than on Windows…
But I only have a few MB of free memory and 1.2GB of cached memory:
total used free shared buffers cached
Mem: 3945 3893 51 0 28 1216
-/+ buffers/cache: 2648 1296
Swap: 3895 857 3038
Is that chached memory used like “not available”?
Does it make sense to regulary drop the cache? Right after flushing I have:
total used free shared buffers cached
Mem: 3945 2820 1125 0 1 197
-/+ buffers/cache: 2621 1323
Swap: 3895 851 3044
1 hour later it’s back to the old state with 1.2 GB chached memory.
cat /proc/meminfo 1 hour after flushing:
MemTotal: 4040048 kB
MemFree: 44636 kB
Buffers: 30172 kB
Cached: 1247868 kB
SwapCached: 137156 kB
Active: 3316940 kB
Inactive: 493920 kB
SwapTotal: 3989496 kB
SwapFree: 3101076 kB
Dirty: 25696 kB
Writeback: 0 kB
AnonPages: 2527784 kB
Mapped: 219676 kB
Slab: 52356 kB
SReclaimable: 21240 kB
SUnreclaim: 31116 kB
PageTables: 96668 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 6009520 kB
Committed_AS: 6223392 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 18852 kB
VmallocChunk: 34359719439 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Just to be clear, cached column is a subset of used. Memory being utilized by a process can be in used column alone, or both the used and cached column if that piece of memory is cached. Cached is just a report on how much of the used memory is cached.
Memory items in cache are not free, but if you need space they will be dropped from cache and replaced with whatever is more frequently requested. However, your os is smart enought to keep frequently used blocks in cache–don’t try to outsmart you memory management–you will probally do worse overall.
The reason those same items keep getting loaded into cache is that they are needed frequently. Not in cache items when required, still use up that memory space.