Re: When does `write' return?
- From: Jean-David Beyer <jdbeyer@xxxxxxxxxxx>
- Date: Thu, 12 Jan 2006 09:02:14 -0500
Andrew Xue wrote:
> Hello,
>
> As far as I know, the system call `write' is asynchronous, which would
> leave the `data' in page cache. The `data' would be flushed in the
> background, thus the `write' could return quickly, in order to improve
> the performance.
>
> My question is: when would the `write' return? For example:
>
> write(fd, buf, 1GB)
>
> The 1GB buf will be written in to disk file represented by `fd'. When the
> `write' returns, how much of buf has been written? Does the kernel cache
> the buf with copy-on-write or just making a full memory copy?
>
>
> I am not so familiar with linux kernel, please forgive me if the question
> is too silly.
>
It is not silly.
It depends on a coupla things. If you have much more than 1GBytes of ram,
the write could return as soon as the data get to a memory buffer. Possibly
some of the cache would have to be paged out, but not necessarily.
It also depends if file fd is a raw file or not (if you are using raw file
systems, you probably already know enough to answer your questions; so
probably not a raw file). If it is, I believe you must wait until the write
completes, but OTOH, you do not need to take the time to find system buffer
space and copy from user space to system space, and you might be able to do
it in a giant "spiral write" as DEC used to call it. Depends on hardware and
the low level driver, I would expect.
And if you are really worried about the data getting onto the disk platter,
consider that many drives have 8 to 16 MByte buffers inside, so even when
the kernel thinks it has written to the hard drive, there may be up to 8
MBytes that might not get there at all if Murphy is on the job.
--
.~. Jean-David Beyer Registered Linux User 85642.
/V\ PGP-Key: 9A2FC99A Registered Machine 241939.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 08:55:00 up 13 days, 23:41, 3 users, load average: 4.14, 4.12, 4.14
.
- Follow-Ups:
- Re: When does `write' return?
- From: Andrew Xue
- Re: When does `write' return?
- References:
- When does `write' return?
- From: Andrew Xue
- When does `write' return?
- Prev by Date: Re: Dial-up connection
- Next by Date: Re: is something wrong in it?
- Previous by thread: When does `write' return?
- Next by thread: Re: When does `write' return?
- Index(es):
Relevant Pages
|