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

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

Change-Id: Ib570a1b16ea67fff6a8d318ea200777f14d78278
This commit is contained in:
Bart Van Assche 2022-03-23 20:56:27 +00:00 committed by Automerger Merge Worker
commit 842815552f

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