Memory

Published on:

Most important commands to remember

  • free -m — see how much memory the whole machine has available.
  • ps — inspect the memory associated with an individual process.

Commands and flags

These are the two commands used in the short example below.

Command Meaning
free -m Show RAM and swap in MiB; -m selects that unit.
ps -p "$$" -o pid,rss,vsz,comm -p selects a process; -o chooses its ID, resident memory, virtual memory size, and program name. RSS and VSZ are in KiB.

$$ is Bash syntax, not a command option. It contains the current shell’s PID, so we can inspect a process that is already running.

Watch the units: 1 KiB is 1,024 bytes; 1 MiB is 1,024 KiB. Divide the ps memory values by 1,024 to express them in MiB. MiB differs from MB, which means 1,000,000 bytes.

The concepts that matter

1. A process needs memory even when it is waiting

RAM is working space for running programs and the operating system. A process uses memory for code, data, and work in progress. Waiting for a request does not automatically release that memory.

That is why a quiet server can still use substantial RAM. CPU activity and memory use answer different questions.

2. Virtual memory is not the same as physical RAM

Each process sees a virtual address space. Linux manages how those addresses connect to physical memory and other backing storage. Some address ranges may be reserved without currently occupying RAM.

Think of VSZ as the size of the address map a process can see, rather than the amount of physical RAM it currently occupies. Imagine a process receives a huge virtual office:

  • VSZ is the total floor space assigned on the building plan.
  • RSS is the furniture currently present in real rooms—physical RAM.

Two ps fields help distinguish these views:

  • VSZ — Virtual Memory Size: the size of the process’s virtual address space. It is not its RAM consumption.
  • RSS — Resident Set Size: memory currently resident in RAM for that process. Shared pages can appear in several processes’ RSS, so adding all RSS values can count them more than once.

A large VSZ alone does not establish a memory problem.

3. Available memory matters more than completely free memory

Linux uses otherwise idle RAM to cache data, such as recently accessed files. Some of that cache can be reclaimed when applications need space.

In the Mem row of free, focus first on:

  • total: usable RAM visible to this Linux system.
  • free: RAM currently unused.
  • buff/cache: buffers and caches, some of which can be reclaimed.
  • available: estimated memory applications could use without swapping.

Low free alone does not mean the machine is short of memory. available gives a more useful starting point for judging headroom.

4. Swap extends where memory data can be kept

Linux can move some memory pages—chunks of memory—out of RAM into swap, commonly a disk file or partition. They must be brought back into RAM when needed. Disk-backed swap is much slower than RAM, so frequent transfers can slow applications down.

The Swap row shows configured, used, and free swap space. A total of zero means no swap is configured. Some swap being used does not by itself prove that the machine is currently struggling. Swap is not a backup of application data.

One small example

Optional: run these two commands in one Bash terminal on Linux. No administrator access is needed:

free -m
ps -p "$$" -o pid,rss,vsz,comm

First, find the machine’s available memory. Then read the shell’s RSS and VSZ; PID identifies it and COMMAND names it. Your readings will vary. These are different views: the entire machine versus one process, and MiB versus KiB.

Nothing is allocated for an experiment or left running, so no cleanup is needed.

Keep this idea: use free for the machine’s memory headroom and ps for a process’s memory footprint. Neither a large VSZ nor a small free value alone proves a shortage.