-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add numa_stat for cgroup v2 #3942
base: main
Are you sure you want to change the base?
Conversation
571eb6c
to
daede0d
Compare
Thanks for your contribution. |
acdbb94
to
8394e04
Compare
Added memory tests. |
0525481
to
2eef6ac
Compare
@@ -219,3 +227,147 @@ func statsFromMeminfo(stats *cgroups.Stats) error { | |||
|
|||
return nil | |||
} | |||
|
|||
func getPageUsageByNUMAV2(path string) (cgroups.PageUsageByNUMA, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need to have V2 in the function name, this package only contains cgroup v2 code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
@@ -13,6 +13,10 @@ import ( | |||
|
|||
type parseError = fscommon.ParseError | |||
|
|||
func malformedLine(path, file, line string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You copied the function over, without copying its docstring.
Perhaps it's better to move it to fscommon and make it available for all cgroups code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do something like this, please make it as a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
return stats, nil | ||
} | ||
|
||
func getNUMAFieldV2(stats *cgroups.PageUsageByNUMA, name string) *cgroups.PageStats { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here about V2 suffix.
"github.com/opencontainers/runc/libcontainer/cgroups" | ||
) | ||
|
||
func expectMemoryStatEquals(t *testing.T, expected, actual cgroups.MemoryStats) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: maybe move this to fscommon_test and make available for both fs and fs2?
If you'll do something like this, please do it as a separate commit.
if err := os.WriteFile(statPath, []byte(memoryStatContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.WriteFile(maxPath, []byte(memoryMaxUsageContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.WriteFile(lowPath, []byte(memoryLimitContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.WriteFile(currentPath, []byte(memoryUsageContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.WriteFile(swapMaxPath, []byte(memoryMaxUsageContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.WriteFile(numaStatPath, []byte(memoryNUMAStatContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.MkdirAll(fakesub1CgroupDir, 0o755); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.WriteFile(subnuma1StatPath, []byte(memoryNUMAStatContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.MkdirAll(fakesub2CgroupDir, 0o755); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.WriteFile(subnuma2StatPath, []byte(memoryNUMAStatContents), 0o644); err != nil { | ||
t.Fatal(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also move writeFileContents
to fscommon under some _test.go file and re-use it from here.
|
||
func expectPageUsageByNUMAEquals(t *testing.T, expected, actual cgroups.PageUsageByNUMA) { | ||
t.Helper() | ||
if !reflect.DeepEqual(expected.Total, actual.Total) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why not reflect.DeepEqual(expected, actual)
?
Signed-off-by: victoryang00 <[email protected]>
Add the parsing for
/sys/fs/cgroup/memory.numa_stat
and add to the correspondingPageUsageByNUMA
.