提交 f698ccf8 编写于 作者: C Chen Wandun 提交者: Zheng Zengkai

memcg: introduce per-memcg reclaim interface for cgroup v1

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I545DF
CVE: NA

--------------------------------

introduce per-memcg reclaim interface for cgroup v1, and
disable memory reclaim for root memcg.
Signed-off-by: NChen Wandun <chenwandun@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 89b8975a
......@@ -5152,6 +5152,49 @@ static int memcg_events_local_show(struct seq_file *m, void *v)
return 0;
}
static ssize_t memory_reclaim(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;
unsigned long nr_to_reclaim, nr_reclaimed = 0;
int err;
buf = strstrip(buf);
err = page_counter_memparse(buf, "", &nr_to_reclaim);
if (err)
return err;
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
mem_cgroup_is_root(memcg))
return -EINVAL;
while (nr_reclaimed < nr_to_reclaim) {
unsigned long reclaimed;
if (signal_pending(current))
return -EINTR;
/* This is the final attempt, drain percpu lru caches in the
* hope of introducing more evictable pages for
* try_to_free_mem_cgroup_pages().
*/
if (!nr_retries)
lru_add_drain_all();
reclaimed = try_to_free_mem_cgroup_pages(memcg,
nr_to_reclaim - nr_reclaimed,
GFP_KERNEL, true);
if (!reclaimed && !nr_retries--)
return -EAGAIN;
nr_reclaimed += reclaimed;
}
return nbytes;
}
static struct cftype mem_cgroup_legacy_files[] = {
{
.name = "usage_in_bytes",
......@@ -5345,6 +5388,10 @@ static struct cftype mem_cgroup_legacy_files[] = {
.file_offset = offsetof(struct mem_cgroup, events_local_file),
.seq_show = memcg_events_local_show,
},
{
.name = "reclaim",
.write = memory_reclaim,
},
{ }, /* terminate */
};
......@@ -6711,46 +6758,6 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of,
return nbytes;
}
static ssize_t memory_reclaim(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;
unsigned long nr_to_reclaim, nr_reclaimed = 0;
int err;
buf = strstrip(buf);
err = page_counter_memparse(buf, "", &nr_to_reclaim);
if (err)
return err;
while (nr_reclaimed < nr_to_reclaim) {
unsigned long reclaimed;
if (signal_pending(current))
return -EINTR;
/*
* This is the final attempt, drain percpu lru caches in the
* hope of introducing more evictable pages for
* try_to_free_mem_cgroup_pages().
*/
if (!nr_retries)
lru_add_drain_all();
reclaimed = try_to_free_mem_cgroup_pages(memcg,
nr_to_reclaim - nr_reclaimed,
GFP_KERNEL, true);
if (!reclaimed && !nr_retries--)
return -EAGAIN;
nr_reclaimed += reclaimed;
}
return nbytes;
}
static struct cftype memory_files[] = {
{
.name = "current",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册