diff --git a/libprocessgroup/setup/cgroup_map_write.cpp b/libprocessgroup/setup/cgroup_map_write.cpp index 3121d244b..992cc2e23 100644 --- a/libprocessgroup/setup/cgroup_map_write.cpp +++ b/libprocessgroup/setup/cgroup_map_write.cpp @@ -263,8 +263,18 @@ static bool SetupCgroup(const CgroupDescriptor& descriptor) { return false; } - result = mount("none", controller->path(), "cgroup2", MS_NODEV | MS_NOEXEC | MS_NOSUID, - nullptr); + // The memory_recursiveprot mount option has been introduced by kernel commit + // 8a931f801340 ("mm: memcontrol: recursive memory.low protection"; v5.7). Try first to + // mount with that option enabled. If mounting fails because the kernel is too old, + // retry without that mount option. + if (mount("none", controller->path(), "cgroup2", MS_NODEV | MS_NOEXEC | MS_NOSUID, + "memory_recursiveprot") < 0) { + LOG(INFO) << "Mounting memcg with memory_recursiveprot failed. Retrying without."; + if (mount("none", controller->path(), "cgroup2", MS_NODEV | MS_NOEXEC | MS_NOSUID, + nullptr) < 0) { + PLOG(ERROR) << "Failed to mount cgroup v2"; + } + } // selinux permissions change after mounting, so it's ok to change mode and owner now if (!ChangeDirModeAndOwner(controller->path(), descriptor.mode(), descriptor.uid(),