Skip to content

systemd: Write rounded CPU quota to cgroupfs#4

Merged
AkihiroSuda merged 1 commit into
opencontainers:mainfrom
hshiina:cpu-quota-round
Apr 11, 2025
Merged

systemd: Write rounded CPU quota to cgroupfs#4
AkihiroSuda merged 1 commit into
opencontainers:mainfrom
hshiina:cpu-quota-round

Conversation

@hshiina

@hshiina hshiina commented Mar 3, 2025

Copy link
Copy Markdown
Contributor

This is a carry of opencontainers/runc#4639.

When CPU quota is updated, the value is converted to CPUQuotaPerSecUSec property for passing to systemd. The value can be rounded in the following cases:

  • The value is rounded up to the nearest 10ms.
  • Depending on CPU period, the value may be rounded during division.

Because of this rounding, systemd and systemd driver may write different values to cgroupfs. In order to avoid this inconsistency, this fix makes systemd driver write the same rounded value to cgroupfs by calculating the value from CPUQuotaPerSecUSec.

Even if systemd writes CPU quota and CPU period to cgroupfs, systemd driver still needs to write to cgroupfs for a case where CPU period is updated to less than the minimum value. In this case, systemd accepts this value by adjusting CPU period while direct update by systemd driver fails. In order to keep this case invalid, systemd driver still needs to update cgroupfs.

Fixes opencontainers/runc#4622

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

  1. Why don't we just do
r = adjustResources(r)

at the very beginning of Set methods? This way we won't have to call convertToCpuQuotaPerSecUsec twice.

  1. We don't have CI in this repo yet, so this have to wait (until at least #3 is merged).

@kolyshkin

Copy link
Copy Markdown
Contributor

I would also add a comment to adjustResources to explain why it is needed.

When CPU quota is updated, the value is converted to CPUQuotaPerSecUSec
property for passing to systemd. The value can be rounded in the
following cases:
- The value is rounded up to the nearest 10ms.
- Depending on CPU period, the value may be rounded during division.

Because of this rounding, systemd and systemd driver may write
different values to cgroupfs. In order to avoid this inconsistency,
this fix makes systemd driver write the same rounded value to cgroupfs.

Even if systemd writes CPU quota and CPU period to cgroupfs, systemd
driver still needs to write to cgroupfs for a case where CPU period
is updated to less than the minimum value. In this case, systemd accepts
this value by adjusting CPU period while direct update by systemd driver
fails. In order to keep this case invalid, systemd driver still needs to
update cgroupfs.

Signed-off-by: Hironori Shiina <shiina.hironori@gmail.com>
@rata

rata commented Apr 4, 2025

Copy link
Copy Markdown
Member

@hshiina IIUC this didn't address the first comment here. Can you please address it? Or am I missing something?

@hshiina

hshiina commented Apr 7, 2025

Copy link
Copy Markdown
Contributor Author

@hshiina IIUC this didn't address the first comment here. Can you please address it? Or am I missing something?

At the first revision, I introduced adjustResources() to update resources before writing values to cgroupfs. Now, I removed adjustResources() in order to avoid calling convertToCpuQuotaPerSecUsec() twice. In the current approach, all required calculations are performed in addCPUQuota().

@hshiina

hshiina commented Apr 7, 2025

Copy link
Copy Markdown
Contributor Author
  1. Why don't we just do
r = adjustResources(r)

at the very beginning of Set methods? This way we won't have to call convertToCpuQuotaPerSecUsec twice.

I removed adjustResources(). Now, r.CpuQuota is updated in addCpuQuota().

@rata

rata commented Apr 7, 2025

Copy link
Copy Markdown
Member

Cool, sorry I missed it, I have not been following this PR.

@kolyshkin PTAL :)

@kolyshkin kolyshkin 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

@rata

rata commented Apr 11, 2025

Copy link
Copy Markdown
Member

@AkihiroSuda friendly ping? This fixes a bug people is hitting in Kubernetes

@AkihiroSuda

Copy link
Copy Markdown
Member

Two LGTMs, but the merge button seems unclickable w/o checking "bypass rules" 🤔

@AkihiroSuda

Copy link
Copy Markdown
Member

Let me uncheck "Require branches to be up to date before merging" in https://github.com/opencontainers/cgroups/settings/branch_protection_rules/60411775

@AkihiroSuda AkihiroSuda merged commit cad55c0 into opencontainers:main Apr 11, 2025
@rata

rata commented Apr 11, 2025

Copy link
Copy Markdown
Member

Do we need a release of this to include it in runc 1.3?

@kolyshkin

Copy link
Copy Markdown
Contributor

I can make a release but I'd like other PRs to be merged first.

@rata

rata commented Apr 14, 2025

Copy link
Copy Markdown
Member

Sure, this can be part of a patch release in 1.3 if we can't release this before final 1.3.0 :)

@rata

rata commented Apr 16, 2025

Copy link
Copy Markdown
Member

I think all code-related PRs are merged (open PRs are more about CI tweaks). Do I smell a release soon? :-D

kolyshkin added a commit to kolyshkin/runc that referenced this pull request Apr 29, 2025
For changes, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.2

Fix integration tests according to changes in [1] (now the CPU quota value set
is rounded the same way systemd does it).

[1]: opencontainers/cgroups#4
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/runc that referenced this pull request Apr 29, 2025
For changes, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.2

Fix integration tests according to changes in [1] (now the CPU quota value set
is rounded the same way systemd does it).

[1]: opencontainers/cgroups#4
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/runc that referenced this pull request May 3, 2025
For changes, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.2

Fix integration tests according to changes in [1] (now the CPU quota value set
is rounded the same way systemd does it).

[1]: opencontainers/cgroups#4
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/runc that referenced this pull request May 6, 2025
For changes, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.2

Fix integration tests according to changes in [1] (now the CPU quota value set
is rounded the same way systemd does it).

[1]: opencontainers/cgroups#4
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/runc that referenced this pull request May 13, 2025
For changes, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.2

Fix integration tests according to changes in [1] (now the CPU quota value set
is rounded the same way systemd does it).

[1]: opencontainers/cgroups#4
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
jaredledvina pushed a commit to DataDog/runc that referenced this pull request Sep 23, 2025
For changes, see https://github.com/opencontainers/cgroups/releases/tag/v0.0.2

Fix integration tests according to changes in [1] (now the CPU quota value set
is rounded the same way systemd does it).

[1]: opencontainers/cgroups#4
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
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.

systemd driver updates CPU quota inconsitently

4 participants