From: Roman Gushchin <guro@fb.com>
To: David Miller <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<kernel-team@fb.com>, <edumazet@google.com>, <hannes@cmpxchg.org>,
<tj@kernel.org>
Subject: Re: [PATCH net] net: memcontrol: charge allocated memory after mem_cgroup_sk_alloc()
Date: Wed, 31 Jan 2018 21:54:08 +0000 [thread overview]
Message-ID: <20180131215401.GA8956@castle> (raw)
In-Reply-To: <20180125.120302.1117695034222616751.davem@davemloft.net>
On Thu, Jan 25, 2018 at 12:03:02PM -0500, David Miller wrote:
> From: Roman Gushchin <guro@fb.com>
> Date: Thu, 25 Jan 2018 00:19:11 +0000
>
> > @@ -476,6 +477,10 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
> > spin_unlock_bh(&queue->fastopenq.lock);
> > }
> > mem_cgroup_sk_alloc(newsk);
> > + amt = sk_memory_allocated(newsk);
> > + if (amt && newsk->sk_memcg)
> > + mem_cgroup_charge_skmem(newsk->sk_memcg, amt);
> > +
>
> This looks confusing to me.
>
> sk_memory_allocated() is the total amount of memory used by all
> sockets for a particular "struct proto", not just for that specific
> socket.
>
> Maybe I don't understand how this socket memcg stuff works, but it
> seems like you should be looking instead at how much memory is
> allocated to this specific socket.
So, the patch below takes the per-socket charge into account,
and it _almost_ works: css leak is weaker by a couple orders
of magnitude, but still exists. I believe, the problem is
that we need additional synchronization for sk_memcg and
sk_forward_alloc fields; and I'm really out of ideas how
to do it without heavy artillery like introducing a new
field for unaccounted memcg charge. As I can see, we
check the sk_memcg field without socket lock; and we
do set it from a concurrent context.
Most likely, I do miss something...
So I really start thinking that reverting 9f1c2674b328
("net: memcontrol: defer call to mem_cgroup_sk_alloc()")
and fixing the original issue differently might be easier
and a proper way to go. Does it makes sense?
Thanks!
--
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 4ca46dc08e63..287de1501a30 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -476,6 +476,12 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
spin_unlock_bh(&queue->fastopenq.lock);
}
mem_cgroup_sk_alloc(newsk);
+ if (mem_cgroup_sockets_enabled && newsk->sk_memcg) {
+ int amt = sk_mem_pages(newsk->sk_forward_alloc);
+ if (amt > 0)
+ mem_cgroup_charge_skmem(newsk->sk_memcg, amt);
+ }
+
out:
release_sock(sk);
if (req)
next prev parent reply other threads:[~2018-01-31 21:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-25 0:19 [PATCH net] net: memcontrol: charge allocated memory after mem_cgroup_sk_alloc() Roman Gushchin
2018-01-25 17:03 ` David Miller
2018-01-25 17:15 ` Roman Gushchin
2018-01-31 21:54 ` Roman Gushchin [this message]
2018-02-01 15:16 ` David Miller
2018-02-01 20:22 ` Roman Gushchin
2018-02-01 21:17 ` Eric Dumazet
2018-02-01 22:55 ` Roman Gushchin
2018-02-01 23:27 ` Eric Dumazet
2018-02-01 23:42 ` Roman Gushchin
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=20180131215401.GA8956@castle \
--to=guro@fb.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tj@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 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.