提交 cf8510b3 编写于 作者: L Liu Shixin 提交者: Zheng Zengkai

mm/dynamic_hugetlb: add interface to disable normal pages allocation

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: NLiu Shixin <liushixin2@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 71197c63
...@@ -81,6 +81,8 @@ ssize_t write_2M_reserved_pages(struct kernfs_open_file *of, ...@@ -81,6 +81,8 @@ ssize_t write_2M_reserved_pages(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off); char *buf, size_t nbytes, loff_t off);
ssize_t write_1G_reserved_pages(struct kernfs_open_file *of, ssize_t write_1G_reserved_pages(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off); 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, ssize_t write_hugepage_to_hpool(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off); char *buf, size_t nbytes, loff_t off);
int hugetlb_pool_info_show(struct seq_file *m, void *v); int hugetlb_pool_info_show(struct seq_file *m, void *v);
......
...@@ -449,6 +449,8 @@ static struct page *__alloc_page_from_dhugetlb_pool(void) ...@@ -449,6 +449,8 @@ static struct page *__alloc_page_from_dhugetlb_pool(void)
if (!get_hpool_unless_zero(hpool)) if (!get_hpool_unless_zero(hpool))
return NULL; return NULL;
if (hpool->normal_pages_disabled)
goto out;
percpu_pool = &hpool->percpu_pool[smp_processor_id()]; percpu_pool = &hpool->percpu_pool[smp_processor_id()];
/* /*
* Before we lock percpu_pool, must be sure hpool is unlocked. * Before we lock percpu_pool, must be sure hpool is unlocked.
...@@ -474,6 +476,7 @@ static struct page *__alloc_page_from_dhugetlb_pool(void) ...@@ -474,6 +476,7 @@ static struct page *__alloc_page_from_dhugetlb_pool(void)
unlock: unlock:
spin_unlock_irqrestore(&percpu_pool->lock, flags); spin_unlock_irqrestore(&percpu_pool->lock, flags);
out:
put_hpool(hpool); put_hpool(hpool);
return page; return page;
} }
...@@ -810,6 +813,33 @@ ssize_t write_1G_reserved_pages(struct kernfs_open_file *of, ...@@ -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; 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, ssize_t write_hugepage_to_hpool(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off) char *buf, size_t nbytes, loff_t off)
{ {
......
...@@ -5212,6 +5212,12 @@ static struct cftype mem_cgroup_legacy_files[] = { ...@@ -5212,6 +5212,12 @@ static struct cftype mem_cgroup_legacy_files[] = {
.write = write_2M_reserved_pages, .write = write_2M_reserved_pages,
.flags = CFTYPE_NO_PREFIX | CFTYPE_WORLD_WRITABLE | CFTYPE_NOT_ON_ROOT, .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 #endif
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册