Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

victoryang00
Copy link

Add the parsing for /sys/fs/cgroup/memory.numa_stat and add to the corresponding PageUsageByNUMA.

@lifubang
Copy link
Member

lifubang commented Jul 27, 2023

Thanks for your contribution. NumaStat has been implemented in cgroup v1, I think it's reasonable to implement it in cgroup v2. Could you please add a unit test case in memory_test.go? Thanks.

@victoryang00
Copy link
Author

Added memory tests.

@@ -219,3 +227,147 @@ func statsFromMeminfo(stats *cgroups.Stats) error {

return nil
}

func getPageUsageByNUMAV2(path string) (cgroups.PageUsageByNUMA, error) {
Copy link
Contributor

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.

Copy link
Author

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 {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Author

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 {
Copy link
Contributor

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) {
Copy link
Contributor

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.

Comment on lines +205 to +234
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)
}
Copy link
Contributor

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) {
Copy link
Contributor

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]>
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.

None yet

3 participants