提交 6a7b3e98 编写于 作者: L Lu Jialin 提交者: Zheng Zengkai

memcg: Export memcg.high from cgroupv2 to cgroupv1

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4IMAK?from=project-issue
CVE: NA

--------

Export memory.high from cgroupv2 to cgroupv1. Therefore, when the usage
of the memcg is larger than memory.high, some pages will be reclaimed
before return to userland, which will throttle the process.

Only export memory.high number in mem_cgroup_legacy_files and move
related functions in front of mem_cgroup_legacy_files. There is no need
to other changes.
Signed-off-by: NLu Jialin <lujialin4@huawei.com>
Reviewed-by: Nweiyang wang <wangweiyang2@huawei.com>
Reviewed-by: Nweiyang wang <wangweiyang2@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 27c047f4
...@@ -5069,6 +5069,55 @@ static ssize_t memory_low_write(struct kernfs_open_file *of, ...@@ -5069,6 +5069,55 @@ static ssize_t memory_low_write(struct kernfs_open_file *of,
return nbytes; return nbytes;
} }
static int memory_high_show(struct seq_file *m, void *v)
{
return seq_puts_memcg_tunable(m,
READ_ONCE(mem_cgroup_from_seq(m)->memory.high));
}
static ssize_t memory_high_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
unsigned int nr_retries = MAX_RECLAIM_RETRIES;
bool drained = false;
unsigned long high;
int err;
buf = strstrip(buf);
err = page_counter_memparse(buf, "max", &high);
if (err)
return err;
page_counter_set_high(&memcg->memory, high);
for (;;) {
unsigned long nr_pages = page_counter_read(&memcg->memory);
unsigned long reclaimed;
if (nr_pages <= high)
break;
if (signal_pending(current))
break;
if (!drained) {
drain_all_stock(memcg);
drained = true;
continue;
}
reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_pages - high,
GFP_KERNEL, true);
if (!reclaimed && !nr_retries--)
break;
}
memcg_wb_domain_size_changed(memcg);
return nbytes;
}
static struct cftype mem_cgroup_legacy_files[] = { static struct cftype mem_cgroup_legacy_files[] = {
{ {
.name = "usage_in_bytes", .name = "usage_in_bytes",
...@@ -5214,6 +5263,12 @@ static struct cftype mem_cgroup_legacy_files[] = { ...@@ -5214,6 +5263,12 @@ static struct cftype mem_cgroup_legacy_files[] = {
.seq_show = memory_low_show, .seq_show = memory_low_show,
.write = memory_low_write, .write = memory_low_write,
}, },
{
.name = "high",
.flags = CFTYPE_NOT_ON_ROOT,
.seq_show = memory_high_show,
.write = memory_high_write,
},
{ }, /* terminate */ { }, /* terminate */
}; };
...@@ -6417,55 +6472,6 @@ static u64 memory_current_read(struct cgroup_subsys_state *css, ...@@ -6417,55 +6472,6 @@ static u64 memory_current_read(struct cgroup_subsys_state *css,
return (u64)page_counter_read(&memcg->memory) * PAGE_SIZE; return (u64)page_counter_read(&memcg->memory) * PAGE_SIZE;
} }
static int memory_high_show(struct seq_file *m, void *v)
{
return seq_puts_memcg_tunable(m,
READ_ONCE(mem_cgroup_from_seq(m)->memory.high));
}
static ssize_t memory_high_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
unsigned int nr_retries = MAX_RECLAIM_RETRIES;
bool drained = false;
unsigned long high;
int err;
buf = strstrip(buf);
err = page_counter_memparse(buf, "max", &high);
if (err)
return err;
page_counter_set_high(&memcg->memory, high);
for (;;) {
unsigned long nr_pages = page_counter_read(&memcg->memory);
unsigned long reclaimed;
if (nr_pages <= high)
break;
if (signal_pending(current))
break;
if (!drained) {
drain_all_stock(memcg);
drained = true;
continue;
}
reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_pages - high,
GFP_KERNEL, true);
if (!reclaimed && !nr_retries--)
break;
}
memcg_wb_domain_size_changed(memcg);
return nbytes;
}
static int memory_max_show(struct seq_file *m, void *v) static int memory_max_show(struct seq_file *m, void *v)
{ {
return seq_puts_memcg_tunable(m, return seq_puts_memcg_tunable(m,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册