Skip to content

Commit

Permalink
review fixes: renaming fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Traumeel committed Sep 18, 2024
1 parent edbd504 commit b65cd36
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions pkg/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Module struct {
Vendor string `json:"vendor"`
}

// HugePage describes huge page info
type HugePage struct {
// HugePageAmounts describes huge page info
type HugePageAmounts struct {
Total int64 `json:"total"`
Free int64 `json:"free"`
Surplus int64 `json:"surplus"`
Expand All @@ -47,13 +47,13 @@ type Area struct {
TotalUsableBytes int64 `json:"total_usable_bytes"`
// An array of sizes, in bytes, of memory pages supported in this area
SupportedPageSizes []uint64 `json:"supported_page_sizes"`
// Default system huge pages size, in bytes
// Default system huge page size, in bytes
DefaultHugePageSize uint64 `json:"default_huge_page_size"`
// Amount of memory, in bytes, consumed by huge pages of all sizes.
HugeTLBSize int64 `json:"huge_tlb_size"`
// Amount of memory, in bytes, consumed by huge pages of all sizes
TotalHugePageBytes int64 `json:"total_huge_page_bytes"`
// Huge page info by size
HugePages map[uint64]*HugePage `json:"huge_pages"`
Modules []*Module `json:"modules"`
HugePageAmountsBySize map[uint64]*HugePageAmounts `json:"huge_page_amounts_by_size"`
Modules []*Module `json:"modules"`
}

// String returns a short string with a summary of information for this memory
Expand Down
30 changes: 15 additions & 15 deletions pkg/memory/memory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ func (i *Info) load() error {
}
i.SupportedPageSizes, _ = memorySupportedPageSizes(paths.SysKernelMMHugepages)
i.DefaultHugePageSize, _ = memoryDefaultHPSizeFromPath(paths.ProcMeminfo)
i.HugeTLBSize, _ = memoryHugeTLBFromPath(paths.ProcMeminfo)
hugePage := make(map[uint64]*HugePage)
i.TotalHugePageBytes, _ = memoryHugeTLBFromPath(paths.ProcMeminfo)
hugePageAmounts := make(map[uint64]*HugePageAmounts)
for _, p := range i.SupportedPageSizes {
info, err := memoryHPInfo(paths.SysKernelMMHugepages, p)
if err != nil {
return err
}
hugePage[p] = info
hugePageAmounts[p] = info
}
i.HugePages = hugePage
i.HugePageAmountsBySize = hugePageAmounts
return nil
}

Expand Down Expand Up @@ -116,27 +116,27 @@ func AreaForNode(ctx *context.Context, nodeID int) (*Area, error) {
return nil, err
}

hugeTlb, err := memoryHugeTLBFromPath(paths.ProcMeminfo)
totHPSize, err := memoryHugeTLBFromPath(paths.ProcMeminfo)
if err != nil {
return nil, err
}

hugePages := make(map[uint64]*HugePage)
hugePageAmounts := make(map[uint64]*HugePageAmounts)
for _, p := range supportedHP {
info, err := memoryHPInfo(filepath.Join(path, "hugepages"), p)
if err != nil {
return nil, err
}
hugePages[p] = info
hugePageAmounts[p] = info
}

return &Area{
TotalPhysicalBytes: totPhys,
TotalUsableBytes: totUsable,
SupportedPageSizes: supportedHP,
DefaultHugePageSize: defHPSize,
HugeTLBSize: hugeTlb,
HugePages: hugePages,
TotalPhysicalBytes: totPhys,
TotalUsableBytes: totUsable,
SupportedPageSizes: supportedHP,
DefaultHugePageSize: defHPSize,
TotalHugePageBytes: totHPSize,
HugePageAmountsBySize: hugePageAmounts,
}, nil
}

Expand Down Expand Up @@ -301,7 +301,7 @@ func memorySupportedPageSizes(hpDir string) ([]uint64, error) {
return out, nil
}

func memoryHPInfo(hpDir string, sizeBytes uint64) (*HugePage, error) {
func memoryHPInfo(hpDir string, sizeBytes uint64) (*HugePageAmounts, error) {
// In linux huge page info can be obtained in several places
// /sys/kernel/mm/hugepages/hugepages-{pagesize}kb/ directory, which contains
// nr_hugepages
Expand Down Expand Up @@ -356,7 +356,7 @@ func memoryHPInfo(hpDir string, sizeBytes uint64) (*HugePage, error) {
}
}

return &HugePage{
return &HugePageAmounts{
Total: total,
Free: free,
Surplus: surplus,
Expand Down
4 changes: 2 additions & 2 deletions pkg/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestMemory(t *testing.T) {
t.Fatalf("Expected >0 default hugepagesize, but got 0")
}

if len(sps) != len(mem.HugePages) {
t.Fatalf("Expected %d hugepages, but got %d", len(sps), len(mem.HugePages))
if len(sps) != len(mem.HugePageAmountsBySize) {
t.Fatalf("Expected %d hugepages, but got %d", len(sps), len(mem.HugePageAmountsBySize))
}
}
4 changes: 2 additions & 2 deletions pkg/topology/topology_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func TestTopologyPerNUMAMemory(t *testing.T) {
if node.Memory.DefaultHugePageSize == 0 {
t.Fatalf("unexpected default HP size for node %d", node.ID)
}
if len(node.Memory.HugePages) != 2 {
t.Fatalf("expected 2 huge page info records, but got '%d' for node %d", len(node.Memory.HugePages), node.ID)
if len(node.Memory.HugePageAmountsBySize) != 2 {
t.Fatalf("expected 2 huge page info records, but got '%d' for node %d", len(node.Memory.HugePageAmountsBySize), node.ID)
}
}
}

0 comments on commit b65cd36

Please sign in to comment.