mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-18 23:19:34 +02:00
memcg: make the v1 soft limit knob inert
The v1 soft limit has been deprecated since v6.12 and nobody has reported depending on it. Start the removal by decoupling the interface from the implementation: keep memory.soft_limit_in_bytes, but ignore writes to it and always report the maximum value on read similar to what memory.kmem.limit_in_bytes already does. Writes are still parsed, so malformed input keeps returning -EINVAL. The knob now also behaves the same everywhere: it used to return -EOPNOTSUPP on PREEMPT_RT, where soft limit reclaim has always been disabled. This also fixes the syzbot report linked below. Soft limit reclaim is the only caller that runs shrink_lruvec() from kswapd against a specific memcg, so it is the only way to reach lru_gen_shrink_lruvec() and in turn set_mm_walk(), which warns when called from kswapd. Link: https://lore.kernel.org/20260811203203.3456029-2-shakeel.butt@linux.dev Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev> Reported-by: syzbot+12ee2725d5fde63a9c96@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/6a7a6929.b50370da.49fe0.005e.GAE@google.com/ Acked-by: Michal Hocko <mhocko@suse.com> Cc: Axel Rasmussen <axelrasmussen@google.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Kairui Song <kasong@tencent.com> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
7b8a8ae4dd
commit
a3417097fb
+26
-17
@@ -96,7 +96,6 @@ enum {
|
||||
RES_LIMIT,
|
||||
RES_MAX_USAGE,
|
||||
RES_FAILCNT,
|
||||
RES_SOFT_LIMIT,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_LOCKDEP
|
||||
@@ -1888,6 +1887,30 @@ static int mem_cgroup_hierarchy_write(struct cgroup_subsys_state *css,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static u64 mem_cgroup_soft_limit_read(struct cgroup_subsys_state *css,
|
||||
struct cftype *cft)
|
||||
{
|
||||
return (u64)PAGE_COUNTER_MAX * PAGE_SIZE;
|
||||
}
|
||||
|
||||
static ssize_t mem_cgroup_soft_limit_write(struct kernfs_open_file *of,
|
||||
char *buf, size_t nbytes, loff_t off)
|
||||
{
|
||||
unsigned long nr_pages;
|
||||
int ret;
|
||||
|
||||
ret = page_counter_memparse(strstrip(buf), "-1", &nr_pages);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
pr_warn_once("soft_limit_in_bytes is deprecated and will be removed. "
|
||||
"Writing any value to this file has no effect. "
|
||||
"Please report your usecase to linux-mm@kvack.org if you "
|
||||
"depend on this functionality.\n");
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
|
||||
struct cftype *cft)
|
||||
{
|
||||
@@ -1924,8 +1947,6 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
|
||||
return (u64)counter->watermark * PAGE_SIZE;
|
||||
case RES_FAILCNT:
|
||||
return counter->failcnt;
|
||||
case RES_SOFT_LIMIT:
|
||||
return (u64)READ_ONCE(memcg->soft_limit) * PAGE_SIZE;
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
@@ -2020,17 +2041,6 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RES_SOFT_LIMIT:
|
||||
if (IS_ENABLED(CONFIG_PREEMPT_RT)) {
|
||||
ret = -EOPNOTSUPP;
|
||||
} else {
|
||||
pr_warn_once("soft_limit_in_bytes is deprecated and will be removed. "
|
||||
"Please report your usecase to linux-mm@kvack.org if you "
|
||||
"depend on this functionality.\n");
|
||||
WRITE_ONCE(memcg->soft_limit, nr_pages);
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret ?: nbytes;
|
||||
}
|
||||
@@ -2384,9 +2394,8 @@ struct cftype mem_cgroup_legacy_files[] = {
|
||||
},
|
||||
{
|
||||
.name = "soft_limit_in_bytes",
|
||||
.private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT),
|
||||
.write = mem_cgroup_write,
|
||||
.read_u64 = mem_cgroup_read_u64,
|
||||
.write = mem_cgroup_soft_limit_write,
|
||||
.read_u64 = mem_cgroup_soft_limit_read,
|
||||
},
|
||||
{
|
||||
.name = "failcnt",
|
||||
|
||||
Reference in New Issue
Block a user