Raw disk I/O

Larry McVoy lm at snafu.Sun.COM
Sun Feb 25 07:58:27 AEST 1990


In article <1990Feb23.223030.9851 at ladc.bull.com> fmayhar at hermes.ladc.bull.com writes:
>... blocking I/O.  We got about
>40k-45k/s.  With block-mode I/O, we get from around 90 k/s to as much as
>200 k/s or a little more, depending on the test parameters.  Are you saying
>that we could exceed these figures using raw I/O?

I sure hope so.  Those are pathetic I/O rates.  

sparcstation 1, SunOS 4.1, Quantum 3.5" SCSI drive:

$ time dd if=/dev/rsd1c of=/dev/null count=400 bs=8k
400+0 records in
400+0 records out

real    0m7.61s
user    0m0.03s
sys     0m0.66s
$ bc
400*8/7.61
420			# kbytes / second for sequential
^D
$

It's probable that you are doing radom I/O so I wrote a little program
that uses rand(3) to calulate the offset into the drive (see below) and
that gives me about 180 Kb / sec (you can really hear the old head seeking).
This assumes that I need all of the 8k block that I read. If you have smaller
records, you'll get worse throughput.  For example, if you only need one byte
of that 8k, your throughput goes down by a factor of 8192.  


Here's the random program (start/stop/ptime are timing utils):

#include <signal.h>

int blks;

main(ac, av)
	char **av;
{
	int fd;
	int disksize;
	char buf[8192];
	int done();

	disksize = atoi(av[2]);		/* blocks */
	srand(3962);			/* my birthday */
	signal(SIGINT, done);
	start();
	fd = open(av[1], 0);
	for (blks = 0; ; blks++) {
		lseek(fd, (rand() % disksize) * 8192, 0);
		if (read(fd, buf, sizeof buf) != sizeof buf)
			break;
	}
	done();
}

done()
{
	stop();
	ptime(blks);
	exit(0);
}
---
What I say is my opinion.  I am not paid to speak for Sun, I'm paid to hack.
    Besides, I frequently read news when I'm drjhgunghc, err, um, drunk.
Larry McVoy, Sun Microsystems     (415) 336-7627       ...!sun!lm or lm at sun.com



More information about the Comp.unix.wizards mailing list