diff mbox series

[RFC,bpf-next,01/10] mm, memcg: Add a new helper memcg_should_recharge()

Message ID 20220619155032.32515-2-laoar.shao@gmail.com (mailing list archive)
State New
Headers show
Series bpf, mm: Recharge pages when reuse bpf map | expand

Commit Message

Yafang Shao June 19, 2022, 3:50 p.m. UTC
Currently we only recharge pages from an offline memcg or reparented
memcg. In the future we may explicitly introduce a need_recharge
state for the memcg which should be recharged.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 include/linux/memcontrol.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 9ecead1042b9..cf074156c6ac 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1755,6 +1755,18 @@  static inline void count_objcg_event(struct obj_cgroup *objcg,
 	rcu_read_unlock();
 }
 
+static inline bool memcg_need_recharge(struct mem_cgroup *memcg)
+{
+	if (!memcg || memcg == root_mem_cgroup)
+		return false;
+	/*
+	 * Currently we only recharge pages from an offline memcg,
+	 * in the future we may explicitly introduce a need_recharge
+	 * state for the memcg which should be recharged.
+	 */
+	return memcg->kmemcg_id == memcg->id.id ? false : true;
+}
+
 #else
 static inline bool mem_cgroup_kmem_disabled(void)
 {
@@ -1806,6 +1818,11 @@  static inline void count_objcg_event(struct obj_cgroup *objcg,
 {
 }
 
+static inline bool memcg_need_recharge(struct mem_cgroup *memcg)
+{
+	return false;
+}
+
 #endif /* CONFIG_MEMCG_KMEM */
 
 #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)