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.

3 Responses to “How to Check Memory Usage in Linux based Server”

  1. nanaz
    September 1st, 2009 12:19
    3

    what about PR NI S?? is there any GUI for this command. I use Ubuntu Linux 9.04. thanks

  2. anonymous
    February 23rd, 2009 21:50
    2

    annoying javascript!
    pgup moves you to bottom of page. can’t navigate

  3. Artem S. Tashkinov
    September 24th, 2007 15:20
    1

    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/

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.

New Articles

Incoming Search Terms for the Article

ubuntu memory usage - linux memory usage - centos memory usage - memory usage ubuntu - linux top memory - ubuntu server memory usage - linux top memory usage - memory usage linux - ps show memory usage - linux top sort by memory - top memory linux - unix memory status - linux memory usage by process - top memory usage - top VIRT column - linux ps memory - memory status linux - linux memory stats - linux real memory usage - centos show memory usage - linux top mem - linux show swap usage - ubuntu show memory - linux check memory usage - memory statistics linux - ps memory linux - ubuntu ram usage - linux memory statistics - display memory linux - ps show memory - ubuntu see memory usage - unix top memory usage - check physical memory linux - linux memory status - linux memory process - physical memory on linux - ubuntu get memory usage - linux top VIRT - linux show memory usage - top show memory usage - top memory usage linux - ubuntu mem usage - ubuntu view memory usage - centos ram usage - linux top by memory - linux show ram on box - Linux check memory status - Linux top memory processes - memory usage in ubuntu - memory usage centos -