Skip to content

add KSM and THP tuning opt-ins - #288

Merged
openshift-merge-bot[bot] merged 6 commits into
openshift-virtualization:mainfrom
michalskrivanek:ksm-thp
Aug 18, 2026
Merged

add KSM and THP tuning opt-ins#288
openshift-merge-bot[bot] merged 6 commits into
openshift-virtualization:mainfrom
michalskrivanek:ksm-thp

Conversation

@michalskrivanek

Copy link
Copy Markdown
Contributor

add opt-in MachineConfigs for KSM zero-only and THP tuning

Two new opt-in features gated on HCO annotations:

  • ksm-zero-only (platform.kubevirt.io/enable-ksm-zero-only):
    Enables KSM in redhat_only_zero_pages mode with adaptive scan rate.
    Formula: pages_to_scan=1000, sleep=min(50, 25600/node_gb).
  • thp-tuning (platform.kubevirt.io/enable-thp-tuning):
    Sets THP to madvise and tunes khugepaged for KVM workloads.
    Formula: pages_to_scan=130000, sleep=1000+64000/node_gb.

Both deploy a Python script via systemd oneshot that reads node
memory size and writes computed parameters to sysfs at boot.

@openshift-ci

openshift-ci Bot commented Aug 4, 2026

Copy link
Copy Markdown

Hi @michalskrivanek. Thanks for your PR.

I'm waiting for a openshift-virtualization member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@michalskrivanek

michalskrivanek commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@fabiand @tiraboschi wdyt?

tried to balance the CPU and the scanning rate and the (currently inevitable) conflict between KSM and THP.
This way for ~90GB worth of VM memory it takes 20m for KSM sweep (40m to merge zero pages), and ~4m for THP to collapse, with <5% CPU usage for ksmd (with spike to <15% when merging) and <1% khugepaged (with spikes as well, depending on available memory)
With some proportionality on smaller or larger systems.
They could be deployed individually and also combined.
The KSM really only makes sense for Windows (or DISA STIG Linux, with the same zeroing memory feature).

corresponding metrics PR openshift-virtualization/kubevirt-metrics-exporter#18

@tiraboschi

Copy link
Copy Markdown
Member

/ok-to-test

Comment on lines +10 to +13
spec:
{{- if $ksmZeroOnly }}
ksmConfiguration: null
{{- end }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering if we should do the opposite and threat HCO CR as read-only honoring the new annotation only when ksmConfiguration is null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

zero-only-pages conflict with kubevirt's KSM management. I think it's the right direction, overriding possible full KSM config when zero-only-pages are requested. Or did you mean something else?

Comment thread assets/active/metrics-exporter/metrics-exporter.yaml.tpl
Comment thread assets/active/metadata.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Generated Files Verification Failed

One or more generated files in this PR are out of sync:

  • CRDs: Run make update-crds if CRD verification failed
  • RBAC: Run make generate-rbac if RBAC verification failed

Please regenerate the files locally and commit the changes.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Generated Files Verification Failed

One or more generated files in this PR are out of sync:

  • CRDs: Run make update-crds if CRD verification failed
  • RBAC: Run make generate-rbac if RBAC verification failed

Please regenerate the files locally and commit the changes.

Comment thread assets/active/metadata.yaml Outdated
Comment thread assets/active/metadata.yaml Outdated
Comment thread pkg/assets/registry_test.go
Comment thread pkg/engine/renderer.go
Signed-off-by: Michal Skrivanek <michal.skrivanek@redhat.com>
Assisted-by: claude-4.6-opus
Comment thread assets/active/machine-config/05-ksm-zero-only.yaml.tpl Outdated
Comment thread assets/active/machine-config/06-thp-tuning.yaml.tpl Outdated
@michalskrivanek
michalskrivanek force-pushed the ksm-thp branch 3 times, most recently from cc24563 to 115ee19 Compare August 18, 2026 13:50
Comment thread pkg/engine/renderer.go
Introduce TemplateParams (map[string]string) on AssetMetadata, passed to
templates as .Params. This allows metadata.yaml to parameterize shared
templates without engine changes per use case.
Add ConditionTypeTopology to gate assets on cluster topology fields
(e.g. hasSchedulableMasters), enabling conditional inclusion of assets
for compact/schedulable-master clusters.

Signed-off-by: Michal Skrivanek <michal.skrivanek@redhat.com>
Assisted-by: claude-4.6-opus
Allow assets to be gated on whether an HCO spec field is configured.
When the field is absent, null, or an empty map, the condition evaluates
to true (asset is included). This supports opt-in assets that should
only apply when the user has not explicitly configured the feature in HCO.

Signed-off-by: Michal Skrivanek <michal.skrivanek@redhat.com>
Assisted-by: claude-4.6-opus
Add KSM zero-pages-only and THP madvise tuning as opt-in MachineConfigs,
gated by annotations and hco-field-unconfigured conditions. Templates use
.Params.role from template_params to support both worker and master roles
from a single shared template. Master variants are conditionally included
via topology hasSchedulableMasters condition.
Includes cluster-monitoring ConfigMap for KSM PrometheusRule.

Signed-off-by: Michal Skrivanek <michal.skrivanek@redhat.com>
Assisted-by: claude-4.6-opus
Signed-off-by: Michal Skrivanek <michal.skrivanek@redhat.com>
Assisted-by: claude-4.6-opus
Replace static 04-psi-enable.yaml and conditional 05-psi-enable-master.yaml.tpl
with a single shared template using .Params.role. Master variant is now gated
by topology hasSchedulableMasters condition in metadata, consistent with
KSM and THP assets.

Signed-off-by: Michal Skrivanek <michal.skrivanek@redhat.com>
Assisted-by: claude-4.6-opus
@tiraboschi

Copy link
Copy Markdown
Member

/approve

@openshift-ci

openshift-ci Bot commented Aug 18, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tiraboschi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tiraboschi

Copy link
Copy Markdown
Member

/cherry-pick release-4.22

@openshift-cherrypick-robot

Copy link
Copy Markdown

@tiraboschi: once the present PR merges, I will cherry-pick it on top of release-4.22 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-4.22

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-merge-bot
openshift-merge-bot Bot merged commit 0171035 into openshift-virtualization:main Aug 18, 2026
7 checks passed
@openshift-cherrypick-robot

Copy link
Copy Markdown

@tiraboschi: #288 failed to apply on top of branch "release-4.22":

Applying: fix RBAC scanner to handle multi-line template comments
Applying: feat: add generic template_params and topology condition to asset engine
Using index info to reconstruct a base tree...
M	pkg/assets/registry.go
M	pkg/assets/registry_test.go
M	pkg/context/render_context.go
M	pkg/controller/platform_controller.go
M	pkg/engine/renderer.go
M	pkg/engine/renderer_test.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/assets/registry.go
Auto-merging pkg/assets/registry_test.go
Auto-merging pkg/context/render_context.go
Auto-merging pkg/controller/platform_controller.go
Auto-merging pkg/engine/renderer.go
Auto-merging pkg/engine/renderer_test.go
CONFLICT (content): Merge conflict in pkg/engine/renderer_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 feat: add generic template_params and topology condition to asset engine

Details

In response to this:

/cherry-pick release-4.22

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants