[Devel] [PATCH vz9 16/16] mm/mecontrol: add memcg_[un]charge_kmem() API
Nikita Yushchenko
nikita.yushchenko at virtuozzo.com
Wed Sep 29 10:00:17 MSK 2021
From: Andrey Ryabinin <aryabinin at virtuozzo.com>
This API will be used to charge kmem directly when using __GFP_ACCOUNT
isn't possible.
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
(cherry-picked from vz8 commit c3432ecc2f0a ("mm/mecontrol:
add memcg_[un]charge_kmem() API"))
Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
include/linux/memcontrol.h | 11 +++++++++++
mm/memcontrol.c | 20 ++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index a4e0e9830d29..1311eec888b1 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -911,6 +911,9 @@ static inline bool mem_cgroup_online(struct mem_cgroup *memcg)
* For memory reclaim.
*/
bool mem_cgroup_dcache_is_low(struct mem_cgroup *memcg, int vfs_cache_min_ratio);
+int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, unsigned long nr_pages);
+void memcg_uncharge_kmem(struct mem_cgroup *memcg, unsigned long nr_pages);
+
bool mem_cgroup_cleancache_disabled(struct page *page);
int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm);
@@ -1395,6 +1398,14 @@ static inline bool mem_cgroup_dcache_is_low(struct mem_cgroup *memcg,
return false;
}
+static inline int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
+ unsigned long nr_pages)
+{
+ return 0;
+}
+static inline void memcg_uncharge_kmem(struct mem_cgroup *memcg, unsigned long nr_pages)
+{ }
+
static inline unsigned long mm_overdraft(struct mm_struct *mm)
{
return 0;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 1fc6a0c78c4e..41c3d5f25fba 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3378,6 +3378,26 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size)
refill_obj_stock(objcg, size, true);
}
+int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
+ unsigned long nr_pages)
+{
+ int ret = 0;
+
+ ret = try_charge(memcg, gfp, nr_pages);
+ if (!ret)
+ page_counter_charge(&memcg->kmem, nr_pages);
+
+ return ret;
+}
+
+void memcg_uncharge_kmem(struct mem_cgroup *memcg, unsigned long nr_pages)
+{
+ page_counter_uncharge(&memcg->kmem, nr_pages);
+ page_counter_uncharge(&memcg->memory, nr_pages);
+ if (!cgroup_memory_noswap)
+ page_counter_uncharge(&memcg->memsw, nr_pages);
+}
+
#endif /* CONFIG_MEMCG_KMEM */
/*
--
2.30.2
More information about the Devel
mailing list