Why Page Cache Isn’t Freed After a Container Restart – A Deep Dive into Linux Memory Stats
This article explains how Linux reports memory usage, clarifies the meaning of free, buffers, cache, and available fields, details /proc/meminfo entries, distinguishes page‑cache, buffer‑pages, shared memory, and shows how process‑level tools like smaps and top present memory statistics.
Starting with the free command
The free utility prints a snapshot of memory usage. total shows the system's RAM, used excludes buffers and cache, free is the truly unused memory, shared reports tmpfs usage, and buffers/cache is the sum of memory used for block‑device buffers and page cache. The newer available column (kernel 3.14+) approximates the amount of memory that can be allocated without swapping, roughly equal to free + buffers/cache but not an exact figure.
/proc/meminfo details
Most memory‑related commands read from /proc/meminfo. Key fields include: MemTotal – total physical RAM minus reserved kernel memory. MemFree – memory not used at all. MemAvailable – kernel’s estimate of reclaimable memory (includes parts of Cache/Buffer and Slab that can be freed).
Linux distinguishes two kinds of user pages: File‑backed Pages (pages that map a file) and Anonymous Pages (heap, stack, etc.). All pages in the page cache are file‑backed; they can be written back to disk (page‑out) when memory is low, while anonymous pages are swapped out to the swap device.
Disk cache statistics
Buffers– cache for block‑device metadata (e.g., superblocks) and raw block I/O. Cached – page cache for file contents read from disk. SwapCached – anonymous pages that have been swapped out but are still cached. SwapTotal and SwapFree – total and free swap space. Dirty – pages modified in memory but not yet written to disk. Writeback – pages currently being written back.
The kernel maintains LRU (least‑recently‑used) lists to decide which pages to reclaim. Since kernel 2.6, an enhanced LRU algorithm separates pages into Active (recently used, low reclaim priority) and Inactive (less recently used, high reclaim priority) lists, each further split into file and anon sub‑lists.
Shared memory
Linux implements shared memory via tmpfs mechanisms. Types include SystemV shared memory ( shmget), POSIX shared memory ( shm_open), and shared anonymous memory ( mmap(MAP_ANONYMOUS|MAP_SHARED)). These pages are counted as File‑backed Pages and appear in the Cached and Mapped counters, not in AnonPages. When such pages are locked with mlock(), they move to the Unevictable list and are also reflected in Mlocked.
Process‑level statistics
VSS – Virtual Set Size, total virtual address space.
RSS – Resident Set Size, physical memory actually resident (includes shared libraries).
PSS – Proportional Set Size, RSS with shared library memory divided among processes.
USS – Unique Set Size, memory used exclusively by the process.
/proc/{pid}/smaps
The /proc/{pid}/smaps file provides a detailed breakdown per memory mapping. Important fields: Size – mapping size. Rss – resident memory for the mapping. Pss – proportional resident memory. Shared_Clean / Shared_Dirty – clean/dirty shared pages. Private_Clean / Private_Dirty – clean/dirty private pages. Referenced – pages marked as referenced. Anonymous – anonymous memory size. AnonHugePages – transparent huge page usage. Swap – swapped‑out portion. KernelPageSize / MMUPageSize – page size used by kernel/MMU. Locked – memory locked via mlock(). VmFlags – a set of flags describing the mapping.
Note that Rss includes shared libraries, so summing it across processes double‑counts shared memory. Pss avoids this by distributing the shared portion.
top command
The top utility shows per‑process memory columns: VIRT – virtual memory size. RES – resident memory size. SHR – shared memory size. SWAP – swapped‑out size. CODE – size of executable code. DATA – data + stack size. USED – RES + SWAP.
Recent kernels also expose smaps_rollup, which aggregates Pss_Anon, Pss_File, and Pss_Shmem for a clearer view of a process’s memory consumption.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
