Thread (32 messages) 32 messages, 9 authors, 2022-05-30

Re: [PATCH memcg v3] net: set proper memcg for net_init hooks allocations

From: Vasily Averin <hidden>
Date: 2022-04-26 05:58:17
Also in: cgroups, lkml

On 4/26/22 05:50, Roman Gushchin wrote:
On Mon, Apr 25, 2022 at 01:56:02PM +0300, Vasily Averin wrote:
quoted
+
+static inline struct mem_cgroup *get_net_memcg(void *p)
+{
+	struct mem_cgroup *memcg;
+
+	memcg = get_mem_cgroup_from_kmem(p);
+
+	if (!memcg)
+		memcg = root_mem_cgroup;
+
+	return memcg;
+}
I'm not a fan of this helper: it has nothing to do with the networking,
actually it's a wrapper of get_mem_cgroup_from_kmem() replacing NULL
with root_mem_cgroup.

Overall the handling of root_mem_cgroup is very messy, I don't blame
this patch. But I wonder if it's better to simple move this code
to the call site without introducing a new function?
Unfortunately root_mem_cgroup is defined under CONFIG_MEMCG,
so we cannot use it outside without ifdefs.
Alternatively, you can introduce something like:
struct mem_cgroup *mem_cgroup_or_root(struct mem_cgroup *memcg)
{
	return memcg ? memcg : root_mem_cgroup;
}
Thank you for the hint, this looks much better.
	Vasily Averin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help