From: Liu Shixin liushixin2@huawei.com
hulk inclusion category: feature bugzilla: 46904, https://gitee.com/openeuler/kernel/issues/I4QSHG CVE: NA
--------------------------------
Add new interface "dhugetlb.disable_normal_pages" to disable the allocation of normal pages from a hpool. This makes dynamic hugetlb more flexible.
Signed-off-by: Liu Shixin liushixin2@huawei.com Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- include/linux/dynamic_hugetlb.h | 2 ++ mm/dynamic_hugetlb.c | 30 ++++++++++++++++++++++++++++++ mm/memcontrol.c | 6 ++++++ 3 files changed, 38 insertions(+)
diff --git a/include/linux/dynamic_hugetlb.h b/include/linux/dynamic_hugetlb.h index ebb5a36a4a26..2b2c90562bcf 100644 --- a/include/linux/dynamic_hugetlb.h +++ b/include/linux/dynamic_hugetlb.h @@ -81,6 +81,8 @@ ssize_t write_2M_reserved_pages(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); ssize_t write_1G_reserved_pages(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); +int normal_pages_disabled_write(struct cgroup_subsys_state *css, struct cftype *cft, u64 val); +u64 normal_pages_disabled_read(struct cgroup_subsys_state *css, struct cftype *cft); ssize_t write_hugepage_to_hpool(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); int hugetlb_pool_info_show(struct seq_file *m, void *v); diff --git a/mm/dynamic_hugetlb.c b/mm/dynamic_hugetlb.c index 40f79f3e6aeb..423d9624d4f0 100644 --- a/mm/dynamic_hugetlb.c +++ b/mm/dynamic_hugetlb.c @@ -449,6 +449,8 @@ static struct page *__alloc_page_from_dhugetlb_pool(void) if (!get_hpool_unless_zero(hpool)) return NULL;
+ if (hpool->normal_pages_disabled) + goto out; percpu_pool = &hpool->percpu_pool[smp_processor_id()]; /* * Before we lock percpu_pool, must be sure hpool is unlocked. @@ -474,6 +476,7 @@ static struct page *__alloc_page_from_dhugetlb_pool(void)
unlock: spin_unlock_irqrestore(&percpu_pool->lock, flags); +out: put_hpool(hpool); return page; } @@ -810,6 +813,33 @@ ssize_t write_1G_reserved_pages(struct kernfs_open_file *of, return update_reserved_pages(memcg, buf, HUGE_PAGES_POOL_1G) ?: nbytes; }
+int normal_pages_disabled_write(struct cgroup_subsys_state *css, + struct cftype *cft, u64 val) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(css); + struct dhugetlb_pool *hpool = memcg->hpool; + + if (!dhugetlb_enabled || !hpool) + return -EINVAL; + if (!((val == 0) || (val == 1))) + return -EINVAL; + + hpool->normal_pages_disabled = val; + return 0; +} + +u64 normal_pages_disabled_read(struct cgroup_subsys_state *css, + struct cftype *cft) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(css); + struct dhugetlb_pool *hpool = memcg->hpool; + + if (!dhugetlb_enabled || !hpool) + return 0; + + return hpool->normal_pages_disabled; +} + ssize_t write_hugepage_to_hpool(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f06c7349d9a4..2804fe9d3dae 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5212,6 +5212,12 @@ static struct cftype mem_cgroup_legacy_files[] = { .write = write_2M_reserved_pages, .flags = CFTYPE_NO_PREFIX | CFTYPE_WORLD_WRITABLE | CFTYPE_NOT_ON_ROOT, }, + { + .name = "dhugetlb.disable_normal_pages", + .read_u64 = normal_pages_disabled_read, + .write_u64 = normal_pages_disabled_write, + .flags = CFTYPE_NO_PREFIX | CFTYPE_WORLD_WRITABLE | CFTYPE_NOT_ON_ROOT, + }, #endif #ifdef CONFIG_NUMA {