linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -mm] mm: percpu: fix incorrect size in pcpu_obj_full_size()
@ 2023-02-10 15:49 Yafang Shao
  2023-02-10 22:05 ` Andrew Morton
  2023-02-10 22:41 ` Roman Gushchin
  0 siblings, 2 replies; 9+ messages in thread
From: Yafang Shao @ 2023-02-10 15:49 UTC (permalink / raw)
  To: akpm
  Cc: linux-mm, Yafang Shao, Dennis Zhou, Tejun Heo, Christoph Lameter,
	Roman Gushchin, Vasily Averin

The extra space which is used to store the obj_cgroup membership is only
valid when kmemcg is enabled. The kmemcg can be disabled via the kernel
parameter "cgroup.memory=nokmem" at runtime.
This helper is also used in non-memcg code, for example the tracepoint,
so we should fix it.

It was found by code review when I was implementing bpf memory usage[1].
No real issue happens in production environment.

[1]. https://lwn.net/Articles/921991/

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Vasily Averin <vvs@openvz.org>
---
 mm/percpu-internal.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h
index 70b1ea2..2a95b1f 100644
--- a/mm/percpu-internal.h
+++ b/mm/percpu-internal.h
@@ -4,6 +4,7 @@
 
 #include <linux/types.h>
 #include <linux/percpu.h>
+#include <linux/memcontrol.h>
 
 /*
  * pcpu_block_md is the metadata block struct.
@@ -125,7 +126,8 @@ static inline size_t pcpu_obj_full_size(size_t size)
 	size_t extra_size = 0;
 
 #ifdef CONFIG_MEMCG_KMEM
-	extra_size += size / PCPU_MIN_ALLOC_SIZE * sizeof(struct obj_cgroup *);
+	if (!mem_cgroup_kmem_disabled())
+		extra_size += size / PCPU_MIN_ALLOC_SIZE * sizeof(struct obj_cgroup *);
 #endif
 
 	return size * num_possible_cpus() + extra_size;
-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-02-14  1:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10 15:49 [PATCH -mm] mm: percpu: fix incorrect size in pcpu_obj_full_size() Yafang Shao
2023-02-10 22:05 ` Andrew Morton
2023-02-10 22:39   ` Dennis Zhou
2023-02-12 14:12     ` Yafang Shao
2023-02-13 20:12       ` Dennis Zhou
2023-02-12 14:05   ` Yafang Shao
2023-02-13 18:50     ` Andrew Morton
2023-02-14  1:57       ` Yafang Shao
2023-02-10 22:41 ` Roman Gushchin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox