From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org, yannick@koehler.name,
xiyou.wangcong@gmail.com, davem@davemloft.net
Subject: Re: [PATCH RFC] unix: account skb memory to receiving socket's sk_rmem_alloc on sending
Date: Mon, 8 Apr 2013 00:47:20 +0200 [thread overview]
Message-ID: <20130407224719.GA9182@order.stressinduktion.org> (raw)
In-Reply-To: <1364313218.1716.37.camel@edumazet-glaptop>
I am still unsure if I should just drop this patch from my todo
list. Eric, may I ask you for additional input again? I try to
specifically answer your question now with code samples. If you do think
it is not worth the effort I will finally drop the patch from my queue.
Thanks a lot!
On Tue, Mar 26, 2013 at 08:53:38AM -0700, Eric Dumazet wrote:
> This opens the possibility of a sender to flood a receiver, instead of
> being blocked by its own sndbuf.
In unix_dgram_sendmsg there are two points where the sending process
could be prevented from delivery of the unix dgram msg:
a) The first one is at sock_alloc_send_pskb and checks if the sk_sndbuf
is smaller than the maximum buffer size. I didn't change anything here,
so it only blocks if sndbuf filled up.
b) The second one is where we check if the receiving sockets has less
than sk_max_ack_backlog of outstanding datagrams. This was checked by
unix_recvq_full. I changed the code that it does now check the status of
the other socket's receive buffer instead of the number of outstanding
datagrams in the receiver's queue. If the rcvbuf is full, it stops the
delivery of the message to the receiver (unchanged blocking/o_nonblock
behaviour):
| @@ -1559,7 +1601,7 @@ restart:
| goto out_unlock;
| }
|
| - if (unix_peer(other) != sk && unix_recvq_full(other)) {
| + if (unix_rmem_full(other, skb)) {
| if (!timeo) {
| err = -EAGAIN;
| goto out_unlock;
|
This is unix_recvq_full:
| +static inline bool unix_rmem_full(struct sock const *sk,
| + struct sk_buff const *skb)
| +{
| + return sk_rmem_alloc_get(sk) + skb->truesize > sk->sk_rcvbuf;
| +}
| +
These checks ensure that a sending socket can not flood a receiver with
messages but instead has to back down.
The maximum rcvbuf size is taken from
/proc/sys/net/core/rmem_{default,max}, so we already have a safe default
setting (we could actually add seperate net/unix/rmem_{default,max} knobs).
This patch would help to prevent that a server socket in a
request/response kind of protocol could be stopped to answer to furhter
requests because its send buffer has filled up because other clients
did not read their messages yet. Instead it could handle this situation
for each client properly.
I also implemented the necessary changes for ->poll().
I tried to come up with a list what could change for user-space
applications but actually found this one only:
a) the SIOCOUTQ ioctl will report a different value: it won't report the
number of not yet received bytes by the other socket but the number of
not yet delivered bytes. I think this is rather harmless As the memory
overhead is accounted too and an application which does rely on this
feature would also have problems as soon as the kernel internal data
structures grow.
I hope I did not forget an important aspect of this change.
Thanks again,
Hannes
prev parent reply other threads:[~2013-04-07 22:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-04 23:14 [PATCH RFC] unix: account skb memory to receiving socket's sk_rmem_alloc on sending Hannes Frederic Sowa
2013-03-09 21:43 ` Hannes Frederic Sowa
2013-03-10 4:31 ` Eric Dumazet
2013-03-10 4:40 ` Hannes Frederic Sowa
2013-03-11 19:37 ` Hannes Frederic Sowa
2013-03-26 0:17 ` Hannes Frederic Sowa
2013-03-26 15:53 ` Eric Dumazet
2013-03-26 16:42 ` Hannes Frederic Sowa
2013-04-07 22:47 ` Hannes Frederic Sowa [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=20130407224719.GA9182@order.stressinduktion.org \
--to=hannes@stressinduktion.org \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
--cc=yannick@koehler.name \
/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;
as well as URLs for NNTP newsgroup(s).