Dirty in /proc/meminfo for dd

iomemoryproc

I read from here that the below command gives me the amount of data that needs to be written to the disk.

grep ^Dirty /proc/meminfo

It particularly says Ever ask yourself "How much data would be lost if I pressed the reset button?"

I wanted to test the above command and so I did the following.

dd if=/dev/urandom of=sample.txt bs=1G count=1

Now, in another shell I ran the above command.

grep ^Dirty /proc/meminfo
Dirty:                44 kB
grep ^Dirty /proc/meminfo
Dirty:                36 kB

However, if I do a file copy using cp it reports,

grep Dirty /proc/meminfo
Dirty:            387680 kB
grep Dirty /proc/meminfo
Dirty:            609172 kB

I see from this page what Dirty does.

Dirty — The total amount of memory, in kilobytes, waiting to be
written back to the disk.

Why Dirty is not reporting any size in case of dd?

Best Answer

Try using this command instead:

dd if=/dev/urandom of=sample.txt bs=1M count=1024

dd will only write assign the data to be written to disk when it got all of the bs size in its memory.

Here is the output of ps for a dd of 128mb just before the output was written to disk:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND    
root      4465  100 12.8 236260 129784 pts/1   R+   17:15   0:13 dd if=/dev/urandom of=sample.txt bs=128M count=1

You can see the process is using about 130mb of ram (RSS Column)

Related Question