libctr/fs2: Initialize MaxUsage field with memory.peak value#4038
libctr/fs2: Initialize MaxUsage field with memory.peak value#4038haircommander wants to merge 1 commit into
Conversation
| // Ignore EEXIST as there's no swap accounting | ||
| // if kernel CONFIG_MEMCG_SWAP is not set or | ||
| // swapaccount=0 kernel boot parameter is given. | ||
| return cgroups.MemoryData{}, nil |
There was a problem hiding this comment.
I think this line should be questioned. I think it'd be better if we continued to collect if there was an error and returned whatever we found at the end
There was a problem hiding this comment.
Not quite. This is for case of name == "swap" (which is implicit here), meaning we're trying to read memory.swap.* values -- and they all are either present or not, so we bail out early when getting ENOENT from open("memory.swap.current").
OTOH if *.peak counter is optional, the logic should be changed. Is it?
While at it, we can always return memoryData not cgroups.MemoryData.
(BTW I took a look at CONFIG_MEMCG_SWAP and it was dropped from Linux v6.1, but there's still CONFIG_SWAP)
There was a problem hiding this comment.
Not quite. This is for case of name == "swap" (which is implicit here), meaning we're trying to read
memory.swap.*values -- and they all are either present or not, so we bail out early when getting ENOENT from open("memory.swap.current").
Meaning, I'd drop the second commit in this PR (and maybe add a better comment explaining why we're bailing out early).
There was a problem hiding this comment.
*peak is added in kernel 5.14--so not yet in any el variants (it's being backported to centos 9 now) which is why I think the second commit is the correct behavior
There was a problem hiding this comment.
For peak, yes. So it should be like this:
- if
memory.swap.currentis not available, return empty set and no error (that's what the current code does); - if
*.peakis not available, return what we have collected so far.
There was a problem hiding this comment.
So, maybe something like this
if err != nil {
if os.IsNotExist(err) {
// Swap accounting is optional, so return early if absent.
if name == "swap" {
err = nil
}
// Peak usage is only available since kernel v5.14.
if strings.HasSuffix(v.name, "peak") {
err = nil
}
return memoryData, err
}
}(plus add a comment above saying the order is important)
There was a problem hiding this comment.
Or, for better readability,
- if name == "swap" {
+ if name == "swap" { // memory.swap.current not found.or even
- if name == "swap" {
+ if f.name == "memory.swap.current" {4705c0a to
94655ab
Compare
|
Total memory max usage != memory.peak + memory.swap.peak |
94655ab to
9782b83
Compare
as well as rework the function to reduce duplication, and update the test for it Signed-off-by: Peter Hunt <pehunt@redhat.com>
9782b83 to
c28247d
Compare
|
I didn't notice #4010! convo is more developed over there, so I can close this in favor of that |
as well as rework the function to reduce duplication, and update the test for it