Comparisons

Two things routinely conflated, put side by side. Neither column is the winner — what decides is the workload and the machine.

CPU cache vs OS page cache

Both are called "cache" and they are almost nothing alike. The CPU cache is hardware holding lines of physical memory and is invisible to software. The page cache is ordinary RAM the kernel uses to hold file data, is software-managed, and is thousands of times larger.

Strengths

Nanosecond-scale, entirely automatic, no software involvement

Costs

Tiny, uncontrollable, and invisible in any profiler that looks at code

Use when

Reasoning about loop performance and data layout

OS page cacheOpen lesson →
Strengths

Huge, inspectable, controllable, and it survives process exit

Costs

Costs a system call to reach, and competes with application memory

Use when

Reasoning about file I/O, database buffer pools and memory pressure

DimensionCPU cacheOS page cache
Managed byHardwareThe kernel
HoldsCache lines of physical memoryPages of file data
ScaleKilobytes to tens of megabytesUp to most of RAM
Software can control itBarely — only through access patternsYes, explicitly