How to Check Memory Usage in Linux

How to Check Memory Usage in Linux

When troubleshooting system problems, application slowdowns, or unexplained problems, the first thing to do is to check the system's memory usage.

This article explains how to check RAM memory usage in Linux using different commands.

1. free command

The free command is the most commonly used command to check memory usage in a Linux system. It displays information about the total memory, memory used, and free memory.

Normally, free is run with the -h option, which means printing the output in a human-readable format:

free -h
       total used free shared buff/cache available
Mem: 3936 1087 252 130 2596 2427
Swap: 0 0 0

Here is what each column means:

  • total - the total amount of memory available to the application
  • used - Memory that has been used. It is calculated like this: used = total - free - buffers - cache
  • free - free/unused memory.
  • shared - This column can be ignored. It is only provided for backward compatibility.
  • buff/cache - kernel cache, page cache and slabs
  • avaiable - Estimated available memory available to start new applications, excluding swap memory.

The free command prints information about physical memory and swap memory.

2. top command

top is a command tool that displays real-time information about running processes. It also displays a system summary, including memory usage.

To run the command, simply type top :

top

The output will look something like this:

The output header includes the following information: system memory, free memory, used memory, and swap memory.

The %MEM column provides information including the proportion of shared memory used by each running process to the available physical memory.

3. /proc/meminfo

The easiest way to check RAM memory is to display the /proc/meminfo virtual file. This file is used by free , top , ps and other system information commands.

Use less or cat to view the contents of the /proc/meminfo file.

cat /proc/meminfo

The file contains a number of information about system memory and swap memory usage:

MemTotal: 4030592 kB
MemFree: 401804 kB
MemAvailable: 2507504 kB
...

This information from the /proc/meminfo file can be parsed and used in shell scripts.

4. ps_mem script

ps_mem is a Python script that reports the RAM usage of each process. It works in both Python 2 and 3, and can be installed using pip .

sudo pip3 install ps_mem

Running ps_mem requires administrator privileges:

sudo ps_mem

The output will include the memory usage of each running program in ascending order:

 Private + Shared = RAM used Program
...
 11.9 MiB + 20.2 MiB = 32.1 MiB nginx (4)
 8.2 MiB + 42.4 MiB = 50.6 MiB systemd-journald
 55.8 MiB + 307.2 MiB = 363.0 MiB php-fpm7.4 (6)
233.9 MiB + 234.0 MiB = 467.9 MiB redis-server
578.2 MiB + 578.6 MiB = 1.1 GiB mysqld
---------------------------------
             2.2 GiB
=================================

V. Conclusion

We have shown you some commands that you can use to check your system memory usage.

Original: https://linuxize.com/post/check-memory-linux/

The above is the details of how to check memory usage under Linux. For more information about checking memory usage in Linux, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Linux virtual memory settings tutorial and practice
  • Linux system diagnostics: memory basics in depth
  • Why does the Linux system eat up my "memory"?
  • Solve the Linux system v shared memory problem
  • Linux system to view CPU, machine model, memory and other information
  • Linux kernel device driver memory management notes
  • Methods for optimizing Oracle database with large memory pages in Linux
  • A brief discussion on Linux virtual memory

<<:  Let's talk about the two functions of try catch in Javascript

>>:  Pessimistic locking and optimistic locking in MySQL

Recommend

MySQL implementation of lastInfdexOf function example

Sometimes MySQL needs to use a function similar t...

Solution to the routing highlighting problem of Vue components

Preface Before, I used cache to highlight the rou...

JavaScript custom calendar effect

This article shares the specific code of JavaScri...

Sample code for implementing DIV suspension with pure CSS (fixed position)

The DIV floating effect (fixed position) is imple...

Why is it slow when using limit and offset paging scenarios?

Let’s start with a question Five years ago when I...

Background image cache under IE6

CSS background image flickering bug in IE6 (backg...

How to change the default character set of MySQL to utf8 on MAC

1. Check the character set of the default install...

Implementation of webpack code fragmentation

Table of contents background CommonsChunkPlugin s...

Docker deployment RabbitMQ container implementation process analysis

1. Pull the image First, execute the following co...

Sample code for deploying ELK using Docker-compose

environment Host IP 192.168.0.9 Docker version 19...

VPS builds offline download server (post-network disk era)

motivation Due to learning needs, I purchased a v...

MAC+PyCharm+Flask+Vue.js build system

Table of contents Configure node.js+nvm+npm npm s...

How to install MySQL 5.7.29 with one click using shell script

This article refers to the work of 51CTO blog aut...