Type Your Question


How to check the memory usage in CentOS?

 Friday, 4 October 2024
CENTOS

CentOS, a robust and stable Linux distribution, provides various tools and commands for monitoring system resources, including memory usage. Understanding how to check memory usage is essential for optimizing system performance, identifying potential bottlenecks, and ensuring smooth operation. This guide will walk you through different methods to monitor memory usage in CentOS.

1. Using the free Command

The free command is a basic yet powerful tool for obtaining a snapshot of memory usage. It displays information about both physical and swap memory.

Syntax

free -h

Example Output

total used free shared buff/cache available
Mem: 15G 8.9G 5.6G 152M 548M 6.1G
Swap: 1.9G 0B 1.9G

Explanation

*total*: Represents the total amount of RAM installed.
*used*: Shows the amount of RAM currently being used by running processes.
*free*: Indicates the amount of RAM that is currently unused and available for new processes.
*shared*: Shows the amount of RAM that is shared between processes (e.g., shared libraries).
*buff/cache*: Displays the memory used for file system buffers and caches.
*available*: Indicates the amount of memory that is immediately available for new applications, considering buffers and caches.

Benefits of Using free

*Simple and easy to use.*
*Provides a quick overview of memory status.*
*Displays information about both physical and swap memory.*

2. Using the top Command

The top command provides a dynamic and real-time view of processes running on the system, including their memory usage. Its an excellent tool for identifying memory-intensive processes.

Syntax

top

Example Output

top - 11:20:23 up 16 days, 18:47, 3 users, load average: 0.00, 0.01, 0.05
Tasks: 159 total, 1 running, 158 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 15671632 total, 8641332 used, 7030296 free, 1106240 buffers
KiB Swap: 1952252 total, 0 used, 1952252 free. 1064880 cached Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1012 root 20 0 1708840 219832 142736 S 0.0 1.4 0:00.43 sshd
2259 root 20 0 74964 14824 10456 S 0.0 0.1 0:00.04 bash
1227 root 20 0 74560 13140 9100 S 0.0 0.1 0:00.03 top

Explanation

*Top Section*: Displays the system uptime, load average, number of users, and CPU usage.
*Tasks*: Shows the number of active, sleeping, stopped, and zombie processes.
*Memory*: Displays the total memory, used memory, free memory, and the amount of memory used for buffers and cache.
*Process List*: Shows the processes sorted by CPU usage by default, but you can change the sorting criteria (e.g., memory usage) by pressing M on the keyboard.
*Process Information*: Provides the process ID (PID), user who owns the process, priority, virtual memory size (VIRT), resident set size (RES), shared memory size (SHR), state (S), CPU usage, memory usage (%MEM), and CPU time consumed (TIME+).

Benefits of Using top

*Provides a real-time view of process activities and memory usage.*
*Allows you to dynamically change sorting criteria.*
*Provides insights into memory-intensive processes.*

3. Using the free -m Command

To view the memory usage in megabytes, use the -m option with the free command.

Syntax

free -m

Example Output

total used free shared buff/cache available
Mem: 15338 8908 5735 154 552 6234
Swap: 1948 0 1948

4. Using the vmstat Command

The vmstat command provides a comprehensive overview of system statistics, including memory usage. Its particularly useful for monitoring memory usage over time.

Syntax

vmstat 1 5

Example Output

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 6771 491 5842 0 0 10 0 361 170 0 1 98 0 0
0 0 0 6768 491 5842 0 0 10 0 363 169 0 0 99 0 0
0 0 0 6770 491 5842 0 0 10 0 362 170 0 0 99 0 0
0 0 0 6772 491 5842 0 0 10 0 361 171 0 1 98 0 0
0 0 0 6771 491 5842 0 0 10 0 361 170 0 0 99 0 0

Explanation

*procs*: Displays the number of running and blocked processes.
*memory*: Shows information about free memory, used buffers, and cache memory.
*swap*: Indicates the amount of swap space used and free.
*io*: Provides information about disk input/output operations.
*system*: Shows the number of interrupts and context switches.
*cpu*: Displays the CPU utilization statistics for user, system, idle, and wait times.

Benefits of Using vmstat

*Provides comprehensive system statistics.*
*Offers a dynamic view of memory usage over time.*
*Useful for monitoring system performance and identifying memory-related issues.*

5. Using the /proc/meminfo File

The /proc/meminfo file contains a wealth of detailed information about memory usage and configuration. Its suitable for more advanced users who want to explore specific memory-related metrics.

Accessing the File

You can access the /proc/meminfo file using the cat command:

cat /proc/meminfo

Example Output

MemTotal: 15674112 kB
MemFree: 6855392 kB
MemAvailable: 6228504 kB
Buffers: 475044 kB
Cached: 1073568 kB
SwapCached: 0 kB
Active: 7256944 kB
Inactive: 1463396 kB
Active(anon): 6366312 kB
Inactive(anon): 77228 kB
Active(file): 890632 kB
Inactive(file): 1386168 kB
Unevictable: 3104 kB
Mlocked: 0 kB
SwapTotal: 1952252 kB
SwapFree: 1952252 kB
Dirty: 340 kB
Writeback: 0 kB
AnonPages: 6674524 kB
Mapped: 133848 kB
Shmem: 12976 kB
Slab: 437640 kB
SReclaimable: 388544 kB
SUnreclaim: 49096 kB
KernelStack: 2304 kB
PageTables: 24576 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 7837056 kB
Committed_AS: 8001528 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 109824 kB
VmallocChunk: 34359628544 kB
HardwareCorrupted: 0 kB
AnonHugePages: 32768 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB

Explanation

The /proc/meminfo file contains various memory-related statistics, including:

*MemTotal*: Total physical memory in kB.
*MemFree*: Free memory in kB.
*MemAvailable*: Memory available for new applications in kB.
*Buffers*: Memory used by buffers for disk I/O.
*Cached*: Memory used by the file system cache.
*SwapTotal*: Total swap space in kB.
*SwapFree*: Free swap space in kB.
*Active*: Memory actively used by processes.
*Inactive*: Memory not actively used, but likely to be reused soon.
*AnonPages*: Anonymous memory used for processes that dont correspond to files.
*Mapped*: Memory mapped to files.
*Slab*: Memory used by the kernel for caching data structures.

Benefits of Using /proc/meminfo

*Provides a comprehensive overview of memory statistics.*
*Offers a high level of granularity and detail.*
*Useful for advanced analysis and debugging memory-related issues.*

Conclusion

Monitoring memory usage is crucial for maintaining the health and stability of your CentOS system. The tools and methods outlined in this guide offer different perspectives and levels of detail, allowing you to choose the most appropriate option for your specific needs. Whether youre seeking a quick snapshot, real-time insights into process memory usage, or in-depth analysis of memory statistics, these techniques empower you to gain valuable insights into your systems memory consumption.

Memory Performance 
 View : 480


Related


Translate : English Rusia China Jepang Korean Italia Spanyol Saudi Arabia

Technisty.com is the best website to find answers to all your questions about technology. Get new knowledge and inspiration from every topic you search.