Re: why I told dd command to write but it reads in first?
From: Doug Gale (dgaleSPAMTHISYOUSCUM_at_mailexcite.com)
Date: 06/19/04
- Next message: Doug Gale: "Re: http server"
- Previous message: Kasper Dupont: "Re: Correlating PID to interrupt requests"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 19 Jun 2004 00:14:30 GMT
"Josef Moellers" <josef.moellers@fujitsu-siemens.com> wrote in message
news:c91suc$3c3$1@nntp.fujitsu-siemens.com...
tcs wrote:
>> Greetings!
>> I am using `dd` command to measure raw disk write speed.
>> I did "dd if=/tmp/test.bin of=/dev/sda1"
>>
>> According to my device driver, `dd` command reads in the whole
>> /dev/sda1 first then writes to it. Should dd just read /dev/sda1? The
>> even weird thing is that dd command reads in as many sectors as the size
>> of /tmp/test.bin file, can someone tell me why?
>
> dd's block size is 512 by default. Linux' buffer size is 4k by default.
> Linux uses the buffer cache by default.
> When dd starts writing, the first 512 bytes arrive in the buffer cache
> and the buffer cache must assume that this will be an update of the
> first 512 bytes of the first buffer, so it must read the first buffer
> and modify the first 512 bytes. This will happen with each 4k buffer of
> the entire disk.
> --
> Josef Möllers (Pinguinpfleger bei FSC)
> If failure had no penalty success would not be a prize
> -- T. Pratchett
Processors have the same behaviour. Instead of 4KB blocks, it is 64-byte
lines. Instead of 512-byte sectors, it is individual bytes. You could say,
using disk terminology and a little imagination, a modern x86 CPU has a
64-byte block size and a 1-byte sector size.
You can't write one byte to memory on a modern processor because it will
read that cache line and modify the byte in the cache. However, really
modern processors use "write combining". Write combining is like a special
cache line that optimizes sequential writes. If you write to ALL the bytes
in the write combining buffer, it does not bother with the read, and just
writes over what is in main memory. If you DON'T write all the bytes in the
cache line, it must read the line being modified, then it merges all the
bytes in the (partially filled) write combining buffer to the cache line, as
it would if there were no write combining.
Why doesn't Linux use a "write combining" algorithm for the sectors in a
block? It could have a special buffer that caches sequential sector writes,
allowing it to avoid unnecessary reads entirely.
If you want a really clear explanation of write combining, see the AMD
Athlon Optimization Guide from the AMD website.
Doug Gale
--- Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.707 / Virus Database: 463 - Release Date: 6/15/2004
- Next message: Doug Gale: "Re: http server"
- Previous message: Kasper Dupont: "Re: Correlating PID to interrupt requests"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|