hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I9H66Y CVE: NA
--------------------------------
Next patch will support to allocate page from a hpool for zram and zspool if they are bounded with a memcg, and the memcg is bounded with the hpool. As a preparation, support to allocate page by specifying memcg.
Signed-off-by: Liu Shixin liushixin2@huawei.com --- include/linux/dynamic_hugetlb.h | 7 +++++-- mm/dynamic_hugetlb.c | 25 ++++++++++++++++++++----- mm/page_alloc.c | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/include/linux/dynamic_hugetlb.h b/include/linux/dynamic_hugetlb.h index 06b20a24dfe6..10bff6f093e0 100644 --- a/include/linux/dynamic_hugetlb.h +++ b/include/linux/dynamic_hugetlb.h @@ -103,7 +103,8 @@ void hugetlb_pool_inherit(struct mem_cgroup *memcg, struct mem_cgroup *parent); int hugetlb_pool_destroy(struct cgroup *cgrp); void __init dynamic_hugetlb_init(void);
-struct page *alloc_page_from_dhugetlb_pool(gfp_t gfp, unsigned int order, +struct page *alloc_page_from_dhugetlb_pool(struct mem_cgroup *memcg, + gfp_t gfp, unsigned int order, unsigned int flags); bool free_page_to_dhugetlb_pool(struct page *page); void free_page_list_to_dhugetlb_pool(struct list_head *list); @@ -142,7 +143,9 @@ static inline void __init dynamic_hugetlb_init(void) { }
-static inline struct page *alloc_page_from_dhugetlb_pool(gfp_t gfp, unsigned int order, +static inline struct page *alloc_page_from_dhugetlb_pool(struct mem_cgroup *memcg, + gfp_t gfp, + unsigned int order, unsigned int flags) { return NULL; diff --git a/mm/dynamic_hugetlb.c b/mm/dynamic_hugetlb.c index 72061fd0395e..95a2a82eb2b0 100644 --- a/mm/dynamic_hugetlb.c +++ b/mm/dynamic_hugetlb.c @@ -576,10 +576,9 @@ static bool should_allocate_from_dhugetlb_pool(gfp_t gfp_mask) return true; }
-static struct page *__alloc_page_from_dhugetlb_pool(void) +static struct page *__alloc_page_from_dpool(struct dhugetlb_pool *hpool) { struct percpu_pages_pool *percpu_pool; - struct dhugetlb_pool *hpool; struct page *page = NULL; unsigned long flags;
@@ -630,9 +629,11 @@ static struct page *__alloc_page_from_dhugetlb_pool(void) return page; }
-struct page *alloc_page_from_dhugetlb_pool(gfp_t gfp, unsigned int order, +struct page *alloc_page_from_dhugetlb_pool(struct mem_cgroup *memcg, + gfp_t gfp, unsigned int order, unsigned int flags) { + struct dhugetlb_pool *hpool; struct page *page = NULL;
if (!dhugetlb_enabled) @@ -641,11 +642,25 @@ struct page *alloc_page_from_dhugetlb_pool(gfp_t gfp, unsigned int order, if (order != 0) return NULL;
- if (should_allocate_from_dhugetlb_pool(gfp)) - page = __alloc_page_from_dhugetlb_pool(); + if (memcg) { + hpool = memcg->hpool; + if (!hpool) + return NULL; + goto alloc_page; + } + + if (!should_allocate_from_dhugetlb_pool(gfp)) + return NULL; + + hpool = find_hpool_by_task(current); + if (!hpool) + return NULL;
+alloc_page: + page = __alloc_page_from_dpool(hpool); if (page) prep_new_page(page, order, gfp, flags); + return page; }
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 1ba392f11e6b..e5878707222f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5397,7 +5397,7 @@ struct page *__alloc_pages(gfp_t gfp, unsigned int order, int preferred_nid, alloc_flags |= alloc_flags_nofragment(ac.preferred_zoneref->zone, gfp);
/* Before alloc from buddy system, alloc from hpool firstly */ - page = alloc_page_from_dhugetlb_pool(alloc_gfp, order, alloc_flags); + page = alloc_page_from_dhugetlb_pool(NULL, alloc_gfp, order, alloc_flags); if (page) goto out;