← Back to Pull requests

OCPNODE-4895: Turn off cgroup v2 memory_hugetlb_accounting before CRI-O and the kubelet start #6786

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 23, 2026 15:46 UTC
Author

- What I did

Added a unit to the base templates, cgroup2-no-hugetlb-accounting.service, that turns the cgroup v2 mount option memory_hugetlb_accounting off before CRI-O and the kubelet start.

Why:

  • With this option, the hugepages a pod uses also count against memory.max (kernel documentation).

  • The kubelet sets memory.max from the memory limit alone, for the pod and for each container. So a pod that uses hugepages and ordinary memory together is OOM-killed, or hangs, below its memory limit. Details and measurements: https://github.com/kubernetes/kubernetes/issues/144131 and https://harche.github.io/2026/11/23/notes-on-kubernetes-issue-144131-hugepages.html

  • The option is opt-in in the kernel (torvalds/linux@8cba9576df60); its documentation says it "could regress existing setups, so it must be explicitly opted in".

  • systemd 259 and later set it whenever the kernel supports it (mount-setup.c in v259, systemd/systemd#39486) and have no way to turn it off.

  • RHEL 9 (systemd 252, mount options in rhel-9.10.0) and RHEL 10 (systemd 257, mount options in rhel-10.4) do not set it, so nodes are not affected today.

  • Their kernels support the option (CentOS Stream 9, 5.14.0-765, CentOS Stream 10, 6.12.0-286), so a later systemd would turn it on for every node at once.
  • Pods that have a memory limit far below their hugepages, and so would fail as soon as they touch them (read from upstream sources, not run):

  • VMs with hugepages and dedicated CPUs. KubeVirt sets the pod's hugepages to the guest memory and its memory limit to the overhead only (WithHugePages, WithCPUPinning). The common instance types cx1, n1 and rt1 are of this kind.

  • DPDK pods. The documented examples use hugepages-1Gi: 4Gi with memory: 1Gi (SR-IOV DPDK example) and hugepages-1Gi: 8Gi with memory: 2Gi (base workload).
  • Other pods that use hugepages fail only when hugepages plus ordinary memory exceed the memory limit. Pods without a memory limit do not fail.

    What the unit does:

  • Option not set: an ExecCondition skips the unit. No remount happens, and the unit shows as skipped, not failed.

  • Option set: it remounts cgroup v2 without it. A cgroup v2 remount replaces all of the mount's options (cgroup_reconfigure), so the unit reads the current options and passes the others again.

  • If it fails, the node still starts and the unit is left in failed state.
  • This is a guard, to be removed when the node has another way to keep the option off.

    - How to verify it

    On a node where the option is not set (every node today):

    $ systemctl status cgroup2-no-hugetlb-accounting.service
    ○ cgroup2-no-hugetlb-accounting.service - Turn off memory_hugetlb_accounting on the cgroup v2 mount
    ...
         Active: inactive (dead) (Result: exec-condition) since ...
    $ journalctl -b -u cgroup2-no-hugetlb-accounting.service
    ... cgroup2-no-hugetlb-accounting.service: Skipped due to 'exec-condition'.
    

    On a node where the option is set at boot:

    $ findmnt -n -o FS-OPTIONS -t cgroup2 /sys/fs/cgroup
    rw,nsdelegate,memory_recursiveprot
    $ journalctl -b -u cgroup2-no-hugetlb-accounting.service
    ... cgroup v2 mount options were rw,nsdelegate,memory_recursiveprot,memory_hugetlb_accounting, are now rw,nsdelegate,memory_recursiveprot
    

    What I tested:

    On OpenShift clusters from cluster-bot (GCP, 5.1.0-ec.2 payload with this PR's MCO; RHCOS 10.2, kernel 6.12, systemd 257, CRI-O 1.36 with crun):

  • The current version (5e3a02e7, with ExecCondition). The cluster was built from the first version; on one master and one worker, a drop-in set the new ExecCondition and ExecStart, so the unit ran exactly what the current version runs.

  • - Option not set, after draining and rebooting both nodes: the unit was skipped (inactive (dead) (Result: exec-condition)), about 8 s into boot, before CRI-O and the kubelet started at 22 to 24 s. Mount options stayed rw,nosuid,nodev,noexec,relatime,seclabel. No failed units, CRI-O and the kubelet active, the nodes came back Ready, and the pools stayed Updated.
    - Option set by hand together with nsdelegate and memory_recursiveprot, then the unit started: only memory_hugetlb_accounting was removed, the other options were kept, and the unit was active (exited). Started again: skipped.
    - The hugepages pod below: completes without the option, OOM-killed with it, completes again once the unit has removed it.
  • The first version (0bfd7b0c, the "nothing to do" check inside ExecStart), delivered by the MCO to the master and worker pools at install. Results: https://github.com/openshift/machine-config-operator/pull/6786#issuecomment-7225819220

  • - Option not set, on all 3 masters and 3 workers: the unit ran at boot before CRI-O and the kubelet, did not remount and exited 0. Mount options stayed rw,nosuid,nodev,noexec,relatime,seclabel. Same after draining and rebooting a worker. Pools stayed Updated and all cluster operators stayed healthy.
    - Option set by hand, then the unit restarted: only memory_hugetlb_accounting was removed. nosuid, nodev, noexec, nsdelegate and memory_recursiveprot were kept. Running it again does nothing.
    - A pod with a 256Mi memory limit and 128Mi of 2Mi hugepages that uses all its hugepages and 192Mi of ordinary memory: it completes without the option, is OOM-killed by the kernel with the option, and completes again once the unit has removed the option.

    Elsewhere:

  • The first version of the unit file on an Ubuntu 26.04 VM (kernel 7.0, systemd 259, containerd), not through the MCO:

  • - Booted with the option set: the unit removed it 1.8 s into boot, before the container runtime started at 3.1 s. nsdelegate and memory_recursiveprot were kept.
    - Started by hand with one more option set (favordynmods): that option was kept too.
    - Started by hand with the option not set: no remount.
  • TestCgroup2NoHugetlbAccountingUnitInEveryRole (new) passes for every platform in the test data, and fails when the template file is removed.
  • What I did not test:

  • The current version delivered by the MCO. The CI e2e jobs cover that.

  • The unit removing the option at boot on RHCOS. No RHCOS ships systemd 259 or later yet, so on OpenShift the option was only turned on by hand after boot.

  • RHCOS 9.

  • An upgrade of an existing cluster to a release with this change, and single-node clusters. CI runs both: e2e-aws-ovn-upgrade and e2e-gcp-op-single-node.

  • Whether anything on a node turns the option back on after boot.
  • AI use: this change was written and tested with Claude Code.

    - Description for the changelog

    Nodes turn the cgroup v2 mount option memory_hugetlb_accounting off at boot, so that pods that use hugepages keep their current memory accounting when systemd starts to set the option.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    Machine configurations now ensure that cgroup v2 mounts do not retain the memory_hugetlb_accounting option. This setting is handled consistently across configured platforms and machine roles, helping avoid differences in cgroup mount behavior during system startup. The change applies automatically when the option is present; when it is absent, startup proceeds without remounting.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: haircommander Review duration: 11867m
    All Vouch review confidence checks passed
    Residual risk 0.40 = Change Risk (0.75) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #6786"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 46.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 40.1% · Moderate risk
    40.1%