How to Check Memory Usage in Linux based Server
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 server such as Oracle or MySQL, which is famous for memory intensive. Linux, including CentOS which is popular on cPanel and Plesk web hosting server, comes with several commands and tools to check memory usage on server.
free
free command displays amount of total, free and used physical memory (RAM) in the system, as well as shoing information on shared memory, buffers, cached memory and swap space used by the Linux kernel.
Syntax of free
free -[options]
Example usage of free
free -m
The command will display information about physical memory in MB.
free -m -s 5
The command will activate continuous polling delay at 5 seconds apart, and then display memory status in megabytes on terminal. Any floating point number for delay can be specified.
free -t -m
Same with “free -m”, but -t switch will display a line containing the totals of physical memory and swap space.
vmstat
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 vmstat command, administrators can has instantaneous reports on memory usage.
Syntax of vmstat
vmstat -[options] [delay count]
Example usage of vmstat
vmstat
The command will display report based on averages since last reboot.
vmstat 5
The command will pool average system resources usage level for a sampling period of 5 seconds at interval of 5 seconds, except the first result that is averages since the last reboot.
top
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.
Syntax and example usage of top
top
Using top is simple, simply type top at command shell, and constantly update stats page will be shown.
ps aux
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
The all mentioned ways of check memory usage should works on most Unix and Linux variant of operating systems. However, if you’re running a VPS (Virtual Private Server) or VDS (Virtual Dedicated Server) or Hybrid Server, especially those powered by Virtuozzo or OpenVZ, the above commands will retrieve data from the host machine, i.e. the entire server the virtual environment is running on. In these virtualization system, the memory usage info has to be calculated from control panel or /proc/user_beancounters file.
Related Articles
- Get Triggered with High Memory Usage via Usage Monitor
- HLP Free Memory Optimizer to Reduce and Minimize RAM Memory Usage in Windows System
- How to Check if Telnet Is Running on a Server
- Optimizing Windows Memory Usage with Minimem
- Lower, Reduce and Optimize Windows RAM Memory Usage with CleanMem
- Open, Extract and Convert DAA, ISO and BIN Files in Linux with Free PowerISO for Linux
- Novell SUSE Linux Enterprise Server 10 Reviews
- Check Your Disk! Provides Statistical Information of Hard Disk Usage
- How to Find and Check Number of Connections to a Server










































September 1st, 2009 12:19
what about PR NI S?? is there any GUI for this command. I use Ubuntu Linux 9.04. thanks
February 23rd, 2009 21:50
annoying javascript!
pgup moves you to bottom of page. can’t navigate
September 24th, 2007 15:20
When you are running top there are three fields related to memory usage. In order to assay your server memory requirements you have to understand their meaning.
The first thing you have to know is that all the columns (VIRT RES SHR) report memory usage in KB (kilobytes).
VIRT column (virtual memory size of the process) means how much memory a particular application has requested, also it counts swapped to the disk memory pages. But this field does NOT mean that this process actually uses that amount of memory, to use it for real this memory has to be initiated for example using memset. Generally speaking you can disregard this column.
RES column (resident set size, the non-swapped physical memory that a task has used (in kiloBytes)) is the most important one – it actually shows how much physical RAM is allocated for a process.
SHR column says how much memory a particular application is sharing with other applications. E.g., most applications in Linux depend on libc, and as every application links with it and uses its functions then this library memory space is mapped to all process simultaneously to conserve memory.
Consult with this pages for better understanding:
1. http://tldp.org/LDP/tlk/mm/memory.html
2. http://www.ibm.com/developerworks/linux/library/l-mem26/