How to Check Memory in Linux

How to Check Memory in Linux

How to Check Memory in Linux

(How to Check Memory in Linux) System performance alongside stability depends heavily on the ability to monitor memory usage in Linux. Users can obtain memory data through different Linux tools that show RAM capacity, available memory space and swap usage, and individual process memory usage. The guidelines show how to monitor memory utilization in Linux systems through built-in utilities which include free and vmstat followed by /proc/meminfo and top and htop and dmidecode.In addition to regular commands, the system provides different explanations with alternative commands to enhance learning.

Understanding Memory in Linux

Before checking memory, it’s important to understand the different types of memory Linux manages:

  • Total Memory (RAM) – The physical memory installed in the system.
  • Used Memory – The memory actively being used by processes.
  • Free Memory – Unused memory available for new processes.
  • Available Memory – The memory available for immediate allocation without swapping.
  • Buffer/Cache Memory – Memory temporarily storing data for performance optimization.
  • Swap Memory – Virtual memory used when physical RAM is full.

Checking Memory with the free Command

The free command provides a simple overview of memory usage.

Basic Usage

Basic usage

The -h flag makes the output human-readable (in MB/GB).

Example Output:

Example output

Explanation:

  • total – Total installed RAM.
  • used – Memory actively being used by processes.
  • free – Completely unused memory.
  • shared – Memory shared between processes.
  • buff/cache – Memory used for disk caching.
  • available – Memory available for new processes.

Checking Memory Using /proc/meminfo

The /proc/meminfo file provides detailed memory statistics.

Command:

command

Example Output (Snippet):

Example Output (Snippet):

Alternative Command to Filter Specific Information:

Alternative Command to Filter Specific Information:

Checking Memory with vmstat

The vmstat command displays memory, CPU, and process details.

Basic Usage:

Basic usage

Example Output:

Example Output:

Alternative: Display Memory Usage Every 5 Seconds

Alternative: Display Memory Usage Every 5 Seconds

This updates memory stats every 5 seconds.

Checking Memory with top Command

The top command provides real-time system information, including memory usage.

Run the Command:

Run the Command:

Look for the Memory Section at the Top:

Look for the Memory Section at the Top:

Alternative: Sorting by Memory Usage

Press Shift + M inside top to sort processes by memory usage.

Checking Memory with htop (Better Alternative to top)

The htop command provides an interactive, color-coded display of memory usage.

Install htop (If Not Installed)

For Ubuntu/Debian:

For Ubuntu/Debian:

For CentOS/RHEL:

For CentOS/RHEL:

For Arch Linux:

For Arch Linux:

Run htop

Run htop

Press F6 to sort by memory usage.

Checking Swap Memory Usage

To check swap memory, use:

To check swap memory, use:

Or:

Or

To monitor swap usage dynamically:

To monitor swap usage dynamically:

Checking Memory Per Process

To check memory used by a specific process:

To check memory used by a specific process:

This lists the top 10 processes consuming memory.

Alternative Using pmap

To check memory usage of a process by PID:

To check memory usage of a process by PID:

For example, if a process has PID 1234:

For example, if a process has PID 1234:

Checking Physical RAM Details with dmidecode

To check the number of RAM sticks, capacity, and speed:

To check the number of RAM sticks, capacity, and speed:

Alternative: Checking RAM Slots Used

Alternative: Checking RAM Slots Used

Checking Memory Usage Over Time

To log memory usage every 10 seconds:

To log memory usage every 10 seconds:

For historical data logging:

For historical data logging:

(Requires sysstat package: sudo apt install sysstat -y)

Checking Memory Usage with glances (Advanced Monitoring Tool)

Install glances

Install glances

Run glances

Run glances

This provides real-time memory monitoring with CPU, network, and disk usage.

Summary of Commands to Check Memory in Linux

Summary of Commands to Check Memory in Linux

Conclusion

System resource performance optimization along with trouble identification and resource allocation require Linux users to monitor their memory usage. Users can obtain a brief overview from free but top and htop along with glances provide real-time display purposes. Two tools available to view memory hardware information are dmidecode and the /proc/meminfo file.

Users who use correct commands gain the ability to inspect and fix memory problems that result in stable Linux system operation. Monitoring memory usage both reveals resource-intensive processes while allowing users to carry out predictive maintenance of their system. System resource allocation improves and application performance increases along with crash prevention while better resource distribution stems from knowledge of memory utilization for both small personal devices and large server management tasks. Linux users who learn these tools and techniques gain the ability to preserve an effective and reliable computing system.

Leave a Reply

Your email address will not be published. Required fields are marked *