From: Liu Shixin <liushixin2@huawei.com> hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IAFWQH -------------------------------- After bound the zram with a memcg which has a dpool as memory provider. The memory usage of zram should prefer to allocate from dpool. zspool is allocated by alloc_page() before, replace it with zs_alloc_page() to achieve the effect. zram->table is allocated by vzalloc(), and vzalloc() is calling alloc_pages_node() to allocate memory. Add vzalloc_with_memcg() and __vmalloc_alloc_pages() to replace vzalloc() and alloc_pages_node() respectively to achieve the effect. Signed-off-by: Liu Shixin <liushixin2@huawei.com> --- mm/dynamic_pool.c | 1 + mm/zsmalloc.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mm/dynamic_pool.c b/mm/dynamic_pool.c index 4dc9e80c2cb7..0924105671ec 100644 --- a/mm/dynamic_pool.c +++ b/mm/dynamic_pool.c @@ -799,6 +799,7 @@ struct page *dynamic_pool_alloc_page(struct mem_cgroup *memcg, gfp_t gfp, return page; } +EXPORT_SYMBOL_GPL(dynamic_pool_alloc_page); void dynamic_pool_free_page(struct page *page) { diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 907a51cc28b1..1fb34d1dd563 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -64,6 +64,7 @@ #include <linux/fs.h> #include <linux/local_lock.h> #include <linux/memcontrol.h> +#include <linux/dynamic_pool.h> #define ZSPAGE_MAGIC 0x58 @@ -843,6 +844,20 @@ static inline void zs_uncharge_memory(struct zs_pool *pool, /* See zs_charge_memory() for detail */ memcg_uncharge_zram(pool->memcg, nr_pages); } + +static inline struct page *zs_alloc_page(struct zs_pool *pool, gfp_t gfp) +{ + struct mem_cgroup *memcg = pool->memcg; + struct page *page; + + if (dpool_enabled && memcg) { + page = dynamic_pool_alloc_page(memcg, gfp, 0, 0); + if (page) + return page; + } + + return alloc_page(gfp); +} #else static inline void zs_charge_memory(struct zs_pool *pool, unsigned long nr_pages) @@ -853,6 +868,11 @@ static inline void zs_uncharge_memory(struct zs_pool *pool, unsigned long nr_pages) { } + +static inline struct page *zs_alloc_page(struct zs_pool *pool, gfp_t gfp) +{ + return alloc_page(gfp); +} #endif static void __free_zspage(struct zs_pool *pool, struct size_class *class, @@ -1004,7 +1024,7 @@ static struct zspage *alloc_zspage(struct zs_pool *pool, for (i = 0; i < class->pages_per_zspage; i++) { struct page *page; - page = alloc_page(gfp); + page = zs_alloc_page(pool, gfp); if (!page) { while (--i >= 0) { dec_zone_page_state(pages[i], NR_ZSPAGES); -- 2.43.0