public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* async I/O seems to be blocking on 2.6.15
@ 2006-11-03  8:23 Brent Baccala
  2006-11-03 12:20 ` Jens Axboe
  0 siblings, 1 reply; 20+ messages in thread
From: Brent Baccala @ 2006-11-03  8:23 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1399 bytes --]

Hello -

I'm running 2.6.15 (Debian) on a Pentium M laptop, PCI attached ext3
filesystem.

I'm writing my first asynchronous I/O program, and for a while I
thought I was really doing something wrong, but more and more I'm
starting to conclude that the problem might be in the kernel.

Basically, I've narrowed things down to a test program which opens a
large (700 MB) file in O_DIRECT mode and fires off 100 one MB async
reads for the first 100 MB of data.  The enqueues take about 5 seconds
to complete, which is also about the amount of time this disk needs to
read 100 MB, so I suspect that it's blocking.

I've gotten the POSIX AIO interface at least tolerably running using
the GLIBC thread-based implementation, but I really want the native
interface working.

I whittled the test program down to use system calls instead of the
POSIX AIO library, and I'm attaching a copy.  You put a big file at
'testfile' (it just reads it) and run the program:


baccala@debian ~/src/endgame$ time ./testaio
Enqueues starting
Enqueues complete

real    0m5.327s
user    0m0.004s
sys     0m0.740s
baccala@debian ~/src/endgame$


Of that five seconds, it's almost all spent between the two "enqueues"
messages.

If anybody can shed any light on this, I'd appreciate your feedback
direct to cosine@freesoft.org (I don't read the list).

Thank you.



 					-bwb

 					Brent Baccala
 					cosine@freesoft.org

[-- Attachment #2: Type: TEXT/x-csrc, Size: 1536 bytes --]


#define _GNU_SOURCE		/* to get O_DIRECT */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>	/* for memset() */
#include <unistd.h>	/* for _PC_REC_XFER_ALIGN */
#include <asm/unistd.h>
#include <fcntl.h>
#include <linux/aio_abi.h>
#include <errno.h>

_syscall2(int, io_setup, int, maxevents, aio_context_t *, ctxp)
_syscall3(int, io_submit, aio_context_t, ctx, long, nr, struct iocb **, iocbs)

#define NUMAIOS 100

#define BUFFER_BYTES (1<<20)

struct iocb iocb[NUMAIOS];
void *buffer[NUMAIOS];

aio_context_t aio_default_context;

main()
{
    int fd;
    int i;
    int alignment;
    struct iocb * iocbp[1];

    fd = open("testfile", O_RDONLY | O_DIRECT);
    alignment = fpathconf(fd, _PC_REC_XFER_ALIGN);

    for (i=0; i<NUMAIOS; i++) {
	if (posix_memalign(&buffer[i], alignment, BUFFER_BYTES) != 0) {
	    fprintf(stderr, "Can't posix_memalign\n");
	}
    }

    io_setup(1024, &aio_default_context);

    fprintf(stderr, "Enqueues starting\n");

    for (i=0; i<NUMAIOS; i++) {

	memset(&iocb[i], 0, sizeof(struct iocb));

	iocb[i].aio_lio_opcode = IOCB_CMD_PREAD;
	iocb[i].aio_fildes = fd;
	iocb[i].aio_buf = (unsigned long) buffer[i];
	iocb[i].aio_nbytes = BUFFER_BYTES;
	iocb[i].aio_offset = BUFFER_BYTES * i;
	/* aiocb[i].aio_offset = 0; */

	iocbp[0] = &iocb[i];
	if (io_submit(aio_default_context, 1, iocbp) != 1) {
	    perror("");
	    fprintf(stderr, "Can't enqueue aio_read %d\n", i);
	}
    }

    fprintf(stderr, "Enqueues complete\n");
}

^ permalink raw reply	[flat|nested] 20+ messages in thread
* RE: async I/O seems to be blocking on 2.6.15
@ 2006-11-07  0:03 Brent Baccala
  2006-11-07  0:24 ` Chen, Kenneth W
  2006-11-07  7:29 ` Jens Axboe
  0 siblings, 2 replies; 20+ messages in thread
From: Brent Baccala @ 2006-11-07  0:03 UTC (permalink / raw)
  To: Chen, Kenneth W; +Cc: linux-kernel

On Mon, 6 Nov 2006, Chen, Kenneth W wrote:

> I've tried that myself too and see similar result.  One thing to note is
> that I/O being submitted are pretty big at 1MB, so the vector list inside
> bio is going to be pretty long and it will take a while to construct that.
> Drop the size for each I/O to something like 4KB will significantly reduce
> the time.  I haven't done the measurement whether the time to submit I/O
> grows linearly with respect to I/O size.  Most likely it will.  If it is
> not, then we might have a scaling problem (though I don't believe we have
> this problem).
> 
> - Ken
> 
>

I'm basically an end user here (as far as the kernel is concerned), so
let me ask the basic "dumb user" question here:

How should I do my async I/O if I just want to read or write
sequentially through a file, using O_DIRECT, and letting the CPU get
some work done in the meantime?  What about more random access?

I've already concluded that I should try to keep my read and write
files on seperate disks and hopefully on seperate controllers, but I
still seem to be fighting this thing to keep it from blocking.


 					-bwb

 					Brent Baccala
 					cosine@freesoft.org

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2006-11-10  9:22 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-03  8:23 async I/O seems to be blocking on 2.6.15 Brent Baccala
2006-11-03 12:20 ` Jens Axboe
2006-11-03 15:58   ` Brent Baccala
2006-11-03 16:02     ` Jens Axboe
2006-11-03 17:09       ` Brent Baccala
2006-11-03 17:30       ` Brent Baccala
2006-11-05 12:15         ` Jens Axboe
2006-11-06  6:42           ` Brent Baccala
2006-11-06 10:43             ` Jens Axboe
2006-11-06 15:52               ` Phillip Susi
2006-11-06 16:02                 ` Jens Axboe
2006-11-06 17:04                   ` Phillip Susi
2006-11-06 17:10                     ` Jens Axboe
2006-11-06 21:22           ` Chen, Kenneth W
2006-11-07  7:26             ` Jens Axboe
2006-11-07 21:02             ` Bill Davidsen
2006-11-10  9:24             ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2006-11-07  0:03 Brent Baccala
2006-11-07  0:24 ` Chen, Kenneth W
2006-11-07  7:29 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox