From: Chris Friesen <chris.friesen@genband.com>
To: Ricardo Nabinger Sanchez <rnsanchez@taghos.com.br>
Cc: linux-kernel@vger.kernel.org
Subject: Re: write() on pipe blocking due to in-page fragmentation?
Date: Fri, 23 Sep 2011 16:03:04 -0600 [thread overview]
Message-ID: <4E7D0218.7020502@genband.com> (raw)
In-Reply-To: <20110923164226.211a76dc@darkmoor.lan.box>
On 09/23/2011 01:42 PM, Ricardo Nabinger Sanchez wrote:
> Hello,
>
> The simple program attached allocates a pipe, perform a number of
> writes in it in order to fill the pipe, and then reads that data to
> empty the pipe. The argument is used to determine how much data to
> write per write iteration.
>
> Values that are power of 2 up to PIPE_BUF work without any issues.
> Other values may cause the write() call to block.
> Intuitively, it seems that pages in the pipe are getting fragmented,
> and eventually it will reach the limit of 16 pages and, if the data is
> not consumed, will cause writers to block --- even though the data
> would fit nicely otherwise.
I suggest reading "man 7 pipe" carefully, looking at the pipe capacity
and pipe_buf sections.
I suspect that what you're seeing is that due to the atomicity
requirements the kernel will not spread a single write over multiple
pages, so that when writing 3 bytes at a time each page in the queue has
a byte of free space.
Thus, you succeed in writing up to byte 65520 (out of 65536) but
anything after that blocks. Note that 65536-65520=16.
>
> Is this understanding correct? If so, is it something that should be
> fixed in the Linux kernel?
>
> Or should the application ensure that data written to the pipe will be
> done carefully as to not block a writer?
From the man page:
"Applications should not rely on a particular capacity: an application
should be designed so that a reading process consumes data as soon as it
is available, so that a writing process does not remain blocked."
Chris
--
Chris Friesen
Software Developer
GENBAND
chris.friesen@genband.com
www.genband.com
prev parent reply other threads:[~2011-09-23 22:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-23 19:42 write() on pipe blocking due to in-page fragmentation? Ricardo Nabinger Sanchez
2011-09-23 22:03 ` Chris Friesen [this message]
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=4E7D0218.7020502@genband.com \
--to=chris.friesen@genband.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rnsanchez@taghos.com.br \
/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