![The reason why buffers in "free -h" command output is increased](https://rvso.com/image/192257/The%20reason%20why%20buffers%20in%20%22free%20-h%22%20command%20output%20is%20increased.png)
Ich habe zwei Experimente gemacht.
Das erste Experiment (Ubuntu 20.04, ext4-Dateisystem):
- Führen Sie den Befehl aus
free -h -w
:
$ free -h -w
total used free shared buffers cache available
Mem: 30Gi 2,6Gi 25Gi 106Mi 126Mi 2,1Gi 27Gi
- Führen Sie den Befehl aus
sudo find / | grep something
- Führen Sie den Befehl
free -h -w
erneut aus und beobachten Sie die deutliche Vergrößerung (ca. 1 G) der Spalte „Puffer“ sowie die Vergrößerung der Spalte „Cache“ (ca. 500 M):
$ free -h -w
total used free shared buffers cache available
Mem: 30Gi 2,6Gi 24Gi 106Mi 1,2Gi 2,6Gi 27Gi
Das zweite Experiment (gleicher PC):
- Führen Sie den Befehl aus
free -h -w
:
$ free -h -w
total used free shared buffers cache available
Mem: 30Gi 2,6Gi 24Gi 106Mi 1,2Gi 2,6Gi 27Gi
- Befehl ausführen
dd if=/dev/nvme0n1p2 of=/dev/null bs=1M count=500
- Ihre Festplatte wäre hier eine andere - Führen Sie den Befehl
free -h -w
erneut aus und beobachten Sie die Puffervergrößerung um 500 MB:
$ free -h -w
total used free shared buffers cache available
Mem: 30Gi 2,6Gi 24Gi 115Mi 1,7Gi 2,6Gi 27Gi
Die Frage ist also: Warum buffers
wurde die Spalte im ersten und im zweiten Fall erhöht? Ich habe dies gelesenWas ist die Pufferspalte in der Ausgabe von Free?aber die Antworten hier sind für mich nicht angemessen.
Sie sagen „die Spalte „Puffer“ enthält Metadaten zu Dateien“ – aber das ist falsch, weil es die Spalte „Cache“ ist, die Slabs für Inode, Dentry und Buffer_head zählt (die eigentlich Metadaten von Dateien sind). man free
sagt uns auch, dass die cache
Spalte enthält SReclaimable
.
They also tell "buffers column contains cache of blocks from block devices" - and it looks more like the truth, it explains why buffers
increased when I ran dd
, but it does not explain why buffers
column increased when I ran find
command. And even in case of dd
- why we need it if we already have file cache? Nobody read/write directly from/to block devices except of DVD disks.
Antwort1
Found the answer here: How to identify cause of large buffer memory usage?
Seems that Linux stores files' inodes twice: first time as ext4_inode_cache
/inode_cache
in slabs (I observed increasing of sizes of these slabs with slabtop
command) and second time in buffers (because inodes are directly read from block devices, and all blocks which were directly read from block devices are stored in buffers). So when I run find
command, then linux reads inodes' blocks from block device, saves them in buffers and then creates inodes' cache in slabs. In result, both cache
and buffers
columns in free
output are increased.