From: Paolo Abeni <pabeni@redhat.com>
To: Edward Cree <ecree@solarflare.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
James Morris <jmorris@namei.org>,
Trond Myklebust <trond.myklebust@primarydata.com>,
Alexander Duyck <aduyck@mirantis.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Eric Dumazet <edumazet@google.com>,
Tom Herbert <tom@herbertland.com>,
Hannes Frederic Sowa <hannes@stressinduktion.org>,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH net-next 2/3] udp: implement memory accounting helpers
Date: Thu, 22 Sep 2016 18:14:24 +0200 [thread overview]
Message-ID: <1474560864.4845.78.camel@redhat.com> (raw)
In-Reply-To: <589839b3-5930-2527-b0a3-315be254a175@solarflare.com>
On Thu, 2016-09-22 at 16:21 +0100, Edward Cree wrote:
> On 22/09/16 11:33, Paolo Abeni wrote:
> > Hi Eric,
> >
> > On Wed, 2016-09-21 at 16:31 -0700, Eric Dumazet wrote:
> >> Also does inet_diag properly give the forward_alloc to user ?
> >>
> >> $ ss -mua
> >> State Recv-Q Send-Q Local Address:Port Peer Addres
> >> s:Port
> >> UNCONN 51584 0 *:52460 *:*
> >> skmem:(r51584,rb327680,t0,tb327680,f1664,w0,o0,bl0,d575)
> > Thank you very much for reviewing this!
> >
> > My bad, there is still a race which leads to temporary negative values
> > of fwd. I feel the fix is trivial but it needs some investigation.
> >
> >> Couldn't we instead use an union of an atomic_t and int for
> >> sk->sk_forward_alloc ?
> > That was our first attempt, but we had some issue on mem scheduling; if
> > we use:
> >
> > if (atomic_sub_return(size, &sk->sk_forward_alloc_atomic) < 0) {
> > // fwd alloc
> > }
> >
> > that leads to inescapable, temporary, negative value for
> > sk->sk_forward_alloc.
> >
> > Another option would be:
> >
> > again:
> > fwd = atomic_read(&sk->sk_forward_alloc_atomic);
> > if (fwd > size) {
> > if (atomic_cmpxchg(&sk->sk_forward_alloc_atomic, fwd, fwd - size) != fwd)
> > goto again;
> > } else
> > // fwd alloc
> >
> > which would be bad under high contention.
> Apologies if I'm misunderstanding the problem, but couldn't you have two
> atomic_t fields, 'internal' and 'external' forward_alloc. Then
> if (atomic_sub_return(size, &sk->sk_forward_alloc_internal) < 0) {
> atomic_sub(size, &sk->sk_forward_alloc);
> // fwd alloc
> } else {
> atomic_add(size, &sk->sk_forward_alloc_internal);
> }
> or something like that. Then sk->sk_forward_alloc never sees a negative
> value, and is always >= sk->sk_forward_alloc_internal. Of course places
> that go the other way would have to add to sk->sk_forward_alloc first,
> before adding to sk->sk_forward_alloc_internal, to maintain that invariant.
I think that the idea behind using atomic ops directly on
sk_forward_alloc is to avoid adding other fields to the udp_socket.
If we can add some fields to the udp_sock structure, the schema proposed
in this patch should fit better (modulo bugs ;-), always requiring a
single atomic operation at memory reclaiming time and at memory
allocation time.
Paolo
WARNING: multiple messages have this Message-ID (diff)
From: Paolo Abeni <pabeni-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Edward Cree <ecree-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>
Cc: Eric Dumazet
<eric.dumazet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"David S. Miller" <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>,
James Morris <jmorris-gx6/JNMH7DfYtjvyW6yDsg@public.gmane.org>,
Trond Myklebust
<trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>,
Alexander Duyck <aduyck-nYU0QVwCCFFWk0Htik3J/w@public.gmane.org>,
Daniel Borkmann <daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>,
Eric Dumazet <edumazet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
Tom Herbert <tom-BjP2VixgY4xUbtYUoyoikg@public.gmane.org>,
Hannes Frederic Sowa
<hannes-tFNcAqjVMyqKXQKiL6tip0B+6BGkLq7r@public.gmane.org>,
linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH net-next 2/3] udp: implement memory accounting helpers
Date: Thu, 22 Sep 2016 18:14:24 +0200 [thread overview]
Message-ID: <1474560864.4845.78.camel@redhat.com> (raw)
In-Reply-To: <589839b3-5930-2527-b0a3-315be254a175-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>
On Thu, 2016-09-22 at 16:21 +0100, Edward Cree wrote:
> On 22/09/16 11:33, Paolo Abeni wrote:
> > Hi Eric,
> >
> > On Wed, 2016-09-21 at 16:31 -0700, Eric Dumazet wrote:
> >> Also does inet_diag properly give the forward_alloc to user ?
> >>
> >> $ ss -mua
> >> State Recv-Q Send-Q Local Address:Port Peer Addres
> >> s:Port
> >> UNCONN 51584 0 *:52460 *:*
> >> skmem:(r51584,rb327680,t0,tb327680,f1664,w0,o0,bl0,d575)
> > Thank you very much for reviewing this!
> >
> > My bad, there is still a race which leads to temporary negative values
> > of fwd. I feel the fix is trivial but it needs some investigation.
> >
> >> Couldn't we instead use an union of an atomic_t and int for
> >> sk->sk_forward_alloc ?
> > That was our first attempt, but we had some issue on mem scheduling; if
> > we use:
> >
> > if (atomic_sub_return(size, &sk->sk_forward_alloc_atomic) < 0) {
> > // fwd alloc
> > }
> >
> > that leads to inescapable, temporary, negative value for
> > sk->sk_forward_alloc.
> >
> > Another option would be:
> >
> > again:
> > fwd = atomic_read(&sk->sk_forward_alloc_atomic);
> > if (fwd > size) {
> > if (atomic_cmpxchg(&sk->sk_forward_alloc_atomic, fwd, fwd - size) != fwd)
> > goto again;
> > } else
> > // fwd alloc
> >
> > which would be bad under high contention.
> Apologies if I'm misunderstanding the problem, but couldn't you have two
> atomic_t fields, 'internal' and 'external' forward_alloc. Then
> if (atomic_sub_return(size, &sk->sk_forward_alloc_internal) < 0) {
> atomic_sub(size, &sk->sk_forward_alloc);
> // fwd alloc
> } else {
> atomic_add(size, &sk->sk_forward_alloc_internal);
> }
> or something like that. Then sk->sk_forward_alloc never sees a negative
> value, and is always >= sk->sk_forward_alloc_internal. Of course places
> that go the other way would have to add to sk->sk_forward_alloc first,
> before adding to sk->sk_forward_alloc_internal, to maintain that invariant.
I think that the idea behind using atomic ops directly on
sk_forward_alloc is to avoid adding other fields to the udp_socket.
If we can add some fields to the udp_sock structure, the schema proposed
in this patch should fit better (modulo bugs ;-), always requiring a
single atomic operation at memory reclaiming time and at memory
allocation time.
Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-09-22 16:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-21 17:23 [PATCH net-next 0/3] udp: refactor memory accounting Paolo Abeni
2016-09-21 17:23 ` Paolo Abeni
2016-09-21 17:23 ` [PATCH net-next 1/3] net/socket: factor out helpers for memory and queue manipulation Paolo Abeni
2016-09-21 17:23 ` [PATCH net-next 2/3] udp: implement memory accounting helpers Paolo Abeni
2016-09-21 17:23 ` Paolo Abeni
2016-09-21 23:31 ` Eric Dumazet
2016-09-22 10:33 ` Paolo Abeni
2016-09-22 15:21 ` Edward Cree
2016-09-22 16:14 ` Paolo Abeni [this message]
2016-09-22 16:14 ` Paolo Abeni
2016-09-22 16:30 ` Eric Dumazet
2016-09-22 20:27 ` Paolo Abeni
2016-09-22 20:34 ` Eric Dumazet
2016-09-22 20:37 ` Eric Dumazet
2016-09-23 9:56 ` Paolo Abeni
2016-09-21 17:23 ` [PATCH net-next 3/3] udp: use it's own memory accounting schema Paolo Abeni
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=1474560864.4845.78.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=aduyck@mirantis.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=ecree@solarflare.com \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=hannes@stressinduktion.org \
--cc=jmorris@namei.org \
--cc=linux-nfs@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tom@herbertland.com \
--cc=trond.myklebust@primarydata.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.