[Devel] [PATCH RH9] mm/memcontrol: prohibit writing to memory.numa_migrate from container

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Wed Dec 6 06:19:02 MSK 2023


We might want to put containers on designated numa nodes for optimal
perfomance, it will be all ruinied if container could force its memory
pages to move to any node it wants.

This memory.numa_migrate file was originaly made for vcmmd which works
from ve0, so we should be fine with this additional restriction.

Fixes: dfc0b63bfd50c ("mm: memcontrol: add memory.numa_migrate file")
https://virtuozzo.atlassian.net/browse/PSBM-152372
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>

Feature: mm: interface to migrate memory between NUMA nodes upon userspace request
---
 mm/memcontrol.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index fd706aa1bbbd1..b7c6ee09ab9fc 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4700,8 +4700,8 @@ static int memcg_numa_migrate_pages(struct mem_cgroup *memcg,
  *
  * The call may be interrupted by a signal, in which case -EINTR is returned.
  */
-static ssize_t memcg_numa_migrate_write(struct kernfs_open_file *of, char *buf,
-				size_t nbytes, loff_t off)
+static ssize_t __memcg_numa_migrate_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));
 	NODEMASK_ALLOC(nodemask_t, target_nodes, GFP_KERNEL);
@@ -4739,6 +4739,15 @@ static ssize_t memcg_numa_migrate_write(struct kernfs_open_file *of, char *buf,
 	return ret ?: nbytes;
 }
 
+static ssize_t memcg_numa_migrate_write(struct kernfs_open_file *of, char *buf,
+					size_t nbytes, loff_t off)
+{
+	if (!ve_is_super(get_exec_env()))
+		return -EPERM;
+
+	return __memcg_numa_migrate_write(of, buf, nbytes, off);
+}
+
 #endif /* CONFIG_NUMA */
 
 static const unsigned int memcg1_stats[] = {
-- 
2.43.0



More information about the Devel mailing list