Fundamentals 6 min read

Understanding Linux Memory: free Command, Buffers, Cache, and Swap Explained

This guide explains how the Linux free command reports memory usage, clarifies the roles of total, used, free, buffers, and cache, describes the meaning of the -/+ buffers/cache line, and provides practical steps to clear swap and drop caches.

Open Source Linux
Open Source Linux
Open Source Linux
Understanding Linux Memory: free Command, Buffers, Cache, and Swap Explained

1. Viewing Linux Memory with free command

total: total memory size.

used: memory already used (includes cached, buffers, shared).

free: idle memory size.

shared: inter‑process shared memory (usually ignored).

buffers: data written to memory awaiting flush to disk.

cached: memory used to cache read data for faster future access.

-/+ buffers/cache is shown as two parts:

-buffers/cache: memory actually in use (used – buffers – cached).

+buffers/cache: memory available for use (free + buffers + cached).

Swap: size of used swap partition on disk.

The purpose of swap is to provide virtual memory when +buffers/cache is exhausted, moving some memory contents to disk.

2. Buffer and Cache Introduction

Cache is designed to speed up CPU‑memory data exchange, while Buffer improves memory‑disk I/O.

Cache mainly targets read operations; CPU has its own caches (L1, L2, L3) for frequently used instructions and data. The larger system cache resides in RAM, storing recently accessed data.

Buffer targets write operations, aggregating writes to reduce disk fragmentation and improve performance.

A daemon periodically flushes Buffer contents to disk; the sync command can trigger this manually.

3. Common Symptoms

Symptom 1: Frequent file access quickly consumes physical memory while cached continuously grows.

Explanation: Linux caches every requested data in memory to allow fast CPU‑memory communication.

Symptom 2: Swap is occupied.

Explanation: Swap usage indicates insufficient RAM; monitoring swap can reveal memory pressure.

4. Manually Clearing Swap and buffers/cache

(1) Clear Swap swapoff -a && swapon -a Explanation: If swap is in use and +buffers/cache still has space, swapoff -a moves swap contents back to memory without data loss.

(2) Clear buffers/cache

sync; sync; sync && echo 3 >/proc/sys/vm/drop_caches

sleep 2

echo 0 > /proc/sys/vm/drop_caches

Explanation: sync writes cached data to disk; echo 3 >/proc/sys/vm/drop_caches clears pagecache, dentries, and inodes; after a short pause, echo 0 >/proc/sys/vm/drop_caches restores the default setting.

5. Summary

When free physical memory is low, it does not necessarily indicate poor system health because cache and buffer memory can be reclaimed and effectively count as extra free memory.

Frequent swap usage, or non‑zero bi/bo values, signals genuine memory pressure; focusing on the -/+ buffers/cache values from free provides a clearer picture of memory adequacy.

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.

CacheSwapmemory-managementBufferssystem-administration
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.