The flag iflag=nocache
of dd
seems to take effect only at the second time onwards.
I don't understand why.
I was thinking maybe it is related to readahead cache, but it doesn't explain the results in the table below:
Results - Effect of iflag=nocache: from big SATA SSD file to /dev/null:
Test_Name dd_flags Time[s] time/dd exit status
w/ iflag=nocache iflag=nocache 6.95 0
again w/ iflag=nocache iflag=nocache 6.94 0
first w/o iflag=nocache - 6.94 0
2nd w/o iflag=nocache - 2.60 0
3nd w/o iflag=nocache - 2.49 0
first w/ iflag=nocache iflag=nocache 2.71 0
2nd w/ iflag=nocache iflag=nocache 6.94 0
3rd w/ iflag=nocache iflag=nocache 6.94 0
Regarding the bottom 3 tests/rows:
- The first time that
iflag=nocache
is used, then still the cache is being used (due to the fast time it took). - The last two attempts with
iflag=nocache
took a long time (i.e. w/o cache), which means they probably didn't use the readahead cache, so probably the readahead cache isn't the issue here. - The
iflag=nocache
flag seemingly works, because that the subsequent attempts to use it are much slower, meaning cache isn't being used.
Note:
- The column
dd_flags
in the table above shows all flags which were provided todd
, except the two flagsif
andof
. For rows which have-
for thedd_flags
column, it means thatdd
didn't have additional flags (exceptif
andof
) - The input file to
dd
is a big file (3.8GB) which is stored in SATA SSD (max throughput about 500MB). - The output file for
dd
is /dev/null. - The
Time[s]
column in the table above is the Real time which is a result of thetime
reserved word of Bash. - I don't perform sync because there is no need - file was written before PC was booted.
- I don't empty the OS pagecache (with
echo 1 >|/proc/sys/vm/drop_caches
) because I want to avoid a complete cache invalidation.
I tried dropping the cache for the whole file, as indicated by info dd
- seemed to work:
Results - Effect of iflag=nocache: from big SATA SSD file to /dev/null:
Test_Name dd_flags Time[s] time/dd exit status
w/ iflag=nocache iflag=nocache 6.95 0
again w/ iflag=nocache iflag=nocache 6.95 0
first w/o iflag=nocache - 6.94 0
2nd w/o iflag=nocache - 2.60 0
3nd w/o iflag=nocache - 2.49 0
Drop cache for whole file iflag=nocache,count=0 0.14 0
first w/ iflag=nocache iflag=nocache 6.94 0
2nd w/ iflag=nocache iflag=nocache 6.94 0
3rd w/ iflag=nocache iflag=nocache 6.94 0
Version:
$ dd --version | head -1
dd (coreutils) 8.32
Related readings which didn't solve my issue:
https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation