[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Don't do unneccesary memory copies in dd.
From: |
Pádraig Brady |
Subject: |
Re: [PATCH] Don't do unneccesary memory copies in dd. |
Date: |
Sat, 22 Nov 2008 00:40:29 +0000 |
User-agent: |
Thunderbird 2.0.0.6 (X11/20071008) |
Pádraig Brady wrote:
> Paul Eggert wrote:
>> $ (echo 'x'; sleep 10; echo y) | dd ibs=3 obs=3
>>
>> POSIX says that in this case the output data must be reblocked into
>> blocks of 3 bytes. With the working 'dd', you'll see a pause of 10
>> seconds (because the first 'echo' outputs only 2 bytes), then the x and
>> y right away (because we now have all 4 input bytes, and can issue a
>> write of 3 bytes and a write of 1 byte). With a buggy 'dd', you'll see
>> the 'x' right away (because we output a 2-byte block), then a pause of
>> 10 seconds, then a 'y' (the other 2-byte block).
>>
>> The simplest fix I see is to revert the patch. Of course one could up
>> with something fancier....
>>
>
> Thanks for that Paul.
> That certainly isn't obvious, and deserves a comment in the code.
>
> A question so on the default behaviour of dd.
> Should it behave like bs=512 or ibs=512 obs=512,
> i.e. should it memcpy/reblock by default?
So I read the actual POSIX spec and it's quite clear
that a single buffer should only be used if bs= is specified.
Note it also states that bs= supersedes [io]bs=
I.E. if you specify [io]bs= and bs= then the code with
revert applied will erroneously use 2 buffers?
Not a major issue I know, but this little bit
of logic has been very confusing for me.
I've replied to another email in this thread with
a cleanup patch which hopefully is less confusing
and addresses the issue above.
cheers,
Pádraig.