Skip to content

fix(snode): size a Kubernetes worker's huge pages from the pods' requests - #1698

Open
noctarius wants to merge 2 commits into
mainfrom
fix/k8s-hugepages-from-node-accounting
Open

noctarius wants to merge 2 commits into
mainfrom
fix/k8s-hugepages-from-node-accounting

Conversation

@noctarius

@noctarius noctarius commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • On a Kubernetes worker, apply_config treated every huge page the host carried before simplyblock as the host's own and added simplyblock's pages on top.
  • A pod can use only the hugepages-2Mi it requests, because the kubelet sets each container's hugetlb limit to its request. Pages that no pod requests are therefore unused, and the kubelet still removes them from the node's memory.
  • apply_config now lists the pods on the node, leaves out simplyblock's storage pods (role=simplyblock-storage-node) and finished pods, and sums their hugepages-2Mi requests. That sum becomes the host's share. A sum above the recorded baseline raises the baseline, so release_hugepages leaves those pages to the host. Requests are parsed as Kubernetes quantities, and native sidecars (init containers with restartPolicy: Always) count beside the app containers, as the scheduler counts them. A pool that already holds both shares is left as it is, and one that doesn't grows by the shortfall.
  • If the pods can't be listed, the previous behavior applies.
  • set_hugepages_if_needed takes the sum as an optional claimed_by_others; without it, the function behaves as before.
  • The storage-node ClusterRole the operator creates already allows listing pods cluster-wide, so no RBAC change is needed.

Why

In e2e lblk run 44678939560, the test bootstrap reserved 7958 pages on a 31 GiB n2-standard-8, and no pod requested them. apply_config raised the pool to 12028 pages (23.5 GiB), which left about 7.6 GiB of ordinary memory on the worker. The SPDK pod's 2188 MiB didn't fit beside the 5.9 GiB the control-plane pods on that worker requested. It stayed Pending with FailedScheduling: Insufficient memory, and node add retried until the run timed out. With this change the pool stays at 7958 pages, which already covers the 3990 simplyblock needs.

Limits

  • On hosts with several NUMA nodes, Kubernetes doesn't say which NUMA node other pods' pages are on. The cap applies their whole request to every NUMA node, which errs toward a bigger pool. On single-NUMA hosts it is exact.
  • On Talos, the flow where sbcli writes the machine config (_talos_managed_pool) is unchanged.

Test plan

  • tests/unit/test_hugepages_kube_accounting.py reproduces the e2e worker. Against unchanged code, 5 of its 6 tests fail with assert 12028 == 7958, the pool size from the e2e run. With the fix, all 6 pass.
  • The 6 tests cover: no pods requesting huge pages, other pods' requests that fit in the existing pool, requests that don't fit (pool grows to adjust_hugepages(6000 + 3990)), a leftover simplyblock storage pod, finished pods, and pods that can't be listed (previous behavior).
  • After review: a pod claim above the recorded baseline grows the pool and survives release_hugepages, a 4194304k request reads as 2000 pages, a native sidecar counts beside the app containers, and an ordinary init container counts only while it runs. The first three failed against the previous commit.
  • The existing huge-page tests still pass (baseline, release, Talos, and apply_config sizing), and the apply_config sizing test no longer reaches a real Kubernetes client.
  • tox -e unit,py314t-unit,types: 7485 passed on each interpreter and mypy is clean. The one failure, test_spdk_proxy_unit.py::TestMetricsEndpoint::test_metrics_are_served, also fails without this change on macOS, because process_open_fds is exported only on Linux.
  • lblk e2e on simplyBlockDeployGCP once the main image is rebuilt.

🤖 Generated with Claude Code

…ests

apply_config treated every huge page a worker carried before simplyblock
as the host's own and added simplyblock's pages on top. On Kubernetes
that pool is accounted for: a pod can use only the hugepages-2Mi it
requests, so pages no pod requests are unused. apply_config now lists
the pods on the node, leaves simplyblock's storage pods out, and keeps
the host's share at no more than what the others request. A pool that
already holds both is left as it is; one that does not grows by the
shortfall. When the pods cannot be listed, the previous behavior stays.

The e2e lblk run 44678939560 reserved 7958 pages that no pod requested;
apply_config raised the pool to 12028 (23.5 GiB of 31 GiB), the kubelet
took all of it out of the node's memory, and the SPDK pod stayed Pending
on "Insufficient memory" until the run timed out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 06:35
@github-actions github-actions Bot added the target/main Targets the development branch label Nov 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Huge-page sizing can leave capacity below combined workload demand by undercounting growing pod claims and native sidecars, while valid Kubernetes quantity requests can cause configuration to fail.

3 open issues
What changed in this PR

This PR adjusts Kubernetes worker huge-page sizing to reuse existing capacity based on other pods’ requests, aiming to avoid unnecessary pool growth that reduces memory available for scheduling.

Changes:

  • Counts other pods’ huge-page requests, excluding simplyblock storage pods and finished pods.
  • Passes those claims into pool sizing while preserving previous behavior when pod listing fails.
  • Adds six regression tests and isolates an existing sizing test from Kubernetes access.
File Description
tests/​unit/​test_talos_hugepages.py Mocks pod accounting in the existing sizing test.
tests/​unit/​test_hugepages_kube_accounting.py Covers pool reuse, growth, pod exclusions, and listing failure.
simplyblock_web/​api/​internal/​storage_node/​kubernetes.py Collects pod huge-page requests and supplies them to sizing.
simplyblock_core/​utils/​__init__.py Adds optional claim-aware huge-page allocation.

Review effort: Balanced

Comment thread simplyblock_core/utils/__init__.py Resolved
Three gaps in the pod accounting, from the review of #1698:

- The pods' claim was capped at the recorded baseline. On a host that
  reserved nothing itself, a pool simplyblock had grown to 4096 and a
  pod claiming 2000 of it was left at 4096, short of the 2000 beside
  simplyblock's 3990. The claim is now the host's share as it stands,
  and a claim above the baseline raises the baseline, so
  release_hugepages leaves those pages to the host.
- Requests were read with the MiB-only converter, which raised on valid
  quantities such as 4194304k outside the error handling and failed
  apply_config. They are now parsed with kubernetes.utils.parse_quantity,
  inside the handler.
- Native sidecars (init containers with restartPolicy Always) were
  counted like init containers that finish. They now add to the app
  containers and to every init container started after them, as the
  scheduler counts them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

target/main Targets the development branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants