Understanding Linux page cache memory

If data is written, it is first written to the Page Cache and managed as one of its dirty pages. Dirty means that the data is stored in the Page Cache, but needs to be written to the underlying storage device first. The content of these dirty pages is periodically transferred (as well as with the system calls sync or fsync) to the underlying storage device.

$ dd if=/dev/zero of=demofile.txt bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB, 20 MiB) copied, 0.0320754 s, 654 MB/s

Now we can check the Dirty pages, which shows the amount of data in Page cache which needs to be written to storage.

$ cat /proc/meminfo | grep Dirty
Dirty:              1092 kB

Now, we can use sync command in Linux to make sure all the dirty pages are cleared and the cached data is written to disk, so we are safe to perform any operations like unmount etc on the disk.

$ sync

Now, we can verify that all cached data is written to disk.

$ cat /proc/meminfo | grep Dirty
Dirty:                 0 kB

Leave a Comment