linux: support hierarchies and cgroup2 for mem constraint lookup (rebase)
Rebase of https://github.com/libuv/libuv/pull/2323, which I'm hoping to help push over the line.
As far as I could see, here were only a couple of remaining review comments by @bnoordhuis:
You parse /proc/self/mountinfo to determine if the system uses cgroups v1 or v2? Is that necessary? Doesn't the format of the memory field in /proc/self/cgroups tell you that?
Would open("/sys/fs/cgroup/unified", O_DIRECTORY|O_CLOEXEC) work? It's a v2 system when it's there, it seems reasonable to assume v1 when it's not. (Related subject: I prefer openat() over path munging.)
I don't know whether the cgroupv2 controller is guaranteed to be mounted at /sys/fs/cgroup/unified. The cgroups man pages only state that modern systemd auto-mounts the cgroup2 filesystem there, nothing more general. So for now, I've left the mountinfo parsing in, but happy to change that.
I think it should fall back to /sys/fs/cgroup/memory/memory.limit_in_bytes if procfs isn't mounted. Right now it seems to default to 0, no limit.
Done.
cc @vtjnash @kjin
On an Alpine Linux (OpenRC, not systemd) system, the cgroup2 mount also appears at /sys/fs/cgroup/unified, if that's helpful at all.
I'll review this when I get back from vacation, around the 25th. Thanks for the PR, @maleadt.
@bnoordhuis Friendly bump; have you had the time to review this yet? Thanks!
I had this on my list of PRs to review this week but looks like I'm not going to get around to it due to time constraints.
Superseded by https://github.com/libuv/libuv/pull/3744