提交 7d36553b 编写于 作者: X Xu Yu 提交者: Shile Zhang

alinux: mm,memcg: export memory.high to v1

Export "memory.high" from cgroup v2 to v1 which can be used to archive
some memory QoS.

This is also a way of migrating to v2 gradually.
Signed-off-by: NXu Yu <xuyu@linux.alibaba.com>
Reviewed-by: NXunlei Pang <xlpang@linux.alibaba.com>
Reviewed-by: NYang Shi <yang.shi@linux.alibaba.com>
上级 f72a099b
......@@ -4751,6 +4751,48 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
return ret;
}
static int memory_high_show(struct seq_file *m, void *v)
{
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
unsigned long high = READ_ONCE(memcg->high);
if (high == PAGE_COUNTER_MAX)
seq_puts(m, "max\n");
else
seq_printf(m, "%llu\n", (u64)high * PAGE_SIZE);
return 0;
}
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 long nr_pages;
unsigned long high;
int err;
buf = strstrip(buf);
err = page_counter_memparse(buf, "max", &high);
if (err)
return err;
memcg->high = high;
nr_pages = page_counter_read(&memcg->memory);
if (nr_pages > high)
try_to_free_mem_cgroup_pages(memcg, nr_pages - high,
GFP_KERNEL, true);
setup_memcg_wmark(memcg);
if (!is_wmark_ok(memcg, true))
queue_work(memcg_wmark_wq, &memcg->wmark_work);
memcg_wb_domain_size_changed(memcg);
return nbytes;
}
static struct cftype mem_cgroup_legacy_files[] = {
{
.name = "usage_in_bytes",
......@@ -4910,6 +4952,12 @@ static struct cftype mem_cgroup_legacy_files[] = {
.write = mem_cgroup_idle_page_stats_write,
},
#endif
{
.name = "high",
.flags = CFTYPE_NOT_ON_ROOT,
.seq_show = memory_high_show,
.write = memory_high_write,
},
{ }, /* terminate */
};
......@@ -6095,48 +6143,6 @@ static ssize_t memory_low_write(struct kernfs_open_file *of,
return nbytes;
}
static int memory_high_show(struct seq_file *m, void *v)
{
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
unsigned long high = READ_ONCE(memcg->high);
if (high == PAGE_COUNTER_MAX)
seq_puts(m, "max\n");
else
seq_printf(m, "%llu\n", (u64)high * PAGE_SIZE);
return 0;
}
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 long nr_pages;
unsigned long high;
int err;
buf = strstrip(buf);
err = page_counter_memparse(buf, "max", &high);
if (err)
return err;
memcg->high = high;
nr_pages = page_counter_read(&memcg->memory);
if (nr_pages > high)
try_to_free_mem_cgroup_pages(memcg, nr_pages - high,
GFP_KERNEL, true);
setup_memcg_wmark(memcg);
if (!is_wmark_ok(memcg, true))
queue_work(memcg_wmark_wq, &memcg->wmark_work);
memcg_wb_domain_size_changed(memcg);
return nbytes;
}
static int memory_wmark_low_show(struct seq_file *m, void *v)
{
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册