The Temple of Fu

code, systems and games

Archive for January 2011

Linux – Checking Memory Usage / Getting Memory Information

leave a comment »

Memory is one of the most critical resource components on a server to ensure that the smooth and fast operation. Thus, the availability of adequate and abundant physical memory size is vital especially for any server, especially high load web host that are also running database servers such as Oracle or MySQL, which are famous for being memory intensive. Linux, including CentOS, come with several commands and tools to check memory usage on server.


The free command displays the amount of total, free and used physical memory (RAM) in the system, as well as, shows information on shared memory, buffers, cached memory and swap space used by the Linux kernel.

free -[options]

Example usage of free; This command will display information about physical memory in MB.

free -m

The following command will activate a continuous polling delay of 5 seconds apart and then display memory status in megabytes on the terminal. Any floating point number for delay can be specified.

free -m -s 5

Same with “free -m”, but -t switch will display a line containing the totals of physical memory and swap space.

free -t -m


The command vmstat reports report virtual memory statistics, which has information about processes, swap, free, buffer and cache memory, paging space, disk IO activity, traps, interrupts, context switches and CPU activity. With the vmstat command, administrators can have instantaneous reports on memory usage.

vmstat -[options] [delay count]

Example usage of vmstat


The following command will display report based on averages since last reboot. The command will pool average system resources usage level for a sampling period of 5 seconds at interval of 5 seconds, except for the first result that is averages since the last reboot.

vmstat 5


The top command displays dynamic real-time view of the running tasks managed by kernel and system information in Linux system. The memory usage stats by top command include real-time live total, used and free physical memory and swap memory with their buffers and cached memory size respectively.


Using top is simple, simply type top at command shell, and constantly update stats page will be shown.

ps aux

The ps command reports a snapshot on information of the current active processes. Advantage of ps command is that system admins will be able to see where the memory is used. ps will show the percentage of memory resource that is used by each process or task running in the system. With this command, top memory hogging processes can be identified.

Syntax and example of ps aux

aux is actually already the options for ps command to see every process on the system. So the typical command to type the following in the command shell:

ps aux

To see only the memory resources occupied by each category of processes, such as Apache httpd, MySQL mysqld or Java, use the following command:

ps aux | awk ‘{print $4″\t”$11}’ | sort | uniq -c | awk ‘{print $2″ “$1” “$3}’ | sort -nr


You can also use the DMIDECODE command line utility to check the ram speed and type:


Written by lordfu

January 27, 2011 at 9:39 am