All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Max Kellermann <max@duempel.org>
Cc: linux-kernel@vger.kernel.org, mk@cm4all.com
Subject: Re: [PATCH] pipe: don't block after data has been written
Date: Thu, 05 Nov 2009 17:27:48 +0100	[thread overview]
Message-ID: <4AF2FD04.4030306@gmail.com> (raw)
In-Reply-To: <20091105153147.27473.19570.stgit@woodpecker.roonstrasse.net>

Max Kellermann a écrit :
> According to the select() / poll() documentation, a write operation on
> a file descriptor which is "ready for writing" must not block.  Linux
> violates this rule: if you pass a very large buffer to write(), the
> system call will not return until everything is written, or an error
> occurs.
> 
> This patch adds a simple check: if at least one byte has already been
> written, break from the loop, instead of calling pipe_wait().
> 
> Signed-off-by: Max Kellermann <max@duempel.org>
> ---
> 
>  fs/pipe.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/pipe.c b/fs/pipe.c
> index ae17d02..9d84f0b 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -582,7 +582,7 @@ redo2:
>  		}
>  		if (bufs < PIPE_BUFFERS)
>  			continue;
> -		if (filp->f_flags & O_NONBLOCK) {
> +		if (filp->f_flags & O_NONBLOCK || ret > 0) {
>  			if (!ret)
>  				ret = -EAGAIN;
>  			break;
> 

Then select()/poll() documentation is wrong, please correct documentation ?

http://www.opengroup.org/onlinepubs/000095399/functions/write.html

	ssize_t write(int fildes, const void *buf, size_t nbyte);

	If the O_NONBLOCK flag is clear, a write request may cause the thread to block,
	but on normal completion it shall return nbyte.

Every Unix I know behaves the same when writing to a pipe.


Your patch breaks many programs, that dont use poll()/select()

char result[1000000];
main()
{
	computethings();
	write(1, buffer, 1000000);
}


$ ./program | more

Please learn how useful O_NDELAY can be in a poll()/select() environment.

Thanks

  parent reply	other threads:[~2009-11-05 16:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-05 15:31 [PATCH] pipe: don't block after data has been written Max Kellermann
2009-11-05 16:20 ` Américo Wang
2009-11-05 16:25   ` Max Kellermann
2009-11-05 16:27 ` Eric Dumazet [this message]
2009-11-05 16:36   ` Max Kellermann
2009-11-05 16:37     ` Eric Dumazet
2009-11-05 17:13       ` Zan Lynx
2009-11-05 18:32         ` Alan Cox

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=4AF2FD04.4030306@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=max@duempel.org \
    --cc=mk@cm4all.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.