brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Dirty and Writeback in /proc/meminfo show how much data Linux still has to write to disk

Linux
~/tips/tip-linux-meminfo-dirty-writeback

watch -n 1 "grep -E '^(Dirty|Writeback):' /proc/meminfo"

Know when a copy has really reached the disk before you pull a USB drive.

A copy to a USB stick finishes in seconds, yet the stick keeps blinking. Linux accepted the data into memory and writes it out in the background. Two lines in /proc/meminfo show how much is still on its way.

watch -n 1 "grep -E '^(Dirty|Writeback):' /proc/meminfo"

Dirty is data in memory that has changed and still waits to be written. Writeback is data that is being written right now. After a big copy you see Dirty jump up and then drain away. When both are back to a few hundred kilobytes, the system has caught up.

To wait for one disk in particular, use sync on it:

sync -f /media/usb/backup.tar

sync -f flushes the filesystem that file lives on, and returns when the data is written. Unmounting does that too, which is why umount can take a while after a fast copy. I’d always unmount before unplugging, and watching these numbers explains the wait.

How much dirty data may pile up is set by vm.dirty_background_ratio and vm.dirty_ratio. The first decides when the kernel starts writing in the background, the second when a program that writes has to wait and help. On a machine with lots of RAM and a slow USB disk, those percentages allow gigabytes of unwritten data, so a copy looks fast and the unmount takes ages. Lowering them makes copies look slower but more honest. Change them carefully and test, since they affect every disk at once.

Further reading: proc_meminfo(5) manual page, Documentation for /proc/sys/vm/

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link