* Re: Slow random file access under OSF/1 on Dec alpha
1993-08-26 15:38 Slow random file access under OSF/1 on Dec alpha Brent McClure
@ 1993-08-27 0:36 ` Alan Rollow - Alan's Home for Wayward Tumbleweeds.
1993-08-31 12:01 ` Jari Tavi
1 sibling, 0 replies; 4+ messages in thread
From: Alan Rollow - Alan's Home for Wayward Tumbleweeds. @ 1993-08-27 0:36 UTC (permalink / raw)
In article <CCDI3H.400@tiguex.cs.unm.edu>, mcclure@tiguex.cs.unm.edu (Brent McClure) writes:
>Newsgroups: comp.unix.osf.misc
>From: mcclure@tiguex.cs.unm.edu (Brent McClure)
>Subject: Slow random file access under OSF/1 on Dec alpha
>
>I'm experiencing extremely slow file accesses when I have code that jumps
>around in a file and accesses it at random locations. The following
>sample program brings out the problem, and if the output file "foo" is
>large enough ( greater than about 65536 bytes on our system ) then
>this program runs _much_ slower on our Dec Alpha than on any other
>unix I can find to run it on.
>
Using a similar program that let me adjust a "block" size and the
I/O size, I was able to do some experimentation. The program is
below. The problem had been noticed by some other customer using
FORTRAN and it has been reported internally. The problem is still
present in V1.3, so the earliest it would be fixed without a patch
is the next version after V1.3.
From my experiments, it appears there is a special boundary
every 64 KB. When random I/Os cross this boundary the I/O
(I'd guess) the previous buffer is flushed. From the I/O
speeds I'm seeing it may be that the current buffer won't
be "finished" until the previous one really is (*), but
I didn't look closely. The behaviour may change slightly
by changing the value of delay_wbuffers.
It may also be that the I/O is being started asyncronously, but
as soon as the program tries to touch a buffer in transit, it
blocks waiting for the I/O to complete. An interesting way to
test this might be to update the file backwards.
The reason that random (or backwards) is interesting, is that
the kernel knows (or thinks it knows) when access is sequential.
As long as you make too much of the buffer cache dirty, a program
writing sequentially, will run at the speed it takes to copy data
from the user buffer to the buffer cache. Another interesting test
would be to see if the kernel things writing forward, but skipping
over the un-updated part is sequential:
+-------+-------+-------+-------+-------+
| write | skip | write | skip | write |
+-------+-------+-------+-------+-------+
Other things we've learned about the problem is that it is specific
to UFS on OSF/1. It doesn't occur on ULTRIX V4.3, nor does it
occur on OSF/1 using the POLYCENTER Advanced File System (or so
I've heard).
(*) Most file system I/O is done asynchronously. To the user
a write appears complete when a buffer has been allocated
in the kernel and his data copied into that buffer. It may be
some tens of seconds before the data is actually written to
disk.
>
>My guess is that there is some kernel parameter that I can tune to
>change this behavior, but I'm not sure what this would be. Can anyone
>suggest anything, or see if this occurs on your system?
On ULTRIX delay_wbuffers was in param.c, but it's moved to ufs_vnops.o
on OSF. I wouldn't be surprised if the magick 64 KB number is also
around there somewhere instead of in param.c or a data file.
* * *
Here is the program. The arguments are:
program file-name block-size io-size
I writes 2 "block-size" blocks and then goes through a loop seeking
back and forth between the two, write an "io-size" buffer after each
lseek. When the I/O stays within one 64 KB area, the program makes
the area dirty, but little I/O occurs. For example:
program data 32768 8192
runs very fast, but:
program data 65536 8192
doesn't.
/*
* Author: Alan Rollow, Subsystems Engineering, Digital Equipment Corp.
* File: %M%
* Date: %G%
* Version: %I%
*
* %M% - Exercise the magic 64 KB boundary.
*/
#ifndef lint
static char SccsId[] = "%W% %G%" ;
#endif
#include <sys/types.h>
#include <sys/file.h>
#include <stdio.h>
#include <errno.h>
char *program ;
main(argc, argv)
int argc ;
char *argv[] ;
{
char *file ;
register fd, size, iosize ;
if( argc < 4 ) {
fprintf(stderr, "usage: %s file size iosize\n", argv[0]) ;
exit(-1) ;
}
else {
program = argv[0] ;
file = argv[1] ;
size = atoi(argv[2]) ;
iosize = atoi(argv[3]) ;
}
if((fd = open(file, O_WRONLY|O_CREAT, 0644)) == -1 ) {
fprintf(stderr, "%s: Can't open %s: %s.\n", program, file,
strerror(errno)) ;
exit(errno) ;
}
write_file(fd, file, size) ;
exercise_file(fd, file, size, iosize) ;
if( close(fd) == -1 )
fprintf(stderr, "%s: Can't close %s: %s.\n", program, file,
strerror(errno)) ;
return 0 ;
}
#define NBLOCKS (2)
/*
* Write NBLOCKS blocks of "size" in the file.
*/
write_file(fd, file, size)
int fd, size ;
char *file ;
{
char *buffer ;
void *malloc() ;
int rc ;
if((buffer = (char *)malloc(size * NBLOCKS)) == NULL ) {
fprintf(stderr, "%s: Can't allocate %d bytes: %s.\n",
program, size * NBLOCKS, strerror(errno)) ;
exit(errno) ;
}
if((rc = write(fd, buffer, size * NBLOCKS)) == -1 ) {
fprintf(stderr, "%s: Write error on %s: %s.\n",
program, file, strerror(errno)) ;
exit(errno) ;
}
else if( rc != (size * NBLOCKS)) {
fprintf(stderr, "%s: Short write of %d bytes on %s.\n",
program, rc, file) ;
exit(-1) ;
}
else
free((void *)buffer) ;
return ;
}
#define ALOT 1000
/*
* The file consists of two block of "size" bytes each. Seeking
* between block, write "iosize" bytes. Do this "ALOT" of times
* and measure the time as simply as possible.
*/
exercise_file(fd, file, size, iosize)
register fd ;
int size ;
char *file ;
register iosize ;
{
time_t before, after, time() ;
register loops, rc ;
register char *buffer ;
register size_t total ;
if((buffer = (char *)malloc(iosize)) == NULL ) {
fprintf(stderr, "%s: Can't allocate %d bytes: %s.\n",
program, iosize, strerror(errno)) ;
exit(errno) ;
}
loops = ALOT ;
total = 0L ;
before = time((time_t)0) ;
/*
* Seek to the beginning of the first "size" block and write
* something, then seek to the beginning 2nd "size" block
* and write something.
*
* It appears, that when the I/Os spans a 64 KB boundary
* the previous buffer is flushed. The guess of the author
* is that the I/O is started to complete asynchronously.
*
* If the I/O stays within one of these 64 KB boundaries,
* very little I/O occurs.
*/
while( loops-- ) {
if( lseek(fd, 0L, SEEK_SET) == -1 )
fprintf(stderr, "%s: Rewind failed on %s: %s.\n",
program, file, strerror(errno)) ;
if((rc = write(fd, buffer, iosize)) == -1 )
fprintf(stderr, "%s: First write failed on %s: %s.\n",
program, file, strerror(errno)) ;
else
total += rc ;
if( lseek(fd, (off_t)size, SEEK_SET) == -1 )
fprintf(stderr, "%s: Seek failed on %s: %s.\n",
program, file, strerror(errno)) ;
if((rc = write(fd, buffer, iosize)) == -1 )
fprintf(stderr, "%s: Second write failed on %s: %s.\n",
program, file, strerror(errno)) ;
else
total += rc ;
}
after = time((time_t)0) ;
free((void *)buffer) ;
if( after - before ) {
printf("%d I/Os in %d seconds: %f tps, %f KB/sec.\n", ALOT * 2,
after - before, (double)(ALOT * 2)/(after - before),
(double)(total / 1024)/(after - before)) ;
}
else
printf("%d I/Os and %d KB too fast.\n", ALOT * 2,
total / 1024) ;
}
--
Alan Rollow alan@nabeth.cxo.dec.com
^ permalink raw reply [flat|nested] 4+ messages in thread