Skip to content

Commit

Permalink
Merge branch 'main' of github.com:victoryang00/runc
Browse files Browse the repository at this point in the history
Signed-off-by: victoryang00 <[email protected]>
  • Loading branch information
victoryang00 committed Jul 28, 2023
2 parents daede0d + 2fbc803 commit 770b509
Show file tree
Hide file tree
Showing 3 changed files with 567 additions and 35 deletions.
112 changes: 77 additions & 35 deletions libcontainer/cgroups/fs2/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fs2
import (
"bufio"
"errors"
"io/ioutil"

Check failure on line 6 in libcontainer/cgroups/fs2/memory.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"math"
"os"
"strconv"
Expand Down Expand Up @@ -130,7 +131,9 @@ func statMemory(dirPath string, stats *cgroups.Stats) error {
swapUsage.Limit += memoryUsage.Limit
}
stats.MemoryStats.SwapUsage = swapUsage

if stats.MemoryStats.PageUsageByNUMA.Hierarchical.Total.Total != 0 {
stats.MemoryStats.UseHierarchy = true
}
return nil
}

Expand Down Expand Up @@ -241,33 +244,34 @@ func getPageUsageByNUMAV2(path string) (cgroups.PageUsageByNUMA, error) {
}
defer fd.Close()

// anon N0=139022336 N1=2760704
// file N0=449581056 N1=0
// kernel_stack N0=3670016 N1=0
// pagetables N0=4116480 N1=0
// sec_pagetables N0=0 N1=0
// shmem N0=0 N1=0
// file_mapped N0=55029760 N1=0
// file_dirty N0=0 N1=0
// file_writeback N0=0 N1=0
// swapcached N0=0 N1=0
// anon_thp N0=0 N1=0
// file_thp N0=0 N1=0
// shmem_thp N0=0 N1=0
// inactive_anon N0=138956800 N1=2752512
// active_anon N0=65536 N1=8192
// inactive_file N0=14770176 N1=0
// active_file N0=434810880 N1=0
// unevictable N0=0 N1=0
// slab_reclaimable N0=2358224 N1=11088
// slab_unreclaimable N0=2672352 N1=544144
// workingset_refault_anon N0=0 N1=0
// workingset_refault_file N0=0 N1=0
// workingset_activate_anon N0=0 N1=0
// workingset_activate_file N0=0 N1=0
// workingset_restore_anon N0=0 N1=0
// workingset_restore_file N0=0 N1=0
// workingset_nodereclaim N0=0 N1=0
// https://docs.kernel.org/admin-guide/cgroup-v2.html
// anon N0=<> N1=<> # The Anon page size in byte which equals to page_num * page_size
// file N0=<> N1=0 # The File page size in byte which equals to file_mmaped_page_num * page_size
// kernel_stack N0=<> N1=0 # The Kernel's stack occupation
// pagetables N0=<> N1=0 # The total number of pagetable entry been occupied
// sec_pagetables N0=<> N1=<>
// shmem N0=<> N1=<>
// file_mapped N0=<> N1=<> # file page breakdown
// file_dirty N0=<> N1=<> # file page breakdown
// file_writeback N0=<> N1=<> # file page breakdown
// swapcached N0=<> N1=<>
// anon_thp N0=<> N1=<> # The transparent huge page occupation
// file_thp N0=<> N1=<> # The transparent huge page occupation
// shmem_thp N0=<> N1=<> # The transparent huge page occupation
// inactive_anon N0=<> N1=<>
// active_anon N0=<> N1=<>
// inactive_file N0=<> N1=<>
// active_file N0=<> N1=<>
// unevictable N0=<> N1=<>
// slab_reclaimable N0=<> N1=<>
// slab_unreclaimable N0=<> N1=<>
// workingset_refault_anon N0=<> N1=<>
// workingset_refault_file N0=<> N1=<>
// workingset_activate_anon N0=<> N1=<>
// workingset_activate_file N0=<> N1=<>
// workingset_restore_anon N0=<> N1=<>
// workingset_restore_file N0=<> N1=<>
// workingset_nodereclaim N0=<> N1=<>

scanner := bufio.NewScanner(fd)
for scanner.Scan() {
Expand All @@ -285,6 +289,10 @@ func getPageUsageByNUMAV2(path string) (cgroups.PageUsageByNUMA, error) {
}
field.Nodes = map[uint8]uint64{}
} else { // Subsequent columns: key is N<id>, val is usage.
if len(byNode) != 2 {
// This is definitely an error.
return stats, malformedLine(path, file, line)
}
val := byNode[1]
if len(key) < 2 || key[0] != 'N' {
// This is definitely an error.
Expand All @@ -305,25 +313,59 @@ func getPageUsageByNUMAV2(path string) (cgroups.PageUsageByNUMA, error) {
}

}
stats.Total.Total = stats.File.Total + stats.Anon.Total
stats.Total.Nodes = map[uint8]uint64{}
for k, v := range stats.File.Nodes {
stats.Total.Nodes[k] = v + stats.Anon.Nodes[k]
}
}
if err := scanner.Err(); err != nil {
return cgroups.PageUsageByNUMA{}, &parseError{Path: path, File: file, Err: err}
}

files, err := ioutil.ReadDir(path)
if err != nil {
return stats, err
}
// hierarchical stats in subdirectory
for _, file := range files {
if file.IsDir() {
stat_tmp, err := getPageUsageByNUMAV2(path + "/" + file.Name())
if err != nil {
return stats, err
}
if stats.Hierarchical.Total.Total == 0 {
stats.Hierarchical.Total.Nodes = map[uint8]uint64{}
stats.Hierarchical.Anon.Nodes = map[uint8]uint64{}
stats.Hierarchical.File.Nodes = map[uint8]uint64{}
stats.Hierarchical.Unevictable.Nodes = map[uint8]uint64{}
}
stats.Hierarchical.Total.Total += stat_tmp.Total.Total
stats.Hierarchical.Anon.Total += stat_tmp.Anon.Total
stats.Hierarchical.File.Total += stat_tmp.File.Total
stats.Hierarchical.Unevictable.Total += stat_tmp.Unevictable.Total
for k, v := range stat_tmp.Total.Nodes {
stats.Hierarchical.Total.Nodes[k] += v
}
for k, v := range stat_tmp.Anon.Nodes {
stats.Hierarchical.Anon.Nodes[k] += v
}
for k, v := range stat_tmp.File.Nodes {
stats.Hierarchical.File.Nodes[k] += v
}
for k, v := range stat_tmp.Unevictable.Nodes {
stats.Hierarchical.Unevictable.Nodes[k] += v
}
}
}
return stats, nil
}

func getNUMAFieldV2(stats *cgroups.PageUsageByNUMA, name string) *cgroups.PageStats {
switch name {
case "pagetables":
return &stats.Total
case "anon":
return &stats.Anon
case "file_mapped":
return &stats.File
case "file_dirty":
return &stats.File
case "file_writeback":
case "file":
return &stats.File
case "unevictable":
return &stats.Unevictable
Expand Down
Loading

0 comments on commit 770b509

Please sign in to comment.