mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 10:31:35 +00:00
init: add support for cgroupv2
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
e71deb3862
commit
5af7c526ec
@ -227,22 +227,26 @@ func doMounts() {
|
|||||||
// misc /proc mounted fs
|
// misc /proc mounted fs
|
||||||
mountSilent("binfmt_misc", "/proc/sys/fs/binfmt_misc", "binfmt_misc", noexec|nosuid|nodev, "")
|
mountSilent("binfmt_misc", "/proc/sys/fs/binfmt_misc", "binfmt_misc", noexec|nosuid|nodev, "")
|
||||||
|
|
||||||
// mount cgroup root tmpfs
|
if isCgroupV2() {
|
||||||
mount("cgroup_root", "/sys/fs/cgroup", "tmpfs", nodev|noexec|nosuid, "mode=755,size=10m")
|
mount("cgroup2", "/sys/fs/cgroup", "cgroup2", noexec|nosuid|nodev, "")
|
||||||
// mount cgroups filesystems for all enabled cgroups
|
} else {
|
||||||
for _, cg := range cgroupList() {
|
// mount cgroup root tmpfs
|
||||||
path := filepath.Join("/sys/fs/cgroup", cg)
|
mount("cgroup_root", "/sys/fs/cgroup", "tmpfs", nodev|noexec|nosuid, "mode=755,size=10m")
|
||||||
mkdir(path, 0555)
|
// mount cgroups filesystems for all enabled cgroups
|
||||||
mount(cg, path, "cgroup", noexec|nosuid|nodev, cg)
|
for _, cg := range cgroupList() {
|
||||||
|
path := filepath.Join("/sys/fs/cgroup", cg)
|
||||||
|
mkdir(path, 0555)
|
||||||
|
mount(cg, path, "cgroup", noexec|nosuid|nodev, cg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// use hierarchy for memory
|
||||||
|
write("/sys/fs/cgroup/memory/memory.use_hierarchy", "1")
|
||||||
|
|
||||||
|
// many things assume systemd
|
||||||
|
mkdir("/sys/fs/cgroup/systemd", 0555)
|
||||||
|
mount("cgroup", "/sys/fs/cgroup/systemd", "cgroup", 0, "none,name=systemd")
|
||||||
}
|
}
|
||||||
|
|
||||||
// use hierarchy for memory
|
|
||||||
write("/sys/fs/cgroup/memory/memory.use_hierarchy", "1")
|
|
||||||
|
|
||||||
// many things assume systemd
|
|
||||||
mkdir("/sys/fs/cgroup/systemd", 0555)
|
|
||||||
mount("cgroup", "/sys/fs/cgroup/systemd", "cgroup", 0, "none,name=systemd")
|
|
||||||
|
|
||||||
// make / rshared
|
// make / rshared
|
||||||
mount("", "/", "", rec|shared, "")
|
mount("", "/", "", rec|shared, "")
|
||||||
}
|
}
|
||||||
@ -421,6 +425,20 @@ func doShutdown(action string) {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isCgroupV2() bool {
|
||||||
|
dt, err := os.ReadFile("/proc/cmdline")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error reading /proc/cmdline: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, s := range strings.Split(string(dt), " ") {
|
||||||
|
if s == "linuxkit.unified_cgroup_hierarchy=1" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if filepath.Base(os.Args[0]) == "rc.shutdown" {
|
if filepath.Base(os.Args[0]) == "rc.shutdown" {
|
||||||
action := "poweroff"
|
action := "poweroff"
|
||||||
|
Loading…
Reference in New Issue
Block a user