0

I did two experiments.

The first experiment (Ubuntu 20.04, ext4 filesystem):

  1. Run command free -h -w:
$ free -h -w
              total        used        free      shared     buffers       cache   available
Mem:           30Gi       2,6Gi        25Gi       106Mi       126Mi       2,1Gi        27Gi
  1. Run command sudo find / | grep something
  2. Run command free -h -w again and observe significant (about 1G) increasing of "buffers" column, and increasing of "cache" column as well (about 500M):
$ free -h -w
              total        used        free      shared     buffers       cache   available
Mem:           30Gi       2,6Gi        24Gi       106Mi       1,2Gi       2,6Gi        27Gi

The second experiment (same PC):

  1. Run command 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. Run command dd if=/dev/nvme0n1p2 of=/dev/null bs=1M count=500 - your disk would be another here
  2. Run command free -h -w again and observe 500M increasing of buffers:
$ free -h -w
              total        used        free      shared     buffers       cache   available
Mem:           30Gi       2,6Gi        24Gi       115Mi       1,7Gi       2,6Gi        27Gi

So the question is: why buffers column was increased in the first and why in the second case? I've read this What is the buffers column in the output from free? but answers here are not appropriate for me.

They tell "buffers column contains metadata about files" - but it is wrong, because it is the "cache" column that counts slabs for inode, dentry and buffer_head (which are actually metadata of files). man free also tells us that cache column contains 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.

1
  • But note that the "available" didn't change. When you no longer need the buffer data, you can just leave it there. The unneeded data can be "instantly" thrown away if you start to run low on space. Jun 19, 2021 at 0:52

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .