Sobes.tech
Middle

How to find out the amount of available RAM on Linux?

sobes.tech AI

Answer from AI

There are several ways to find out the amount of available RAM on Linux.

1. Using the free command

This is probably the most common and straightforward method.

free -h  // Displays memory information in a human-readable format (GB, MB)

The output of free -h usually looks like this:

total used free shared buff/cache available
Mem: 15Gi 6.5Gi 2.0Gi 500Mi 7.0Gi 8.0Gi
Swap: 2Gi 0B 2Gi
  • total: Total amount of physical RAM.
  • used: Used memory.
  • free: Free memory.
  • shared: Memory used by multiple processes.
  • buff/cache: Memory used for buffering and caching.
  • available: An estimate of the memory available for new processes without swapping. This is the most accurate indicator of actually available memory.

2. Viewing the /proc/meminfo file

This file contains low-level information about the kernel's memory subsystem.

cat /proc/meminfo

The output of cat /proc/meminfo will be more detailed and may contain many lines. The most interesting for us:

  • MemTotal: Total memory in kilobytes.
  • MemFree: Free memory in kilobytes.
  • MemAvailable: Memory available for new processes in kilobytes.

3. Using the top or htop commands

System monitoring utilities like top (standard) or htop (more interactive) also display memory usage information.

top  // Memory information will be at the top of the output

In top or htop, memory information is often presented in a line similar to free, indicating total, used, free, and buffered/cached amounts.

For Python developers, understanding available memory is important for:

  • Assessing application performance.
  • Determining the need for memory consumption optimization.
  • Configuring application parameters (e.g., database connection pools, cache).
  • Diagnosing memory leak issues.

The most useful indicator of the actual amount of memory that can be used by new processes is the available value from the free command or /proc/meminfo.

How to find out the amount of available RAM on Linux… - sobes.tech