bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Don't do unneccesary memory copies in dd.


From: Jim Meyering
Subject: Re: [PATCH] Don't do unneccesary memory copies in dd.
Date: Fri, 21 Nov 2008 09:16:31 +0100

Pádraig Brady <address@hidden> wrote:

> I was surprised that dd did memcpy() by default,
> which one can see using:
>
> ltrace -e memcpy dd if=/dev/zero of=/dev/null count=10
>
> Now if you specify bs=512 for example
> a memcpy() is not done, which seems inconsistent to me.
>
> What about the attached patch to not do a
> memory copy in any of the combinations where
> ibs = obs, and conversions are not done?
>
> cheers,
> Pádraig.
>>From 3bf7a447aa0b2339915cb5abe4d17919224c88dc Mon Sep 17 00:00:00 2001
> From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
> Date: Thu, 20 Nov 2008 22:49:02 +0000
> Subject: [PATCH] Don't do unneccesary memory copies in dd.

That looks fine.
You're welcome to push it, but please first amend it to use
the following log message instead, which starts with "PROGNAME: "
and mentions the affected function name.

----------
dd: avoid unnecessary memory copies

* src/dd.c (scanargs): When not otherwise required (e.g. for
conversion), use two-buffer mode only when the input and output
buffer sizes differ.  Before, some of the most basic invocations of
dd, e.g., dd < in > out, would unnecessarily use separate buffers
and perform unnecessary memcpy operations.
----------

I was disappointed to see no performance improvement.
But it's not too surprising: this affects dd only with a block
size that's so low (512) that the cost of the memcpy is
lost in the noise of the read/write syscalls.
Maybe on some small/old CPU it actually does make a difference.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]