From 304881205579d65819711d8fe733c31f100977fa Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 15 Nov 2023 09:11:20 -0800 Subject: [PATCH] Revert "libprocessgroup: Add a function to remove only empty process groups" Revert this CL because it tests whether or not cgroup.procs files are empty with the stat() system call and because the cgroup filesystem always reports st_size == 0. Rename RemoveUidCgroups() into RemoveEmptyUidCgroups(). Change-Id: I4de6f16c814c4b47d8d74c8045f0c1ee71975ac0 Signed-off-by: Bart Van Assche --- .../include/processgroup/processgroup.h | 1 - libprocessgroup/processgroup.cpp | 33 +++---------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index a319c631f..9107838b8 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -87,7 +87,6 @@ bool setProcessGroupSwappiness(uid_t uid, int initialPid, int swappiness); bool setProcessGroupSoftLimit(uid_t uid, int initialPid, int64_t softLimitInBytes); bool setProcessGroupLimit(uid_t uid, int initialPid, int64_t limitInBytes); -void removeAllProcessGroups(void); void removeAllEmptyProcessGroups(void); // Provides the path for an attribute in a specific process group diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index d352f0e34..b4482d096 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -233,7 +233,7 @@ static int RemoveCgroup(const char* cgroup, uid_t uid, int pid, unsigned int ret return ret; } -static bool RemoveUidCgroups(const std::string& uid_path, bool empty_only) { +static bool RemoveEmptyUidCgroups(const std::string& uid_path) { std::unique_ptr uid(opendir(uid_path.c_str()), closedir); bool empty = true; if (uid != NULL) { @@ -248,21 +248,6 @@ static bool RemoveUidCgroups(const std::string& uid_path, bool empty_only) { } auto path = StringPrintf("%s/%s", uid_path.c_str(), dir->d_name); - if (empty_only) { - struct stat st; - auto procs_file = StringPrintf("%s/%s", path.c_str(), - PROCESSGROUP_CGROUP_PROCS_FILE); - if (stat(procs_file.c_str(), &st) == -1) { - PLOG(ERROR) << "Failed to get stats for " << procs_file; - continue; - } - if (st.st_size > 0) { - // skip non-empty groups - LOG(VERBOSE) << "Skipping non-empty group " << path; - empty = false; - continue; - } - } LOG(VERBOSE) << "Removing " << path; if (rmdir(path.c_str()) == -1) { if (errno != EBUSY) { @@ -275,7 +260,9 @@ static bool RemoveUidCgroups(const std::string& uid_path, bool empty_only) { return empty; } -static void removeAllProcessGroupsInternal(bool empty_only) { +void removeAllEmptyProcessGroups() { + LOG(VERBOSE) << "removeAllEmptyProcessGroups()"; + std::vector cgroups; std::string path, memcg_apps_path; @@ -302,7 +289,7 @@ static void removeAllProcessGroupsInternal(bool empty_only) { } auto path = StringPrintf("%s/%s", cgroup_root_path.c_str(), dir->d_name); - if (!RemoveUidCgroups(path, empty_only)) { + if (!RemoveEmptyUidCgroups(path)) { LOG(VERBOSE) << "Skip removing " << path; continue; } @@ -315,16 +302,6 @@ static void removeAllProcessGroupsInternal(bool empty_only) { } } -void removeAllProcessGroups() { - LOG(VERBOSE) << "removeAllProcessGroups()"; - removeAllProcessGroupsInternal(false); -} - -void removeAllEmptyProcessGroups() { - LOG(VERBOSE) << "removeAllEmptyProcessGroups()"; - removeAllProcessGroupsInternal(true); -} - /** * Process groups are primarily created by the Zygote, meaning that uid/pid groups are created by * the user root. Ownership for the newly created cgroup and all of its files must thus be