0

I am performing some dd outputs and running in parallel vmstat:

With no direct write (i.e. via cache)

$ dd if=/dev/urandom of=somefile.txt bs=1M count=200 
200+0 records in
200+0 records out
209715200 bytes (210 MB, 200 MiB) copied, 1,31332 s, 160 MB/s



$ vmstat 1 1000
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0     64 2659604 383244 3596884    0    0     3    47   34   14 27  7 66  0  0
 1  0     64 2509432 383244 3746080    0    0     0     0 1005 2278  5 20 75  0  0
 0  0     64 2452560 383248 3807932    0    0     4 204880 1175 2321  4 12 75  9  0
 0  0     64 2453144 383248 3807548    0    0     0     0  814 2677  5  2 93  0  0
 1  0     64 2444868 383248 3814516    0    0     0   244  529 1746  4  2 94  0  0
 0  0     64 2445756 383248 3814516    0    0     0     0  495 1957  3  1 96  0  0

I see that it performed more or less one bulk write

With direct write

$ dd if=/dev/urandom of=somefile.txt bs=1M count=200 oflag=direct
200+0 records in
200+0 records out
209715200 bytes (210 MB, 200 MiB) copied, 1,6902 s, 124 MB/s



$ vmstat 1 1000
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0     64 2623556 383248 3603572    0    0     3    47   35   14 27  7 66  0  0
 1  0     64 2613784 383248 3611220    0    0     0 88064 1001 2573  5 15 79  1  0
 0  0     64 2612236 383256 3611804    0    0     8 116736  912 2033  1 18 78  3  0
 4  0     64 2621076 383256 3604232    0    0     0    96 1086 3250  8  3 89  0  0

My question is the following:

How does this fragmentation of direct writing operation occurs? What is the (kernel?) parameter that determined the file should be broken (when not passing via cache) into 2 chunks of 88 and 116 MB (and not say into 4 chunks of 50MB)?

Would the results be different if i had used the oflag=sync instead of direct?

  • 1
    You are using vmstat to get the stats output once every second (for 1000 seconds), why do you give significance to the fact that in one run of dd, all data was written more or less during one such interval while in the other run, the interval ended partway through the operation? – Kusalananda Dec 15 '18 at 8:42
  • because after multiple experiments this behavior seems consistent; after repeating it with 1G output,using the direct flag seems to break it into more or less 10 writes of 100MB each while not using it caused 3-4 writes (albeit uneven in size); what is more, not using the direct flag causes the writes to be done immediately (in terms of the bo appearing right away in the vmstat output) – pkaramol Dec 15 '18 at 8:47
  • If you are really interested in why the kernel does things this way, I'd (1) read kernel code, (2) use kernel tracing, e.g. perf or or ftrace. I wouldn't expect the high-level behaviour you observe to have a simple explanation or a single parameter (but I don't know). – dirkt Dec 15 '18 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.