How to Check Linux Memory Usage

Linux is not like Windows, you will not always see a graphical system interface, especially in a server environment. As a Linux administrator, it is important to know how to check available and used resources such as memory, CPU, disk space, etc. If there are any applications that are using too many resources on the system to run the system at an optimal level, it needs to be found and fixed. Let's take a look at how to view memory usage in Linux.

1. View the memory usage using the free command

The Free command is the most powerful command widely used by Linux administrators. But compared to the "/proc/meminfo" file, it provides very little information. The Free command displays the total amount of free and used physical and swap memory on the system, as well as buffers and caches used by the kernel.              

[root@sharplee creatfile]# free -m

The following is the meaning of the parameter fields in the figure:

  • total: total memory
  • used: memory used by the running process (used= total - free - buff/cache)
  • free: unused memory (free= total - used - buff/cache)
  • shared: memory shared by multiple processes
  • buffers: memory reserved for the kernel to operate on a process queue request
  • cache: The size of the page cache that holds recently used files in RAM
  • buff/cache: Buffers + Cache
  • available: An estimate of how much memory is available to start new applications without swapping.

2. View memory usage using /proc/meminfo file

The "/proc/meminfo" file is a quasi-file that contains various real-time information about memory usage. It displays memory statistics in kilobytes, most of which are a bit hard to understand. However, it contains useful information about memory usage.

[root@sharplee creatfile]# cat /proc/meminfo

3. View the memory usage using the vmstat command

The vmstat command is another useful tool for reporting virtual memory statistics. vmstat reports information about processes, memory, paging, block IO, disk, and CPU capabilities. vmstat requires no special privileges and can help identify system bottlenecks.

[root@sharplee creatfile]# vmstat

The following is an explanation of the above commands:

Procedures

  • r: number of runnable processes (running or waiting to run)
  • b: number of processes in uninterruptible sleep state

Memory

  • swpd: amount of virtual memory used
  • free: amount of free memory
  • buff: the amount of memory used as a buffer
  • cache: the amount of memory used as cache
  • inact: amount of inactive memory
  • active: amount of active memory

Swap

  • si: amount of memory swapped from disk (/s)
  • so: amount of memory swapped to disk (/s)

IO

  • bi: blocks received from the block device (blocks/s)
  • bo: blocks sent to the block device (blocks/s)

System

  • in: number of interrupts per second, including clock
  • cs: number of context switches per second

CPU : These are percentages of total CPU time

  • us: time spent running non-kernel code (user time)
  • sy: time spent running kernel code (system time)
  • id: idle time. Prior to Linux 2.5.41 this included IO wait time
  • wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle
  • st: The time stolen from the virtual machine. Before Linux 2.6.11, unknown

Run the following command to view the details.

[root@sharplee creatfile]# vmstat -s

4. View the memory usage using the smem command

smem is a tool that provides reports on the memory usage of a large number of Linux systems. Unlike existing tools, smem can report proportional set size (PSS), unique set size (USS) and resident set size (RSS). Proportional Set Size (PSS): Refers to the amount of memory used by libraries and applications in the virtual memory system. Unique Set Size (USS): Unshared memory is reported as USS (Unique Set Size). Resident Set Size (RSS): A standard measure of physical memory (often shared among multiple applications) usage, known as Resident Set Size (RSS), will greatly overestimate memory usage. Note: If the prompt is not found after executing the following command, please execute "yum install smem installation"

[root@sharplee creatfile]#  smem -tk 

 

5. View the memory usage using the top command

The top command is one of the most commonly used commands for Linux administrators to understand and view the resource usage of processes on a Linux system. It displays the system's total memory, current memory usage, available memory, and total memory used by buffers. Additionally, it displays the system's total swap memory, current swap usage, available swap memory, and total cache memory.

[root@sharplee creatfile]# top -b | head 10

6. View memory usage using htop command

The htop command is an interactive process viewer for Linux/Unix systems. It is a text-mode application and requires the ncurses library, which was developed by Hisham. It is designed as an alternative to top-level commands. This is similar to the top command, but allows you to scroll vertically and horizontally to see all processes running on the system. htop comes with Visual Colors which are an added bonus and very visible when tracking system performance. Freedom to perform any task related to a process, such as process termination and reset, without entering its PID.

[root@sharplee creatfile]# htop

 

7. View memory usage using the glances command

glances is a cross-platform system monitoring tool written in Python. All information such as CPU usage, memory usage, running processes, network interfaces, disk I/O, Raid, sensors, file system information, Docker, system information, uptime, etc. can be viewed.

[root@sharplee creatfile]# glances

 

8. View memory usage using the ps_mem command

ps_mem is a simple Python script that allows you to accurately get the core memory usage of programs in Linux. This determines how much RAM is used per program (not per process). It calculates the total amount of memory used by each program, total = sum (private RAM for program processes) + sum (shared RAM for program processes). There are issues with calculating shared RAM, and the tool automatically chooses the most accurate method for the running core. Note: If you execute the following command prompt not found, please execute "yum install ps_mem" to install

[root@sharplee creatfile]# ps_mem

9. View the memory usage using the sar command

The sar command is used to collect and report system activity details. ( Note: If you use the following command to prompt that the command cannot be found, you can use "yum install sysstat" to install )

[root@sharplee creatfile]# sar -r 

Summary: There are various tools and commands available on the Linux system to monitor memory usage and system resource utilization. So many command tools can be used according to the actual situation. Generally, free, top, vmstat, htop, etc. are often used .

 

Guess you like

Origin blog.csdn.net/xsq123/article/details/126947016