mirror of
https://github.com/NixOS/nix
synced 2025-07-05 12:21:48 +02:00
Merge pull request #11412 from parkerhoyes/daemon-cgroup
Move daemon process into sub-cgroup
This commit is contained in:
commit
5e337ee60d
8 changed files with 115 additions and 17 deletions
|
@ -32,11 +32,7 @@ unsigned int getMaxCPU()
|
|||
auto cgroupFS = getCgroupFS();
|
||||
if (!cgroupFS) return 0;
|
||||
|
||||
auto cgroups = getCgroups("/proc/self/cgroup");
|
||||
auto cgroup = cgroups[""];
|
||||
if (cgroup == "") return 0;
|
||||
|
||||
auto cpuFile = *cgroupFS + "/" + cgroup + "/cpu.max";
|
||||
auto cpuFile = *cgroupFS + "/" + getCurrentCgroup() + "/cpu.max";
|
||||
|
||||
auto cpuMax = readFile(cpuFile);
|
||||
auto cpuMaxParts = tokenizeString<std::vector<std::string>>(cpuMax, " \n");
|
||||
|
|
|
@ -144,4 +144,23 @@ CgroupStats destroyCgroup(const Path & cgroup)
|
|||
return destroyCgroup(cgroup, true);
|
||||
}
|
||||
|
||||
std::string getCurrentCgroup()
|
||||
{
|
||||
auto cgroupFS = getCgroupFS();
|
||||
if (!cgroupFS)
|
||||
throw Error("cannot determine the cgroups file system");
|
||||
|
||||
auto ourCgroups = getCgroups("/proc/self/cgroup");
|
||||
auto ourCgroup = ourCgroups[""];
|
||||
if (ourCgroup == "")
|
||||
throw Error("cannot determine cgroup name from /proc/self/cgroup");
|
||||
return ourCgroup;
|
||||
}
|
||||
|
||||
std::string getRootCgroup()
|
||||
{
|
||||
static std::string rootCgroup = getCurrentCgroup();
|
||||
return rootCgroup;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,4 +25,13 @@ struct CgroupStats
|
|||
*/
|
||||
CgroupStats destroyCgroup(const Path & cgroup);
|
||||
|
||||
std::string getCurrentCgroup();
|
||||
|
||||
/**
|
||||
* Get the cgroup that should be used as the parent when creating new
|
||||
* sub-cgroups. The first time this is called, the current cgroup will be
|
||||
* returned, and then all subsequent calls will return the original cgroup.
|
||||
*/
|
||||
std::string getRootCgroup();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue