Commit cf8510b3 authored by Liu Shixin's avatar Liu Shixin Committed by Zheng Zengkai
Browse files

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: default avatarLiu Shixin <liushixin2@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 71197c63
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);
+30 −0
Original line number Diff line number Diff line
@@ -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)
{
+6 −0
Original line number Diff line number Diff line
@@ -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
	{