From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roman Gushchin Subject: Re: [PATCH memcg v4] net: set proper memcg for net_init hooks allocations Date: Wed, 27 Apr 2022 15:36:03 -0700 Message-ID: References: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> <20220427122232.GA9823@blackbody.suse.cz> <6b18f82d-1950-b38e-f3f5-94f6c23f0edb@openvz.org> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1651098970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YptwFdA8KWuDmjvuchBNuhhYcNiTn83Pm656usmn0sI=; b=xurUMpP3QLqUoZxw1BdoFkYM+0wVMIHfRfnM/Miz+pyrSnam+pUfOqzeu4w7WEtz+vscdO t8sZhvk29FJHTf9oMznLUlDzxrKSBESrMWIxTbOsTmuGq6MX7UWPvgVN2r6Q4pckJigj3y prcDwZAQTSSNCJlRUCceBDukatZZNz4= Content-Disposition: inline In-Reply-To: <6b18f82d-1950-b38e-f3f5-94f6c23f0edb@openvz.org> List-ID: Content-Type: text/plain; charset="iso-8859-1" To: Vasily Averin Cc: Shakeel Butt , Michal =?iso-8859-1?Q?Koutn=FD?= , Vlastimil Babka , kernel@openvz.org, Florian Westphal , LKML , Michal Hocko , Cgroups , netdev , "David S. Miller" , Jakub Kicinski , Paolo Abeni On Thu, Apr 28, 2022 at 01:16:53AM +0300, Vasily Averin wrote: > On 4/27/22 18:06, Shakeel Butt wrote: > > On Wed, Apr 27, 2022 at 5:22 AM Michal Koutn=FD wrot= e: > >> > >> On Tue, Apr 26, 2022 at 10:23:32PM -0700, Shakeel Butt wrote: > >>> [...] > >>>> > >>>> +static inline struct mem_cgroup *get_mem_cgroup_from_obj(void *p) > >>>> +{ > >>>> + struct mem_cgroup *memcg; > >>>> + > >>> > >>> Do we need memcg_kmem_enabled() check here or maybe > >>> mem_cgroup_from_obj() should be doing memcg_kmem_enabled() instead of > >>> mem_cgroup_disabled() as we can have "cgroup.memory=3Dnokmem" boot > >>> param. >=20 > Shakeel, unfortunately I'm not ready to answer this question right now. > I even did not noticed that memcg_kmem_enabled() and mem_cgroup_disabled() > have a different nature. > If you have no objections I'm going to keep this place as is and investig= ate > this question later.=20 >=20 > >> I reckon such a guard is on the charge side and readers should treat > >> NULL and root_mem_group equally. Or is there a case when these two are > >> different? > >> > >> (I can see it's different semantics when stored in current->active_mem= cg > >> (and active_memcg() getter) but for such "outer" callers like here it > >> seems equal.) >=20 > Dear Michal, > I may have misunderstood your point of view, so let me explain my vision > in more detail. > I do not think that NULL and root_mem_cgroup are equal here: > - we have enabled cgroups and well-defined root_mem_cgroup, > - this function is called from inside memcg-limited container, > - we tried to get memcg from net, but without success, > and as result got NULL from mem_cgroup_from_obj() > (frankly speaking I do not think this situation is really possible) > If we keep memcg =3D NULL, then current's memcg will not be masked and > net_init's allocations will be accounted to current's memcg.=20 > So we need to set active_memcg to root_mem_cgroup, it helps to avoid > incorrect accounting. It's way out of scope of this patch, but I think we need to stop using NULL as root_mem_cgroup/system scope indicator. Remaining use cases will be like end of cgroup iteration, active memcg not set, parent of the root memcg, etc. We can point root_mem_cgroup at a statically allocated structure on both CONFIG_MEMCG and !CONFIG_MEMCG. Does it sound reasonable or I'm missing some important points? Thanks!