Skip to content

R5 systemd as PID 1: cgroup v2 controllers, namespaces and pidfds #536

Open

Description

@tamnd

Part of #14.

cgroup2 has the cpu, cpuset, io, memory and pids controllers, cgroup.freeze, cgroup.kill, PSI, the thread mode, nsdelegate and CLONE_INTO_CGROUP (core/rk-cgroup, fs/rk-fs-cgroup). rukernel has the mount, cgroup, network, UTS and IPC namespaces, but CLONE_NEWPID, CLONE_NEWUSER and CLONE_NEWTIME give EINVAL (core/rk-syscall/src/process.rs). pidfd_open, pidfd_send_signal, pidfd_getfd, CLONE_PIDFD and waitid(P_PIDFD) work, but there is no pidfs, no PIDFD_GET_INFO and no SO_PEERPIDFD. The debian boot test runs a shell script as init. No boot test runs systemd.

LTP now: pidfd_* 8 pass, unshare 3 pass, clone3 2 pass. ioctl_ns01, ioctl_ns06 and setns02 fail, and clone301, clone304, unshare05 and ioctl_pidfd02 to ioctl_pidfd06 do not apply, because there is no PID or user namespace.

Scope

Done when

systemd boots as PID 1 and starts its default units. This is the exit of the first item of #14.

Test each task on x86_64 and on arm64. Give the result of both in the PR body.

Linux reference: kernel/cgroup/cgroup.c, kernel/nsproxy.c, kernel/pid_namespace.c, kernel/user_namespace.c, kernel/time/namespace.c, fs/pidfs.c, kernel/pid.c.

Activity

  1. added
    kind/feature
    area/proc
    area/containers
    on Nov 2, 2026
  2. tamnd commented on Nov 2, 2026

    @tamnd
    OwnerAuthor

    #552 (not an item of this issue): the arm64 boot and smp boot tests now run with 8 CPUs. 3 runs of the arm64 smp test on server1 pass in 61, 63 and 73 s at a load of 0.2 to 4.7.

  3. tamnd commented on Nov 3, 2026

    @tamnd
    OwnerAuthor

    #555 merged: pidfs. Each pidfd of a process has one inode in the internal mount of pidfs, with PID_FS_MAGIC. name_to_handle_at gives a FILEID_KERNFS handle and open_by_handle_at opens a new pidfd from it. /proc/PID/fdinfo of a pidfd has Pid: and NSpid:. The init and smp boot tests pass on x86_64 and arm64 (server1, load 0.4 to 4.6), with 15 new checks.

    The item stays open. pidfd_fdinfo_test and pidfd_file_handle_test need CLONE_NEWUSER and CLONE_NEWPID in their fixtures, so pidfd goes into tools/kselftest/build.sh with the PID and user namespaces.

  4. tamnd commented on Nov 3, 2026

    @tamnd
    OwnerAuthor

    #557 merged: the pidfd ioctls. PIDFD_GET_INFO gives the IDs, the credentials, the cgroup ID, the core dump bits, and the exit status after the reap. PIDFD_GET_*_NAMESPACE open the namespace files of the process, and setns takes them. The init and smp boot tests pass on x86_64 and arm64 (server1, load 0.03 to 3.8), with 11 new checks.

    The item stays open: a real PIDFD_THREAD and process_mrelease are not done, and pidfd_info_test, pidfd_test and pidfd_setns_test need user and PID namespaces. PIDFD_GET_USER_NAMESPACE gives EOPNOTSUPP until rukernel has user namespaces.

  5. tamnd commented on Nov 3, 2026

    @tamnd
    OwnerAuthor

    Item 3 is done with #560. kselftest net/af_unix/scm_pidfd passes 4 of 4. The gVisor Unix socket tests (20 binaries, socket_unix_* and the related socket_*_local tests) all pass on x86_64 with QEMU TCG, with a kernel that has #560 (server1, load average 0.63 at start, 0.94 at end), so the results do not change.

  6. tamnd commented on Nov 3, 2026

    @tamnd
    OwnerAuthor

    #565 merged: time namespaces. unshare and clone3 with CLONE_NEWTIME, /proc/PID/timens_offsets, setns with /proc/PID/ns/time or a pidfd, and a vvar page with the offsets for the vDSO. On x86_64 with QEMU TCG (server1), LTP timens01 (8 of 8), clock_gettime03 (24 of 24), clock_nanosleep03 (2 of 2) and sysinfo03 (6 of 6) pass, and kselftest timens passes 8 with 2 skips. timerfd04 passed 3 of 4 in one run (the first case slept 747 ms, more than the limit of 250 ms), and passed in three later runs. The sysinfo uptime now rounds up as on Linux. init and smp pass on x86_64 and arm64. I ticked the item.

  7. tamnd commented on Nov 3, 2026

    @tamnd
    OwnerAuthor

    #567 merged: two fixes that the systemd boot found. mount with MS_BIND | MS_REC now copies the mounts under the source (copy_tree), and /proc/PID/mountinfo works with epoll and has an event when the mounts change. In the Debian 13 systemd boot on x86_64, systemd-logind no longer fails at the step NAMESPACE, "Failed to drain libmount events" is gone, and tmp.mount, dev-hugepages.mount, dev-mqueue.mount and run-lock.mount no longer fail. This is part of the systemd boot test item, which stays open.

  8. tamnd commented on Nov 4, 2026

    @tamnd
    OwnerAuthor

    #572 merged: cargo xtask boot-test systemd (Debian 13, systemd as PID 1, archive from tools/systemd/build.sh, skipped without RK_SYSTEMD) and one /dev/kmsg record for each writev. The item stays open, because the test does not pass yet:

    All the mount units start now (after #567). When these two are fixed, fill allowed in the test and check the state again.

  9. tamnd commented on Nov 4, 2026

    @tamnd
    OwnerAuthor

    #575 adds SO_ATTACH_FILTER, SO_DETACH_FILTER and SO_LOCK_FILTER to netlink sockets. This was the probable cause of the logind failure of #572 ("Failed to create udev watchers: Protocol not available"): the udev monitor of systemd attaches a classic BPF filter to its NETLINK_KOBJECT_UEVENT socket.

    I could not confirm the logind fix with the systemd boot test. On server2, with the Debian 13 archive of tools/systemd/build.sh, systemd now stops before any unit starts:

    systemd[1]: Failed to fork off sandboxing environment for executing generators: Protocol error
    [!!!!!!] Failed to start up manager.
    systemd[1]: Freezing execution.
    

    The kernel of main (a60e447, without #575) stops in the same place with the same archive, so #575 does not cause it. The run of #572 on server1 got past the generators. In systemd, "Protocol error" (EPROTO) here means that the child of safe_fork for the generators (new mount namespace, MS_SLAVE propagation) exited with an error. The cause is not traced yet. It is probably the mount namespace setup, or something that changed after #572.

  10. tamnd commented on Nov 4, 2026

    @tamnd
    OwnerAuthor

    #578 adds the kmod package to the systemd boot test image. systemd 257 loads libkmod with dlopen, and without it systemd-modules-load failed with "Failed to initialize libkmod context: Operation not supported". Now systemd-modules-load.service finds no modules and ends with status 0/SUCCESS, as on Linux without loadable modules (systemd boot on server1, QEMU TCG). The init boot test now checks that the module calls give ENOSYS and that /proc/modules does not exist.

    About "Failed to fork off sandboxing environment for executing generators: Protocol error": I saw it in one boot on server2 at a load average of 30 to 46, with the kernel of main a60e447 and the image with kmod. Two boots on server1 (load 0.05) with the same kernel and image did not show it. In those boots (sd-gens) succeeded and the boot went on to the systemd-logind failure. Thus the error is not a fixed result of a change on main. It occurs on a busy host, and its cause is not known yet.

  11. tamnd commented on Nov 4, 2026

    @tamnd
    OwnerAuthor

    #581 adds the first part of item 12: PID namespaces. clone, clone3 and unshare take CLONE_NEWPID, and setns takes /proc/PID/ns/pid or a pidfd. A thread has an ID at each level, the system calls use the IDs of the caller namespace, the init of a namespace reaps its orphans and is protected from signals of its namespace, and its exit ends the namespace. /proc/PID/ns/pid_for_children, NS_GET_PARENT, the NS_GET_*_PIDNS ioctls and NSpid in the pidfd fdinfo work. On x86_64, LTP pidns01, 02, 04, 06, 10, 12, 13, 16, 17, 20, 30, 31, 32, clone301, ioctl_ns01, ioctl_ns05, pidfd_send_signal03 and unshare05 pass, and the init check passes on x86_64 and arm64. Not done yet: procfs for each namespace (pidns03 fails), NSpid and NStgid in /proc/PID/status, ns_last_pid for each namespace, set_tid of clone3, and pidns05 is too slow under TCG. The item stays open.

  12. 21 remaining items

  13. tamnd commented on Nov 9, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #676 is merged. test_cgcore_destroy passes now. The kernel runs with interrupts off, so the timer ticks did not come in a long read, and a task that slept in usleep did not wake. should_yield now lets in the waiting interrupts and wakes the expired timers, and a long read yields between its steps and ends at a fatal signal. x86_64 test_core: 10 pass, 1 fail (test_cgcore_thread_migration, next PR), 1 skip, in 23 s. The -- only cgroup init test passes on x86_64 and arm64.

  14. tamnd commented on Nov 9, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #681 is merged. /proc/PID/task/TID/cgroup shows the cgroup of the thread, so test_cgcore_thread_migration passes. The kselftest boot test now builds and runs test_core and test_cpuset, and mounts cgroup2 at /sys/fs/cgroup with nsdelegate. x86_64 test_core: 12 pass. test_cpuset: 3 pass. The -- only cgroup init test passes on x86_64 and arm64, except the check cpu.max limits a busy loop in some boots, which is sensitive to the load of the host (#504) at a load average of 10 to 18.

  15. tamnd commented on Nov 10, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #682 is merged. A stopped, traced or vfork thread counts as frozen in its cgroup, and cgroup.events sends inotify IN_MODIFY. The kselftest boot test now builds and runs test_freezer and test_kill too. On x86_64 TCG, test_core, test_cpuset, test_freezer and test_kill pass (666 s for the boot test at a load average of 14). The -- only cgroup init test passes on x86_64. On arm64 only the load sensitive check cpu.max limits a busy loop (#504) failed, at a load average of 30 to 45.

  16. tamnd commented on Nov 10, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #685 is merged. A write of memory.peak now resets the peak of the open file only, as peak_write of Linux, so the checks of test_memcg_current_peak on the open files of memory.peak pass. The test still fails later, because a read of a hole of a file does not put a page in the page cache. The x86_64 and arm64 -- only cgroup init tests pass (load average 16 to 20 on x86_64, 26 on arm64).

  17. tamnd commented on Nov 10, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #687 is merged. A long populate (mlock, MAP_POPULATE, MAP_LOCKED) now waits for memory.high after each batch of 64 pages, as try_charge_memcg of Linux, and test_memcg_high_sync passes. The x86_64 and arm64 -- only cgroup init tests pass.

  18. tamnd commented on Nov 11, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #688 is merged. tools/kselftest/build.sh builds the cgroup selftests without optimization, as their Makefile in Linux, so alloc_anon of test_memcontrol uses its memory again. test_memcontrol and test_cpu are not in TESTS yet, because some of their tests still fail (page cache of reads of holes, sock accounting, cpu.stat against the CPU clock of the process, the weights of nested cgroups, and cpu.max on QEMU TCG).

  19. tamnd commented on Nov 11, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #691 is merged. A kill of a memory.oom.group now counts the victim again in oom_kill, as oom_kill_memcg_member of Linux, and test_memcg_oom_group_score_events passes. The x86_64 and arm64 -- only cgroup init tests pass.

  20. tamnd commented on Nov 11, 2026

    @tamnd
    OwnerAuthor

    cgroup2: LTP runtest/controllers ran once with tools/ltp/run.py on server2 (x86_64, QEMU TCG without KVM, release kernel of the cgroup2 branches up to cg-8, LTP_TIMEOUT_MUL=4). Load average 23.8 at the start and 10.5 at the end. The run took about 4 hours.

    Of the 347 tests: 96 pass, 206 do not apply (TCONF), 40 time out, and 5 fail.

    • Pass: cgroup_core01 to cgroup_core03, memcontrol01, memcontrol02, memcg_regression, memcg_control, io_control01, cgroup_fj_function for cpu, cpuset, memory and hugetlb, 47 of the cgroup_fj_stress tests, and 37 of the 39 pids tests.
    • Do not apply: the tests of the cgroup v1 controllers that cgroup2 does not have (memcg_* v1 files, cpuset_*, cpuacct_*, cgroup_xattr, and the cgroup_fj_* tests of debug, cpuacct, devices, freezer, blkio, net_cls, net_prio and perf_event).
    • Time out: memcg_stress, memcontrol03, memcontrol04, and 37 cgroup_fj_stress tests of cpuset, cpu, memory and hugetlb with many cgroups (2_9, 10_3, 4_4, 200_1 and 1_200). These tests are long on QEMU without KVM.
    • Fail: cgroup (cgroup_regression_test.sh mounts the v1 cgroup file system, and rukernel has only cgroup2), memcg_test_3 (the test timer killed it), controllers (test_controllers.sh is not in the LTP build), and pids_9_2 and pids_9_10 (TWARN: the cleanup rmdir of a test cgroup gave EBUSY right after its processes ended).

    tools/ltp/controllers.md is not made yet, because report.py knows only the groups syscalls, mm, sched, net and pty.

  21. tamnd commented on Nov 11, 2026

    @tamnd
    OwnerAuthor

    cgroup2: #692 is merged. A cgroup that ran past its cpu.max quota now stays throttled until the next periods pay for the difference, as distribute_cfs_runtime of Linux. cpu.max limits a busy loop of the init test passed in the first try at a load average of 16 to 20. test_cpucg_max and test_cpucg_max_nested still fail on QEMU TCG, because each wake costs about 24 ms against a quota of 1 ms, and the main thread of the test does not run first after a throttle.

  22. tamnd commented on Nov 15, 2026

    @tamnd
    OwnerAuthor

    #755 is merged for the cgroup2 item. It adds nested cpu.weight, the weighted load balance of rk-sched, the seccomp CAP_SYS_ADMIN check in the user namespace of the caller, the kselftest cgroup runner (tools/kselftest/run.py and cgroup.md) and the LTP controllers report (tools/ltp/controllers.md).

    Results:

    • The root cgroup.controllers is cpuset cpu io memory hugetlb pids rdma misc on rukernel and on Linux 6.8.
    • kselftest cgroup (test_core, test_memcontrol, test_freezer, test_kill, test_cpu, test_cpuset) on x86_64: Linux 6.8 has 36 pass, 10 fail and 5 skip. rukernel has 36 pass, 11 fail and 4 skip, with the same pass set. On arm64, test_cgfreezer_migrate failed in one run. It is a race in the test, and Linux on arm64 has the same race.
    • LTP runtest/controllers: rukernel has 136 pass, 4 fail, 206 that do not apply and 1 timeout. Linux 6.8 has 133 pass, 9 fail, 201 that do not apply and 4 timeouts.

    I did not tick the item, because 2 LTP tests pass on Linux and not on rukernel:

    • cgroup_regression_test mounts cgroup v1, and rukernel has only cgroup v2. If cgroup v1 is out of the scope of this item, this test is an exception.
    • pids_9_10 depends on timing. It passed on server2 and failed on server1. The test kills the processes of a cgroup and runs rmdir at once. On Linux, the woken process usually runs its exit before the shell, because a wakeup can preempt the shell. rukernel does not preempt on a wakeup in this case, so rmdir can give EBUSY.

    The full gate did not run.

  23. tamnd commented on Nov 16, 2026

    @tamnd
    OwnerAuthor

    #761 merged (10edbe2) for the systemd integration test item. tools/systemd/integration.py runs TEST-07-PID1, TEST-19-CGROUP and TEST-55-OOMD under QEMU on rukernel and on Linux 6.8.0-147-generic, and tools/systemd/integration.md has the tables for x86_64 and arm64 and the list of the exceptions.

    Results on x86_64 (server1, load average 0.2 to 9):

    • TEST-19-CGROUP: the pass set of Linux (14 of 14 subtests and test cases). The same on arm64.
    • TEST-07-PID1: the pass set of Linux, except exec-context. The DevicePolicy=strict part of exec-context now passes (the device controller in access and faccessat).
    • TEST-55-OOMD: 4 of 5 test cases pass. testcase_preference_avoid fails on x86_64 and arm64.

    The item stays open for two reasons:

    • The TEST-55-OOMD kill cases are blocked on R5 memory reclaim: the reclaim counters and anonymous pages to swap, for systemd-oomd #752. They need memory pressure from reclaim, and rukernel has no reclaim of anonymous memory and no swap, so pgscan stays 0 and systemd-oomd does not kill.
    • TEST-07-PID1 exec-context fails at SocketBindAllow= and SocketBindDeny=. The eBPF verifier of rukernel stops the program sd_bind4 of systemd (82 instructions, two loops of 128 rounds) at the limit of 1000000 instructions. It prunes a path only when a kept state is equal in all registers, and it keeps at most 16 states for each instruction. Linux 6.8 also prunes when the registers that are different are dead or are scalars that are not precise. So systemd turns off bpf-socket-bind. restrict_ifaces_bpf also does not load, because mmap of a BPF_F_MMAPABLE array map gives ENODEV. This needs a separate change in rk-bpf.

    The other differences are TCG timing: exec-deserialization (Linux failed testcase_removal and testcase_swapped in its run, rukernel passed them), DeferReactivation, and type-exec-parallel on arm64 at a load of 40 (a D-Bus time limit). private-pids is skipped on both kernels.

  24. tamnd commented on Nov 17, 2026

    @tamnd
    OwnerAuthor

    #793 merged (8561b50) for item 2. The match patterns of tools/systemd/integration.py now reach systemd, and a test that made /testok and stopped with SIGTERM passes. On rukernel 0.5.36, TEST-07-PID1 passes in full on x86_64 (1029 s, load 0.0 to 1.7) and TEST-19-CGROUP passes on x86_64 (174 s) and arm64 (1045 s, load 4.5 to 13.8). On arm64, exec-context, protect-control-groups and the other subtests that ran pass, and private-pids is skipped, as on Linux. TEST-55-OOMD is blocked on #752 item 3, so item 2 stays open.

  25. tamnd commented on Nov 18, 2026

    @tamnd
    OwnerAuthor

    #798 merged (8216c76) for item 1. The base slice of the fair class is now 0.75 ms on one CPU and grows with the log of the CPUs. RUN_TO_PARITY now keeps the running task only for the slice of its pick, as Linux 6.8 does. LTP pids_9_10 passes 24 of 24 times on x86_64 (it was 11 of 24), all 39 pids tests pass, and runtest/sched has no new failure. arm64 TEST-19-CGROUP passes. Now only cgroup_regression_test passes on Linux and not on rukernel, and it is a listed exception (cgroup v1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/containersarea/prockind/feature

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions