lkml.org 
[lkml]   [2004]   [Oct]   [6]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateWed, 6 Oct 2004 09:01:58 -0300
FromMarcelo Tosatti <>
SubjectRe: [patch rfc] towards supporting O_NONBLOCK on regular files
On Wed, Oct 06, 2004 at 09:13:38AM -0400, Jeff Moyer wrote:
> ==> Regarding Re: [patch rfc] towards supporting O_NONBLOCK on regular files; Marcelo Tosatti <marcelo.tosatti@cyclades.com> adds:

Hi Jeff!

> Hi, Marcelo,
> 
> The text below was taken from the following standard:
> 
> IEEE Std 1003.1, 2004 Edition
> The Open Group Technical Standard
> Base Sepcifications, Issue 6
> Includes IEEE Std 1003.1-2001, IEEE Std 1003.1-2001/Cor 1-2002
> 
> 
> open()
> 
> O_NONBLOCK When opening a FIFO with O_RDONLY or O_WRONLY set:
>  o If O_NONBLOCK is set, an open( ) for reading-only shall return without
>    delay. An open( ) for writing-only shall return an error if no process
>    currently has the file open for reading.
>  o If O_NONBLOCK is clear, an open( ) for reading-only shall block the
>    calling thread until a thread opens the file for writing. An open( ) for
>    writing-only shall block the calling thread until a thread opens the file
>    for reading.
> 
> When opening a block special or character special file that supports non-
> blocking opens:
>  o If O_NONBLOCK is set, the open( ) function shall return without blocking
>    for the device to be ready or available. Subsequent behavior of the device
>    is device-specific.
>  o If O_NONBLOCK is clear, the open( ) function shall block the calling
>    thread until the device is ready or available before returning.
> 
>  Otherwise, the behavior of O_NONBLOCK is unspecified.
> 
> read()
> 
> When attempting to read a file (other than a pipe or FIFO) that supports
> non-blocking reads and has no data currently available:
>  o If O_NONBLOCK is set, read( ) shall return -1 and set errno to [EAGAIN].

This implies read(O_NONBLOCK) should never block.

Maybe your code should pass down __GFP_FAIL in the gfp_mask 
to the page_cache_alloc() to avoid blocking reclaiming pages,
and possibly pass info down to the block layer 
"if this is going to block, fail".

We have a bdi_congested() check before doing the readahead (dont RA
if the queue is full). Check if that really works - I'm afraid
it can block because the check is not done at each page 
submitted, but rather at each readahead operation (which 
can be several pages large).

>  o If O_NONBLOCK is clear, read( ) shall block the calling thread until
>    some data becomes available.
>  o The use of the O_NONBLOCK flag has no effect if there is some data
>    available.
> 
> write()
> 
> When attempting to write to a file descriptor (other than a pipe or FIFO)
> that supports non- blocking writes and cannot accept the data immediately:
>   o If the O_NONBLOCK flag is clear, write( ) shall block the calling
>     thread until the data can be accepted.
>   o If the O_NONBLOCK flag is set, write( ) shall not block the thread. If
>     some data can be written without blocking the thread, write( ) shall
>     write what it can and return the number of bytes written. Otherwise, it
>     shall return -1 and set errno to [EAGAIN].
> 
> 
> Thanks!
> 
> Jeff
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:06    [W:0.801 / U:0.280 seconds]
©2003-2008 Jasper Spaans