From: Brandon Black <blblack@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: behavior of recvmmsg() on blocking sockets
Date: Wed, 24 Mar 2010 11:15:56 -0500 [thread overview]
Message-ID: <84621a61003240915p2a4ce6bbjd0c6bfb02ab05ba8@mail.gmail.com> (raw)
[Not on the list, please CC responses]
Currently, my application code uses blocking UDP sockets and is
basically structured like this:
while(1) {
recvmsg(fd, ...);
// do some work on the packet
sendmsg(fd, ...);
}
It uses a thread-per-socket model, and the "do some work" code is very
fast, and so this turns out to be more efficient than non-blocking
techniques for my use case. Today I started playing with 2.6.33's new
recvmmsg(), hoping to convert my code like so (still on blocking
sockets):
while(1) {
recvmmsg(fd, ...);
// do some work on up to N packets
// loop over sendmsg() foreach packet to be sent
// (or sendmmsg() if/when that interface becomes available)
}
The catch I ran into is that on a blocking socket, recvmmsg() will
block until *all* vlen packets have been received. The behavior I'd
prefer for my use case would be for it to only block until at least
one packet is available, not until all are available. Or in code
terms, the first internal call to recvmsg should use the supplied
flags, and the rest of the recvmsg calls should use flags &
MSG_DONTWAIT. It's not clear to me which is the better default
behavior, but I feel like at the very least there should be a flag
that can switch behavior between the two possible interpretations of
"blocking".
Obviously, I can also work around this at the user level by simply
switching to a non-blocking socket and using select/poll before
recvmmsg, but then under any conditions where only 1 packet is
available (probably fairly common) I'm issuing two syscalls per packet
when only one should be necessary (and only one is necessary when
using recvmsg()). This seems inefficient and antithetical to one of
the design goals of recvmmsg (cut down the syscalls:packets ratio).
Thoughts on this?
Thanks,
-- Brandon
next reply other threads:[~2010-03-24 16:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-24 16:15 Brandon Black [this message]
2010-03-24 17:41 ` Chris Friesen
2010-03-24 18:28 ` Brandon Black
2010-03-24 18:34 ` drepper
2010-03-24 23:35 ` Brandon Black
2010-03-26 12:00 ` Ulrich Drepper
2010-03-26 14:20 ` Eric Dumazet
2010-03-24 19:36 ` Chris Friesen
2010-03-24 19:55 ` Brandon Black
2010-03-27 13:19 ` Brandon Black
2010-03-27 14:26 ` Arnaldo Carvalho de Melo
2010-03-29 16:18 ` Chris Friesen
2010-03-29 17:24 ` Brandon Black
2010-03-29 17:48 ` Chris Friesen
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=84621a61003240915p2a4ce6bbjd0c6bfb02ab05ba8@mail.gmail.com \
--to=blblack@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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®