@@ -220,6 +220,9 @@ struct mem_cgroup {
*/
bool oom_group;
+ /* Folios won't be mlocked in this memcg. */
+ bool nomlock;
+
int swappiness;
/* memory.events and memory.events.local */
@@ -4374,6 +4374,35 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf,
return nbytes;
}
+static int memory_nomlock_show(struct seq_file *m, void *v)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
+
+ seq_printf(m, "%d\n", READ_ONCE(memcg->nomlock));
+ return 0;
+}
+
+static ssize_t memory_nomlock_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));
+ int ret, nomlock;
+
+ buf = strstrip(buf);
+ if (!buf)
+ return -EINVAL;
+
+ ret = kstrtoint(buf, 0, &nomlock);
+ if (ret)
+ return ret;
+
+ if (nomlock != 0 && nomlock != 1)
+ return -EINVAL;
+
+ WRITE_ONCE(memcg->nomlock, nomlock);
+ return nbytes;
+}
+
static struct cftype memory_files[] = {
{
.name = "current",
@@ -4445,6 +4474,12 @@ static struct cftype memory_files[] = {
.flags = CFTYPE_NS_DELEGATABLE,
.write = memory_reclaim,
},
+ {
+ .name = "nomlock",
+ .flags = CFTYPE_NOT_ON_ROOT,
+ .seq_show = memory_nomlock_show,
+ .write = memory_nomlock_write,
+ },
{ } /* terminate */
};
Add a new cgroup file memory.nomlock to control the behavior of mlock. This is a preparation of the followup patch. 0: Disable nomlock 1: Enable nomlock Signed-off-by: Yafang Shao <laoar.shao@gmail.com> --- include/linux/memcontrol.h | 3 +++ mm/memcontrol.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)