There are many commands that can be used to identify total RAM memory size installed and check the amount of free and used memory in the Linux operating system such as Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and etc.
Memory is one of the critical resources for a computer especially server as enough memory ensures that applications can be allocated the memory it required to perform the operation before swapping to disk, which is much slower, hindering the response time.
As GUI is not always available especially for Linux users who frequently SSH or Telnet to remote system, this tutorial focuses on command-line options to find out the memory usage and status in Linux, which includes RAM and swap.
1. free Command
free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo. The information displayed are:
- total: Total installed memory (MemTotal and SwapTotal in /proc/meminfo)
- used: Used memory (calculated as total – free – buffers – cache)
- free: Unused memory (MemFree and SwapFree in /proc/meminfo)
- shared: Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, available on kernels 2.6.32, displayed as zero if not available)
- buffers: Memory used by kernel buffers (Buffers in /proc/meminfo)
- cache: Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo)
- buff/cache: Sum of buffers and cache
- available: Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)
total used free shared buff/cache available Mem: 24512912 253112 23761468 41484 498332 23873560 Swap: 12387324 0 12387324
2. vmstat Command
vmstat reports information about processes, memory, paging, block IO, traps, disks and cpu activity. The following information are displayed by default:
r: The number of runnable processes (running or waiting for run time).
b: The number of processes in uninterruptible sleep.
swpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 23760168 62096 438828 0 0 0 0 4 4 0 0 100 0 0
3. top Command
top command is mainly used to display dynamic real-time view of a running system especially the Linux processes or threads currently being managed by the Linux kernel. But it also displays system summary information, including RAM memory and swap free and used size.
To exit from top program, press Ctrl + c, or just q.
top - 09:55:34 up 20:23, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 188 total, 2 running, 186 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 24512912 total, 23758072 free, 252420 used, 502420 buff/cache KiB Swap: 12387324 total, 12387324 free, 0 used. 23873892 avail Mem
As you can see from commands above, most of the utilities rely on /proc/meminfo to report the amount of free and used memory and swap space in the system. /proc/meminfo is a virtual file that contains dynamic statistics about the memory usage by the kernel and the system.
To view the content of /proc/meminfo, use any of the following commands and any other you prefer:
cat /proc/meminfo more /proc/meminfo less /proc/meminfo
5. atop Command
atop is an interactive monitor to view the load on a Linux system which is similar to top. It shows the occupation of the most critical hardware resources (from a performance point of view) on system level, i.e. cpu, memory, disk and network. atop is not installed by default on most Linux distribution, so if you want to use it, you need to install atop manually.
6. htop Command
htop is an interactive process viewer for Unix systems, which is similar to top but provides more detailed information. It is a text-mode application (for console or X terminals) and requires ncurses. htop is not installed by default on most Linux distribution, so if you want to use it, you need to install htop manually.
Physical RAM Information
If you’re interested in knowing about the physical RAM DIMM modules installed on the system, use dmidecode (DMI Table Decoder), a tool for dumping a computer’s DMI (or SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision.
To use dmidecode to view physical RAM modules, use one of the following commands:
$sudo dmidecode --type memory $ sudo dmidecode -t 17
# dmidecode 3.0 Scanning /dev/mem for entry point. SMBIOS 2.6 present. Handle 0x001C, DMI type 17, 28 bytes Memory Device Array Handle: 0x001A Error Information Handle: Not Provided Total Width: 72 bits Data Width: 64 bits Size: 4096 MB Form Factor: DIMM Set: None Locator: CPU0 Bank Locator: DIMM01 Type: Other Type Detail: Other Speed: 1066 MHz Manufacturer: Samsung Serial Number: 88XX8X88 Asset Tag: AssetTagNum01 Part Number: M888MXXXXMM8-MM8 Rank: Unknown