Operations 5 min read

Master Linux Memory: Understand VIRT, RES, SWAP and Diagnose Low Memory

This guide explains Linux memory fundamentals, clarifies the meanings of VIRT, RES, and SWAP, shows how to quickly check memory status with top and free, distinguishes buffers from cache, and provides practical tips using sar and vmstat to identify real memory shortages.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Master Linux Memory: Understand VIRT, RES, SWAP and Diagnose Low Memory

Memory Basics

First run the top command to view memory-related fields.

The fields VIRT , RES , and SWAP represent virtual memory, resident (physical) memory, and swapped memory respectively.

Physical memory ( RES ) is the actual RAM in use. When RAM is insufficient, the OS moves rarely used pages to the swap area on disk; swapped pages are brought back when needed. Swap acts as a temporary storage, like a small warehouse for infrequently used data.

Virtual memory ( VIRT ) equals physical memory plus swap space. Programs operate on virtual addresses, which the OS maps to physical memory or swap.

Quickly Check Memory Status

Run free to see key metrics:

total – total physical memory size

used – amount of physical memory currently used

free – amount of idle physical memory

shared – memory shared among processes

buffers/cached – memory used for buffers and cache

swap – usage status of swap space

Common Memory Questions

1. Is low free space a sign of insufficient memory? In Linux, free physical memory is often low because the system uses idle memory for caching to improve performance. When memory runs low, Linux releases cache to satisfy program needs.

2. What is the difference between buffer and cache? Buffers store metadata of disk files (e.g., attributes, directory structures), while cache stores the actual file contents.

3. How to determine if memory is truly insufficient? Two main signs: continuous page swapping and a high number of major page faults. Major faults occur when a page is not in memory and must be fetched from disk. Use sar -B 1 3 to view metrics such as pgpgin/pgpgout (page in/out), fault (minor faults), and majflt (major faults). The vmstat 1 5 command also shows memory information, where the memory column displays memory stats and si/so indicate swap in/out.

Additional tip: after running top, the SWAP column may be hidden. Press f to enter column edit mode, then press p to select the SWAP column, and hit Enter to return to the top view with SWAP displayed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxMemorytopFreesarvmstat
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.