libprocessgroup: Remove isolated UID cgroup directories
Global UID level cgroup removal was eliminated because of a race
between app launch and app killing using the same directory name. [1]
However isolated app UIDs are assigned sequentially, and are
basically never reused until we wrap around the large range of
isolated UIDs. This leaves thousands of isolated cgroup directories
unused, which consumes kernel memory and increases memory reclaim
overhead. Remove this subset of UID level cgroup directories when
killing process groups.
[1] https://android.googlesource.com/platform/system/core/+/d0464b0c0180b8b98fe6a65b7188d45612b2d546
Test: 50 cycle ACT leaves 1000 fewer empty isolated cgroups
Bug: 290953668
Change-Id: If7d2a7b8eec14561a72208049b74ff785ca961bd
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index 1f29040..06d386f 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -223,6 +223,13 @@
std::this_thread::sleep_for(5ms);
}
+ if (!ret && uid >= AID_ISOLATED_START && uid <= AID_ISOLATED_END) {
+ // Isolated UIDs are unlikely to be reused soon after removal,
+ // so free up the kernel resources for the UID level cgroup.
+ const auto uid_path = ConvertUidToPath(cgroup, uid);
+ ret = rmdir(uid_path.c_str());
+ }
+
return ret;
}