Skip to content

Conversation

@xueruini
Copy link

If either memory.high, memory.low, memory.max, or memory.min is not available in V2, the current code will panic, which might break user applications unintentionally. This PR tries to return the default value instead.

@Tim-Zhang Tim-Zhang requested a review from liubin July 3, 2023 14:15
@Tim-Zhang
Copy link
Member

Tim-Zhang commented Aug 1, 2023

I am not sure if it is ok to use default instead of panic, @lifupan PTAL, @liubin

alexman-stripe added a commit to alexman-stripe/cgroups-rs that referenced this pull request Sep 10, 2024
When containers are terminated, cgroup v2 memory metrics under /sys/fs/cgroup may disappear.
Previously, kata-agent assumed these metrics always exist, leading to panics as reported in kata-containers#138.

This commit returns default value (0) when memory metric files are missing.
This behaviour aligns with cgroup v1, which also defaults to 0 memory metric files are missing:
- Memory.limit_in_bytes which maps to m.max https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L635
- Memory.soft_limit_in_bytes which maps to m.low https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L661
- MemSwap.fail_cnt: https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L631

Submitting a new PR because kata-containers#116 does not handle MemSwap.fail_cnt, which will also cause panic.
alexman-stripe added a commit to alexman-stripe/cgroups-rs that referenced this pull request Sep 10, 2024
When containers are terminated, cgroup v2 memory metrics under /sys/fs/cgroup may disappear.
Previously, kata-agent assumed these metrics always exist, leading to panics as reported in kata-containers#138.

This commit returns default value (0) when memory metric files are missing.
This behaviour aligns with cgroup v1, which also defaults to 0 memory metric files are missing:
- Memory.limit_in_bytes which maps to m.max https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L635
- Memory.soft_limit_in_bytes which maps to m.low https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L661
- MemSwap.fail_cnt: https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L631

Submitting a new PR because kata-containers#116 does not handle MemSwap.fail_cnt, which will also cause panic.
alexman-stripe added a commit to alexman-stripe/cgroups-rs that referenced this pull request Sep 11, 2024
When containers are terminated, cgroup v2 memory metrics under /sys/fs/cgroup may disappear.
Previously, kata-agent assumed these metrics always exist, leading to panics as reported in kata-containers#138.

This commit returns default value (0) when memory metric files are missing.
This behaviour aligns with cgroup v1, which also defaults to 0 memory metric files are missing:
- Memory.limit_in_bytes which maps to m.max https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L635
- Memory.soft_limit_in_bytes which maps to m.low https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L661
- MemSwap.fail_cnt: https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L631

Submitting a new PR because kata-containers#116 does not handle MemSwap.fail_cnt, which will also cause panic.

Signed-off-by: Alex Man <[email protected]>
oguzbilgener pushed a commit to oguzbilgener/cgroups-rs that referenced this pull request Mar 14, 2025
When containers are terminated, cgroup v2 memory metrics under /sys/fs/cgroup may disappear.
Previously, kata-agent assumed these metrics always exist, leading to panics as reported in kata-containers#138.

This commit returns default value (0) when memory metric files are missing.
This behaviour aligns with cgroup v1, which also defaults to 0 memory metric files are missing:
- Memory.limit_in_bytes which maps to m.max https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L635
- Memory.soft_limit_in_bytes which maps to m.low https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L661
- MemSwap.fail_cnt: https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L631

Submitting a new PR because kata-containers#116 does not handle MemSwap.fail_cnt, which will also cause panic.

Signed-off-by: Alex Man <[email protected]>
@facetious
Copy link

I am not sure if it is ok to use default instead of panic, @lifupan PTAL, @liubin

It is not appropriate to use "max" as the default of all fields. It is the default of some fields, but some other fields default to 0. Care should be taken when suggesting a default here, preferably referencing the kernel version and documentation.

@lifupan
Copy link
Member

lifupan commented May 28, 2025

I am not sure if it is ok to use default instead of panic, @lifupan PTAL, @liubin

It is not appropriate to use "max" as the default of all fields. It is the default of some fields, but some other fields default to 0. Care should be taken when suggesting a default here, preferably referencing the kernel version and documentation.

Yeah, I agree, it should keep align with it's default value defined in the cgroup v2 instead of "max" value.

@fidencio
Copy link
Member

Yeah, I agree, it should keep align with it's default value defined in the cgroup v2 instead of "max" value.

I've adjusted to the actual default values.

@fidencio fidencio force-pushed the fix-mem-panic branch 4 times, most recently from 3cccfc8 to 75887f3 Compare May 28, 2025 20:53
fidencio and others added 3 commits May 28, 2025 23:02
I'm not fmiliar with this crate, so let's just ignore the warning for
now instead of removing the code.

Signed-off-by: Fabiano Fidêncio <[email protected]>
When containers are terminated, cgroup v2 memory metrics under
/sys/fs/cgroup may disappear.  Previously, kata-agent assumed these
metrics always exist, leading to panics as reported in
kata-containers#138.

This commit returns default value (0) when memory metric files are
missing.  This behaviour aligns with cgroup v1, which also defaults to 0
memory metric files are missing:
- Memory.limit_in_bytes which maps to m.max
  https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L635
- Memory.soft_limit_in_bytes which maps to m.low
  https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L661
- MemSwap.fail_cnt:
  https://github.com/kata-containers/cgroups-rs/blob/main/src/memory.rs#L631

Signed-off-by: Ruini Xue <[email protected]>
Signed-off-by: Alex Man <[email protected]>
Signed-off-by: Fabiano Fidêncio <[email protected]>
Otherwise it simply breaks.

Signed-off-by: Alex Man <[email protected]>
Signed-off-by: Fabiano Fidêncio <[email protected]>
@lifupan
Copy link
Member

lifupan commented May 29, 2025

/retest

@Tim-Zhang Tim-Zhang closed this May 29, 2025
@Tim-Zhang Tim-Zhang reopened this May 29, 2025
@Tim-Zhang Tim-Zhang added the enhancement New feature or request label May 29, 2025
@fidencio
Copy link
Member

For some reason the WIP and Commit Message Checks are not running.
I'm bypassing the rules and merging it.

Thanks for the reviews.

@fidencio fidencio merged commit db82247 into kata-containers:main May 29, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants