mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stanislav Meduna <stano@trillian.eunet.sk>
To: linux-kernel@vger.kernel.org
Cc: pcg@goof.com, alan@lxorguk.ukuu.org.uk
Subject: Re: select() bug
Date: Sun, 5 Nov 2000 17:14:10 +0100	[thread overview]
Message-ID: <20001105171410.A2707@trillian.eunet.sk> (raw)

> > > - If I'm correct that pipes have a 4K kernel buffer, then writing 1 
> > > byte shouldn't cause this situation, as the buffer is well more than 
> > > half empty. Is this still a bug? 
> > 
> > The pipe code uses totally full/empty. Im not sure why that was chosen 
> 
> Just a quick guess: maybe because of the POSIX atomicity guarantees (if 
> select returned, write might have to block which is not what is expected), 
> and maybe this limitation was used not only on write but on read (Although 
> it's not necessary on the read side, AFAIK). 

FWIW: I tried to do some experiments (I was hit by the context
switch 'explosion': the writer writes one byte and then
cannot write another one until the reader wakes up and reads
the single one - for my application this was very bad).

Unfortunately my experiments made the most-used uses slower
and I don't know the kernel internals enough to analyse it :-(

I am repeating here my post from 14. 7. (this was with -test4,
I don't know whether there were any significant changes since then)
under the subject "pipe concurrent r/w performance". Last time
I did not get any replies.

- snip -

I am (again) playing with pipe.c trying to enlarge the
pipe buffer, so the pipe can select for write even when
non-empty (but with more than PIPE_BUF free), aiming
for reducing context switches when two applications
signal something via a pipe without waiting for
an answer. The functionality is (hopefully) OK and
I am testing the performance.

I have written two similar test programs. The
writer side selects the pipe and then writes a byte.
The reader side does either 1) blocking read of one
byte, or 2) selects the pipe for reading and then
reads a byte.

To my surprise the case 1) is slower than the original
version by 20% and there is actually more context switches.
Case 2) is at least 30% faster than the original version
and the number of context switches is dramatically reduced.

The difference probably is, that the reader is faster
than the writer and in the case 1) it nearly always
blocks in the pipe_wait call inside pipe_read.
It seems like as soon as the writer writes something
in the pipe, the reader immediately gets the CPU
instead of allowing the writer to continue.

In the case 2) it blocks in poll_wait inside pipe_poll.

I don't quite understand all the semantics behind
synchronisation primitives, but it seems like the
current code is not optimal for the concurrent
presence of reader and writer in pipe_read/pipe_write.
The code in pipe_poll excluded such possibility.
Could someone understanding these things better
take a look?

My patch and the test programs are available at
http://www.penguin.cz/~stano/code/kernelpipe.tar.gz
The patch is against 2.4.0-test4, my machine is
a SMP one (maybe the situation differs on UP).

- snip -

Regards
-- 
				Stano



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

             reply	other threads:[~2000-11-05 16:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-05 16:14 Stanislav Meduna [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-11-02 22:11 Paul Marquis
2000-11-02 22:27 ` Alan Cox
2000-11-02 22:42   ` Richard B. Johnson
2000-11-02 22:58     ` Paul Marquis
2000-11-03  0:53       ` Richard B. Johnson
2000-11-03  5:00         ` Paul Marquis
2000-11-03 13:05           ` Richard B. Johnson
2000-11-02 22:53   ` Paul Marquis
2000-11-02 22:58     ` Alan Cox
2000-11-02 23:08       ` Paul Marquis
2000-11-02 23:20         ` Alan Cox
2000-11-02 23:44           ` Paul Marquis
2000-11-02 23:46             ` David S. Miller
2000-11-02 23:52               ` David S. Miller
2000-11-03  0:05                 ` David S. Miller
2000-11-03  0:38                   ` H. Peter Anvin
2000-11-03  0:13                 ` H. Peter Anvin
2000-11-03  0:04               ` H. Peter Anvin
2000-11-02 23:53             ` H. Peter Anvin
2000-11-03  0:01               ` Alan Cox
2000-11-02 23:55             ` Alan Cox
2000-11-03  5:52               ` dean gaudet
2000-11-03  7:05               ` Marc Lehmann

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=20001105171410.A2707@trillian.eunet.sk \
    --to=stano@trillian.eunet.sk \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pcg@goof.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

all inboxes | Powered by JetHome®