Merge "Enable the memory_recursiveprot mount option" am: 3e9eeb8329 am: 842815552f

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1975508

Change-Id: I1d9489889815a7b53399db0e3549fcd098975e66
This commit is contained in:
Bart Van Assche 2022-03-23 21:16:26 +00:00 committed by Automerger Merge Worker
commit 00916cbb6d

View file

@ -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(),