[comp.unix.i386] dd curiosity

mark@zok.UUCP (Mark W. Snitily) (12/31/89)

This is really just a trivia question about the implementation of dd.
Have recently been using dd to read/write sectors to/from a raw disk
partition.  Noticed a large speed difference based upon the direction
of the I/O.

For example, if I write 4 sectors into the partition starting at sector
20000, the write will complete very fast, (i.e. a few seconds):
      dd if=myfile of=/dev/rdsk/0p1 seek=20000 count=4

But, if I read 4 sectors from the partition starting at sector 20000,
the read will take forever to complete, (i.e. we're talking minutes to
hours depending upon the skip value):
      dd if=/dev/rdsk/0p1 of=myfile skip=20000 count=4

Anyone have any ideas why reading with dd takes so long?

Any ideas of how to speed it up?  (e.g. Don't use dd, use program xyz
instead.  Or something like, if you specify undocumented option "inseek",
then dd will seek to the specified sector of the input file rather than
reading every sector.  etc...)

BTW, Running 386/ix 2.0.2, raw disk partition is on an ESDI 14ms drive.

Thanks...

-- Mark

Mark W. Snitily                 Consulting Services:
894 Brookgrove Lane             Graphics, Operating Systems, Compilers
Cupertino, CA 95014             (408) 252-0456
mark@zok.uucp

bill@twwells.com (T. William Wells) (12/31/89)

In article <396@zok.UUCP> mark@zok.UUCP (Mark W. Snitily) writes:
: For example, if I write 4 sectors into the partition starting at sector
: 20000, the write will complete very fast, (i.e. a few seconds):
:       dd if=myfile of=/dev/rdsk/0p1 seek=20000 count=4

Does an lseek to the appropriate place.

: But, if I read 4 sectors from the partition starting at sector 20000,
: the read will take forever to complete, (i.e. we're talking minutes to
: hours depending upon the skip value):
:       dd if=/dev/rdsk/0p1 of=myfile skip=20000 count=4

Reads everything from the beginning of /dev/rdsk/0p1 till it gets
to the place to read.

: Any ideas of how to speed it up?

Use seek instead of skip.

---
Bill                    { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com

mark@zok.UUCP (Mark W. Snitily) (01/01/90)

In article <1989Dec30.233951.23096@twwells.com> bill@twwells.com (T. William Wells) writes:
>In article <396@zok.UUCP> mark@zok.UUCP (Mark W. Snitily) writes:
>: But, if I read 4 sectors from the partition starting at sector 20000,
>: the read will take forever to complete, (i.e. we're talking minutes to
>: hours depending upon the skip value):
>:       dd if=/dev/rdsk/0p1 of=myfile skip=20000 count=4
>
>Reads everything from the beginning of /dev/rdsk/0p1 till it gets
>to the place to read.
>
>: Any ideas of how to speed it up?
>
>Use seek instead of skip.

Thanks for the suggestion, but quoting from the manual:
    skip=n   skips n input blocks before starting copy
    seek=n   seek n blocks from beginning of output file before copying

"skip" applies to the input file.  "seek" applies to the output file.
What I'd like to have is a "seek" performed on the input file.
Ideas anyone?

-- Mark

Mark W. Snitily                 Consulting Services:
894 Brookgrove Lane             Graphics, Operating Systems, Compilers
Cupertino, CA 95014             (408) 252-0456
mark@zok.uucp

bill@twwells.com (T. William Wells) (01/01/90)

In article <397@zok.UUCP> mark@zok.UUCP (Mark W. Snitily) writes:
: Thanks for the suggestion, but quoting from the manual:
:     skip=n   skips n input blocks before starting copy
:     seek=n   seek n blocks from beginning of output file before copying
:
: "skip" applies to the input file.  "seek" applies to the output file.
: What I'd like to have is a "seek" performed on the input file.
: Ideas anyone?

Right you are. I got it in my head that both applied to the input
file and just never checked. Now, back to the original problem....

Assuming that seekprog is something like this highly condensed
version:

main(argc, argv)
char    **argv;
{
	extern long atol(), lseek();

	return lseek(0, atol(argv[1]) * atol(argv[2]), 0) == -1;
}

Try:

( seekprog 20000 512 ; dd of=myfile ) </dev/rdsk/0p1

There might be an easier way than writing a program, but I can't
think of one right off the top of my head.

---
Bill                    { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com

joe@junkyard.UUCP (Joseph Sarkes) (01/02/90)

In article <396@zok.UUCP>, mark@zok.UUCP (Mark W. Snitily) writes:
> partition.  Noticed a large speed difference based upon the direction
> of the I/O.
> 
> For example, if I write 4 sectors into the partition starting at sector
> 20000, the write will complete very fast, (i.e. a few seconds):
>       dd if=myfile of=/dev/rdsk/0p1 seek=20000 count=4
> 
> But, if I read 4 sectors from the partition starting at sector 20000,
> the read will take forever to complete, (i.e. we're talking minutes to
> hours depending upon the skip value):
>       dd if=/dev/rdsk/0p1 of=myfile skip=20000 count=4

dd skip= READS over the amount specified. See if your dd command has an
option iseek= instead of using skip=.
This should seek over the space instead of reading all of it.
You can either use strings /bin/dd | grep iseek,
or just try using the option and look for an error message.

I understand that some raw devices also have problems seeking, so
you may have better luck using iseek with a block device.

Joseph Sarkes	(junkyard!joe)

djm@eng.umd.edu (David J. MacKenzie) (01/02/90)

With if=myfile dd can use lseek to skip.
With if=/dev/rdsk/0p1 perhaps it either can't use lseek or thinks it
can't, so uses read to skip instead.  Just a guess.
--
David J. MacKenzie <djm@eng.umd.edu>

bga@bgalli.eds.com (Billy G. Allie) (01/02/90)

bill@twwells.com (T. William Wells) writes:

:In article <396@zok.UUCP> mark@zok.UUCP (Mark W. Snitily) writes:
::   ...
:: But, if I read 4 sectors from the partition starting at sector 20000,
:: the read will take forever to complete, (i.e. we're talking minutes to
:: hours depending upon the skip value):
::       dd if=/dev/rdsk/0p1 of=myfile skip=20000 count=4
:
:Reads everything from the beginning of /dev/rdsk/0p1 till it gets
:to the place to read.
:
:: Any ideas of how to speed it up?
:
:Use seek instead of skip.

Using seek will cause it to seek to block 20000 of the _OUTPUT_ file.
Some versions of dd have an iseek option to seek on the input file.  The
easiest way to find out is to try it and see if it works.  If it doesn't
work, you will have to continue to use (the slow method of using) skip.
-- 
____	   | Billy G. Allie	| Internet..: bga@bgalli.eds.com
|  /|	   | 7436 Hartwell	| UUCP......: uunet!edsews!bgalli!bga
|-/-|----- | Dearborn, MI 48126	| Compuserve: 76337,2061
|/  |LLIE  | (313) 582-1540	| Genie.....: BGALLIE

bill@twwells.com (T. William Wells) (01/02/90)

In article <592@junkyard.UUCP> joe@junkyard.UUCP (Joseph Sarkes) writes:
: dd skip= READS over the amount specified. See if your dd command has an
: option iseek= instead of using skip=.

Mine, Microport SysV/386 3.0e, has an option iseek. What it does
I haven't tested. It is, of course, undocumented. Grrrrr.

---
Bill                    { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com

alh@einoed.UUCP (Adrian Le Hanne) (01/05/90)

mark@zok.UUCP (Mark W. Snitily) writes:

>For example, if I write 4 sectors into the partition starting at sector

>But, if I read 4 sectors from the partition starting at sector 20000,
>the read will take forever to complete, (i.e. we're talking minutes to
[...]
>Anyone have any ideas why reading with dd takes so long?

A write is stored in the buffer cache while a read must access the storage 
directly to get (uncached) data.

>-- Mark

Adrian
-- 
Adrian S. Le Hanne           ..!tmpmbx!einoed!alh                    alh@einoed
Einoed Systemberatung. Joachimstalerstr.19, 1000 Berlin 15. Tel.:030 / 88000335
             "Le plus semblable aux morts meurt le plus 'a regret"