How to see how much free memory is available in Linux

The amount of available memory is equal to the amount of free memory + the amount of cached memory. Keep in mind that RAM disks are stored in the cache and memory used by RAM disk content cannot be reclaimed by the system until that content is deleted from the RAM disk (maybe). The last documentation I read about RAM disks stated that they only grow. They never shrink. This may be different now in newer kernels.

The following command can be used to see how much RAM is available for use:

cat /proc/meminfo | \
awk '{ \
if ($0 ~ /^MemTotal:/) { TotalMemory = $2; } \
if ($0 ~ /^Cached:/) { CachedMemory = $2; } \
if ($0 ~ /^MemFree/) { FreeMemory = $2; } \
} \
END { print \
"Available memory = " (TotalMemory - CachedMemory) / 1024 \
"MB, Free memory = " (FreeMemory + CachedMemory) / 1024 "MB" \
}'

I’m not sure which value in the report is more accurate: “Available memory” or “Free memory”, but I think it’s the latter because it takes miscellaneous allocations into consideration. Here is an example of the output on my workstation, which contains 2GB of system RAM:

user@host:~$ echo $SHELL
/bin/bash

user@host:~$ cat /proc/meminfo | \
> awk '{ \
> if ($0 ~ /^MemTotal:/) { TotalMemory = $2; } \
> if ($0 ~ /^Cached:/) { CachedMemory = $2; } \
> if ($0 ~ /^MemFree/) { FreeMemory = $2; } \
> } \
> END { print \
> "Available memory = " (TotalMemory - CachedMemory) / 1024 \
> "MB, Free Memory = " (FreeMemory + CachedMemory) / 1024 "MB" \
> }'
Available memory = 1560.73MB, Free Memory = 1525.25MB

user@host:~$ cat /proc/meminfo
MemTotal:        2059248 kB
MemFree:         1105060 kB
Buffers:           84752 kB
Cached:           460936 kB
SwapCached:            0 kB
Active:           511048 kB
Inactive:         350320 kB
Active(anon):     315976 kB
Inactive(anon):     3380 kB
Active(file):     195072 kB
Inactive(file):   346940 kB
Unevictable:          16 kB
Mlocked:              16 kB
HighTotal:       1186160 kB
HighFree:         389832 kB
LowTotal:         873088 kB
LowFree:          715228 kB
SwapTotal:       1952764 kB
SwapFree:        1952764 kB
Dirty:               132 kB
Writeback:             0 kB
AnonPages:        315692 kB
Mapped:           103636 kB
Shmem:              3680 kB
Slab:              45576 kB
SReclaimable:      35152 kB
SUnreclaim:        10424 kB
KernelStack:        2304 kB
PageTables:         5476 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2982388 kB
Committed_AS:    1243316 kB
VmallocTotal:     122880 kB
VmallocUsed:       63084 kB
VmallocChunk:      40444 kB
HardwareCorrupted:     0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       4096 kB
DirectMap4k:       36856 kB
DirectMap4M:      872448 kB
Advertisements

, , , , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: