Monday, March 14, 2016

Howto check Linux memory usage

Ever found a Linux suddenly having low free memory or none at all? This is something to check when the server suddenly starts slowing down or not able to complete processes.

Here are several method to diagnose and maybe identify a fix. Check the memory usage then identify the process causing the extreme usage. Next, work on that process configuration.

Check memory usage

Display available and used memory with 'free' command
# free
# free  -m

The top live monitor
# top

Press m to display memory
Press Shift + m to sort by memory percentage
Press R to reverse the sort

List processes and amount of memory being used
# ps -e -o pid,vsz,comm=
# ps -e -o pid,vsz,comm= | sort -n -k 2

# ps aux  | awk '{print $6/1024 " MB\t\t" $11}'  | sort -n

View meminfo
# cat  /proc/meminfo
# vmstat -s

View the RAM device installed
# dmidecode -t 17

Check the process

List processes that open files
# lsof

Several TYPE of files are monitored

REG – Regular File
DIR – Directory
FIFO – First In First Out
CHR – Character special file

A description of the file is shown by FD
cwd – Current Working Directory
txt – Text file
mem – Memory mapped file
mmap – Memory mapped device
NUMBER – Represent the actual file descriptor. The character after the number i.e ‘1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write.

List processes base on process names
# lsof -c ssh

List processes base on process id
# lsof -p 1234

Where 1234 is an example of the process id (pid).


No comments:

Blog Archive