Note trans. : This fascinating article, revealing in detail the purpose of swap in Linux and responding to a common misconception about it, was written by Chris Down - SRE from Facebook, who, in particular, is developing new metrics in the kernel that help analyze the load on the RAM. And he begins his story with a concise TL; DR ...
TL; DR
- Swap is a fairly important part of a well-functioning system. Without it, it is more difficult to achieve reasonable memory management.
- Swap is needed not so much for urgent memory acquisition, but for even and efficient memory release. To use it as an “urgent memory” is generally very harmful.
- Disabling swap does not save you from disk I / O problems with memory contention — disk I / O simply moves from anonymous pages to file pages. Not only can this be less effective, since there remains a smaller pool of pages available for release, but in itself can contribute to the emergence of this high competition.
Foreword
cgroup v2, , , « » .
swap. swap , Linux . — , , , . , , : , , , , swap — - , , .
swap': « » , .
: «Linux », «swap » .. , «» swap , , — .
, Linux- , / swap 
vm.swappiness, 0.
, swap' — , Linux, , .
Linux , . — , swap .
, 
(«» , 4k), , . , , , . 
[page cache], 
[file] .
, , , , 
malloc MAP_ANONYMOUS mmap. «» — , «», — 
[anon] .
: , slab-, , , — , , , , .
. «» 
[reclaim] , , , .
. , 
[clean], .. , , , - .
, . , 
[dirty], .. , , . 
[reclamation], , .
. , , (.. ).
swap'
, swap Linux, RAM . , , , Google «what is swap»:
« swap — ; , - , RAM. «» , , swap, , . [..] RAM , swap-».
, — « », Linux , , swap'. , swap', .
, «», , , — , . … , ?
swap. Swap — , «» 
[unreclaimable], , . , , ( ), .
Swap — , « ». swap — - .
, « » ? :
- . /, «» ( ) . , .
- , . - , .
swap
swap. « » 
cgroup v2.
- swap: swap , . .
- swap: swap , . , , - , .
- swap: . — , ( [thrashing]).
- swap: , .. . , . . , , / , : disk I/O - swapping' , .
- swap: , OOM killer . , .
- swap: OOM killer , . , OOMing' . — . , OOMing'. , — OOM killer . , , (.. — . .) .
, swap, ?
, cgroup v2?
, , . , , 
vm.swappiness. : 
vm.swappiness , , , .
mlock , 
LD_PRELOAD, . , , - , 
mlockall, , .
cgroup v2 cgroup 
memory.low, . , swapping , . swap' , swap . swap' , , swapper'. , , «».
OOM killer. OOM killer , 
, , . , OOM killer'.
, Linux. , - , : , .. — , . Facebook, 
Johannes' , , — . cgroup v2, 
.
swap' ?
swap-, , , , . — , , , .
(4.0+) , swap' , . kswapd — , swap', — swap, , swap' . swapping' swap- . , 4.0+, swap swapping'. , swap , .
, , , . swap', ( ) . 2-3 swap' , ( ). , , swap' . , , swap . atop 
SWAPSZ , swap. — , ( ). , swap, .
swap'. swap , , . SSD , / , . , , , , . , swapping' , , , , .
/, swap 
[hibernate], , swap- .
swappiness?
-, , 
vm.swappiness. (sysctl), . : 
file_prio ( ) 
anon_prio ( ). 
vm.swappiness , 
anon_prio 200 
file_prio, 
vm.swappiness = 50 anon_prio 50 
file_prio 150 ( — ).
, 
vm.swappiness — , , . , , swap . , , swapping' . - , swap , , «» , swappiness swapping' , . SSD- , 
vm.swappiness = 100 (.. ) . swapping , .. , .
, , , , , — , . , .
vm.swappiness, 
, Satoru Moriya vmscan 2012 : 
vm.swappiness = 0.
, 
vm.swappiness = 0 ( ) , . , , , . 
vm.swappiness = 1 — , , , .
— 
vm.swappiness = 60. , , . , « swap' ?», 
vm.swappiness ( ). , 
refault (. «refault distance-based file cache sizing» — . .), , «page refaulting» cgroup v2.
- Swap — , , . swap , , , , - .
- swap / — I/O . , , , .
- Swap OOM kill , , , . OOM killer , . :
 - , (cgroup) . , Unix . refault detection.
- (, , swapping) (per-cgroup) memory.low, swap.