From: Marcelo Tosatti <marcelo.tosatti@cyclades.com>
To: Jeff Moyer <jmoyer@redhat.com>
Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, sct@redhat.com
Subject: Re: [patch rfc] towards supporting O_NONBLOCK on regular files
Date: Tue, 5 Oct 2004 08:27:52 -0300 [thread overview]
Message-ID: <20041005112752.GA21094@logos.cnet> (raw)
In-Reply-To: <16733.50382.569265.183099@segfault.boston.redhat.com>
On Fri, Oct 01, 2004 at 04:57:50PM -0400, Jeff Moyer wrote:
> This patch makes an attempt at supporting the O_NONBLOCK flag for regular
> files. It's pretty straight-forward. One limitation is that we still call
> into the readahead code, which I believe can block. However, if we don't
> do this, then an application which only uses non-blocking reads may never
> get it's data.
>
> Comments welcome.
Hi Jeff,
Curiosity: Is this defined in any UNIX standard?
Adv. Programming in the UNIX environment says:
12.2 Nonblocking I/O
"Nonblocking I/O lets us issue an I/O operation, such as open, read,
or write and not have it block forever. If the operation cannot be
completed, return is made immediately with an error noting that
the operation would have blocked."
He is talking about read's on descriptors (pipe's, devices, etc) which
block in case of no data present, not about filesystem IO.
But here we create our own semantics of O_NONBLOCK on read() of
fs IO. As you say page_cache_readahead can block for one
trying to allocate pages, possibly while submitting IO too.
The patch is cool - might be nice to check if SuS or someone else
specificies behaviour and try to match if so?
>
> -Jeff
>
> --- linux-2.6.8/mm/filemap.c.orig 2004-09-30 16:33:46.881129560 -0400
> +++ linux-2.6.8/mm/filemap.c 2004-09-30 16:34:12.109294296 -0400
> @@ -720,7 +720,7 @@ void do_generic_mapping_read(struct addr
> unsigned long index, end_index, offset;
> loff_t isize;
> struct page *cached_page;
> - int error;
> + int error, nonblock = filp->f_flags & O_NONBLOCK;
> struct file_ra_state ra = *_ra;
>
> cached_page = NULL;
> @@ -755,10 +755,20 @@ find_page:
> page = find_get_page(mapping, index);
> if (unlikely(page == NULL)) {
> handle_ra_miss(mapping, &ra, index);
> + if (nonblock) {
> + desc->error = -EWOULDBLOCK;
> + break;
> + }
> goto no_cached_page;
> }
> - if (!PageUptodate(page))
> + if (!PageUptodate(page)) {
> + if (nonblock) {
> + page_cache_release(page);
> + desc->error = -EWOULDBLOCK;
> + break;
> + }
> goto page_not_up_to_date;
> + }
> page_ok:
>
> /* If users can be writing to this page using arbitrary
> @@ -1004,7 +1014,7 @@ __generic_file_aio_read(struct kiocb *io
> desc.error = 0;
> do_generic_file_read(filp,ppos,&desc,file_read_actor);
> retval += desc.written;
> - if (!retval) {
> + if (!retval || desc.error) {
> retval = desc.error;
> break;
> }
next prev parent reply other threads:[~2004-10-05 13:06 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-01 20:57 [patch rfc] towards supporting O_NONBLOCK on regular files Jeff Moyer
2004-10-03 19:48 ` Pavel Machek
2004-10-13 14:28 ` Jeff Moyer
2004-10-14 17:39 ` Pavel Machek
2004-10-05 11:27 ` Marcelo Tosatti [this message]
2004-10-06 13:13 ` Jeff Moyer
2004-10-06 12:01 ` Marcelo Tosatti
2004-10-07 3:31 ` Stephen C. Tweedie
2004-10-07 10:12 ` Marcelo Tosatti
2004-10-07 12:30 ` Arjan van de Ven
2004-10-11 18:32 ` Stephen C. Tweedie
2004-10-11 18:58 ` Jeff Moyer
2004-10-11 21:49 ` Stephen C. Tweedie
2004-10-13 14:26 ` Jeff Moyer
2004-10-15 15:44 ` Jeff Moyer
2004-10-15 16:19 ` Stephen C. Tweedie
2004-10-17 7:59 ` Alexandre Oliva
2004-10-17 11:20 ` Ingo Molnar
2004-10-17 19:38 ` Alexandre Oliva
2004-10-18 16:51 ` Jeff Moyer
2004-10-19 6:04 ` Alexandre Oliva
2004-10-21 20:14 ` James Antill
2004-10-05 15:35 ` Rik van Riel
-- strict thread matches above, loose matches on Subject: below --
2004-10-05 13:07 Dan Kegel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041005112752.GA21094@logos.cnet \
--to=marcelo.tosatti@cyclades.com \
--cc=jmoyer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=sct@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox