Skip to content

Conversation

vickiegpt
Copy link

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

@vickiegpt vickiegpt force-pushed the main branch 4 times, most recently from 571eb6c to daede0d Compare July 21, 2023 22:30
@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.

@vickiegpt vickiegpt force-pushed the main branch 3 times, most recently from acdbb94 to 8394e04 Compare July 28, 2023 05:19
@vickiegpt
Copy link
Author

Added memory tests.

@vickiegpt vickiegpt force-pushed the main branch 4 times, most recently from 0525481 to 2eef6ac Compare July 28, 2023 20:13
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.


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.

3 participants