Skip to content

bootloader: Simplify tuning of rpm-ostree kargs - #690

Merged
yarda merged 2 commits into
redhat-performance:masterfrom
zacikpa:rpm-ostree-fix
Jul 23, 2025
Merged

yarda merged 2 commits into
redhat-performance:masterfrom
zacikpa:rpm-ostree-fix

Conversation

@zacikpa

@zacikpa zacikpa commented Sep 27, 2024

Copy link
Copy Markdown
Contributor

This PR aims to simplify the tuning of kernel parameters in rpm-ostree systems, which has some major flaws:

  1. It does not respect the claim that existing kernel parameters are left untouched.
  2. It does not append new kernel parameters in the order specified in the profile.

The new implementation is much simpler, but it also restricts the user more, since it disallows replacing existing kernel parameters.

Setting to WIP, since I'm still doing testing on Fedora CoreOS virtual machines.

@zacikpa
zacikpa marked this pull request as ready for review September 30, 2024 09:09
@zacikpa
zacikpa requested a review from yarda September 30, 2024 09:09
@yarda

yarda commented Dec 11, 2024

Copy link
Copy Markdown
Contributor

The new implementation is much simpler, but it also restricts the user more, since it disallows replacing existing kernel parameters.

There is an older grub convention that TuneD cannot change/delete any karg it didn't add itself, so I think this restriction is OK.

One question, what happen if there is running deployment or the rpm-ostree is busy. IMHO previously, it waited until it's idle. Is the request processed later or is there failure in such case?

@zacikpa

zacikpa commented Dec 11, 2024

Copy link
Copy Markdown
Contributor Author

One question, what happen if there is running deployment or the rpm-ostree is busy. IMHO previously, it waited until it's idle. Is the request processed later or is there failure in such case?

I will re-check that, can't remember if I tested such cases or not, thanks.

@yarda

yarda commented Jan 16, 2025

Copy link
Copy Markdown
Contributor

One question, what happen if there is running deployment or the rpm-ostree is busy. IMHO previously, it waited until it's idle. Is the request processed later or is there failure in such case?

I will re-check that, can't remember if I tested such cases or not, thanks.

Is the behaviour the same?

@zacikpa

zacikpa commented Jan 17, 2025 •

Copy link
Copy Markdown
Contributor Author

One question, what happen if there is running deployment or the rpm-ostree is busy. IMHO previously, it waited until it's idle. Is the request processed later or is there failure in such case?

I will re-check that, can't remember if I tested such cases or not, thanks.

Is the behaviour the same?

Looking at it now, I likely factored out that code by accident. I will add it back.
Edit: Or I rather misunderstood what the code did. If there is a new active deployment, it's ok to proceed, but if there is a transaction in progress (like creating new deployment), then we should wait.

@zacikpa

zacikpa commented Jan 31, 2025

Copy link
Copy Markdown
Contributor Author

Updated the code to handle errors better and re-added the wait until rpm-ostree becomes idle.

@jmencak

jmencak commented Mar 31, 2025 •

Copy link
Copy Markdown
Contributor

I've tested this PR on RHEL AI 1.4 and apart from very long times (cca 1 minute) to add/remove kernel parameters I did not find any issues. The very long times seem to be an rpm-ostree issue.

Edit: this seems to lower the long delays in rpm-ostree by roughly 6x for me (from 1 minute to 10s).

@zacikpa zacikpa closed this May 16, 2025
@zacikpa

zacikpa commented May 19, 2025 •

Copy link
Copy Markdown
Contributor Author

I adjusted the handling of kargs in no-daemon mode: before appending kargs from a profile, TuneD removes any kargs that may be present from previous profiles. This should be consistent with how TuneD behaves on traditional package-based systems, where the entire grub configuration file is overwritten.

@zacikpa

zacikpa commented May 19, 2025

Copy link
Copy Markdown
Contributor Author

Closed this on accident, reopening.

@zacikpa zacikpa reopened this May 19, 2025
@cgwalters

Copy link
Copy Markdown
Contributor

One thing I would note here is that with bootc we are also now supporting modifying kargs at container build time via https://docs.fedoraproject.org/en-US/bootc/kernel-args/#_via_usrlibbootckargs_d

This is a totally new capability vs what came before with (rpm-)ostree.

So in a world where we're running tuned at build time to execute on a profile, it could write out e.g. /usr/lib/bootc/kargs.d/20-tuned.toml or so. The key benefit of this is that tuned doesn't need to reconcile anything - bootc takes care of that.

@richm

richm commented May 20, 2025 •

Copy link
Copy Markdown

One thing I would note here is that with bootc we are also now supporting modifying kargs at container build time via https://docs.fedoraproject.org/en-US/bootc/kernel-args/#_via_usrlibbootckargs_d

This is a totally new capability vs what came before with (rpm-)ostree.

So in a world where we're running tuned at build time to execute on a profile, it could write out e.g. /usr/lib/bootc/kargs.d/20-tuned.toml or so. The key benefit of this is that tuned doesn't need to reconcile anything - bootc takes care of that.

Thanks - @martinpitt this is good to know when you get to converting the bootloader system role to work at container build time - also note that for TOML formatting we implemented an Ansible filter plugin for the podman role to convert data types to their TOML representation - https://github.com/linux-system-roles/podman/tree/main/filter_plugins

@cgwalters cgwalters 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.

I give this only a somewhat superficial review, it seems sane. I think it's worth calling out that there's very similar reconciliation logic that lives in https://github.com/openshift/machine-config-operator/blob/b1b4c729adbd8d7bd20c1fd3ae7801e5fa23230b/pkg/daemon/update.go#L1757

Now again kargs are very complex because we have the use case of both machine-specific or generic kargs embedded in bootc images, but I really hope for as many use cases as possible we can go to the kargs-in-container path because it dramatically simplifies this reconciliation logic.

if d is None:
"""Apply kernel parameter tuning in a rpm-ostree system."""
appended_kargs = self._get_appended_rpm_ostree_kargs()
profile_kargs = self._cmdline_val.split()

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.

This is a pre-existing issue but I think something to followup on at some point here is that just using split() on kargs will incorrectly handle quoted kernel arguments that contain embedded whitespace. This has been rare IME. But probably worth at least having "parse_kargs" function that can be updated in one place when we do fix this.

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.

Good catch. This also applies to package mode systems, I'll create an issue for it.

log.error("Not updating kernel arguments, could not read the current ones.")
return
# Ignore kargs previously appended by TuneD, these will be removed later.
non_tuned_kargs = active_kargs.split()

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.

Ditto here.

zacikpa added 2 commits May 22, 2025 15:13
The bootloader plugin claims that it does not mess
with existing kernel parameters; make sure we adhere
to that also for rpm-ostree systems:

1. Only append a new karg if the same key=value pair
does not already appear in kernel parameters. If we would
duplicate it, it would not be possible to determine which
one to delete when unapplying the profile.

2. Do not delete existing key=value pairs when the profile
adds a karg with another value for the key. A single key can
appear multiple times in the kernel parameter list with different
values.

Also make sure new kargs are added exactly in the order in which
they appear in the profile. This is especially important for kargs
related to hugepages.

Resolves: RHEL-45836
If TuneD-appended kargs are present and do not match
the kargs to be appended, we should remove them. This
can happen if there was no profile rollback, e.g.,
when using the no-daemon mode.

Resolves: RHEL-86814
@zacikpa

zacikpa commented May 28, 2025

Copy link
Copy Markdown
Contributor Author

Thank you for the comments, @cgwalters, much appreciated.

One thing I would note here is that with bootc we are also now supporting modifying kargs at container build time via https://docs.fedoraproject.org/en-US/bootc/kernel-args/#_via_usrlibbootckargs_d

This is a totally new capability vs what came before with (rpm-)ostree.

So in a world where we're running tuned at build time to execute on a profile, it could write out e.g. /usr/lib/bootc/kargs.d/20-tuned.toml or so. The key benefit of this is that tuned doesn't need to reconcile anything - bootc takes care of that.

Is there a way to reliably detect that we are in this scenario, i.e., in a bootc container being built?

@cgwalters

Copy link
Copy Markdown
Contributor

Is there a way to reliably detect that we are in this scenario, i.e., in a bootc container being built?

systemd-detect-virt -c is easiest

@yarda

yarda commented May 28, 2025

Copy link
Copy Markdown
Contributor

IMHO in TuneD we use virt-what tool a lot, maybe it can also detect it (I didn't try).

@cgwalters

Copy link
Copy Markdown
Contributor

xref bootc-dev/bootc#899

@yarda yarda 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.

LGTM, it's improvement.

@yarda

yarda commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

So in a world where we're running tuned at build time to execute on a profile, it could write out e.g. /usr/lib/bootc/kargs.d/20-tuned.toml or so. The key benefit of this is that tuned doesn't need to reconcile anything - bootc takes care of that.

This can be handled in future PRs.

@yarda
yarda merged commit b208ff4 into redhat-performance:master Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants