Re: How do disk writes work these days?
Re: How do disk writes work these days?
- Subject: Re: How do disk writes work these days?
- From: "Justin C. Walker" <email@hidden>
- Date: Tue, 30 Jul 2002 09:12:05 -0700
On Tuesday, July 30, 2002, at 07:38 AM, Pelle Johansson wrote:
torsdagen den 25 juli 2002 kl 11.04 skrev Timothy A. Seufert:
Wade Tregaskis <email@hidden> wrote:
Wade -- one thing you might want to look in to is that some
operating
systems implement an asynchronous I/O API in addition to traditional
blocking synchronous I/O. For asynch, the difference in the
sequence of
events (from userland POV) is that the initial I/O call doesn't
block,
and there is always some mechanism to notify the process of I/O
completion. In "classic" MacOS, ISTR this was done by giving the
OS a
pointer to a callback function, which would be called on error or
completion. I think it also set a flag in the descriptor structure
used
to request the I/O, so you could also determine completion by
polling
that flag.
Is this still an efficient way of operating, in an increasingly
linear [e.
g. single-user] OS? I'm just thinking, if you could return from
writes
faster, the calling process can keep doing other things.
The classic way of doing this in UNIX systems is to make the
application multithreaded. By splitting things into an I/O thread and
a (other stuff) thread, you can avoid making the whole program stop
every time it needs to do I/O.
IMO, a much better way, in programs where it is possible, is to use
O_NONBLOCK (in either open() or fcntl()) and select() to check for
writable file descriptors. Most programs should in fact be centered
around a select() call. If you wish, you can check for SIGIO as well,
but it is usually not necessary.
O_NONBLOCK and select() are not very useful in writing to files; the
kernel will, on the user's thread, copy the data into the kernel (or
locate the page in the page buffer, depending on details of the call and
the user's buffer layout), and then return to user mode. Writes to a
file are (already) essentially asynchronous.
FreeBSD (and other Unix/Unix-like OS's) have "asynch I/O" functionality,
but for this specific use, it's overly complicated for no real gain.
Regards,
Justin
--
Justin C. Walker, Curmudgeon-At-Large *
Institute for General Semantics | Men are from Earth.
| Women are from Earth.
| Deal with it.
*--------------------------------------*-------------------------------*
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.