The reason why buffers in "free -h" command output is increased

The reason why buffers in "free -h" command output is increased

Ich habe zwei Experimente gemacht.

Das erste Experiment (Ubuntu 20.04, ext4-Dateisystem):

  1. 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
  1. Führen Sie den Befehl aussudo find / | grep something
  2. Führen Sie den Befehl free -h -werneut 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):

  1. 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
  1. Befehl ausführen dd if=/dev/nvme0n1p2 of=/dev/null bs=1M count=500- Ihre Festplatte wäre hier eine andere
  2. Führen Sie den Befehl free -h -werneut 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 bufferswurde 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 freesagt uns auch, dass die cacheSpalte 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.

verwandte Informationen