-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: memory: topology: expose per-numa hugepages
This patch wants to add hugepages informations on topology.Node, so we can have per-NUMA-zone information. WIP: docs are missing, and so are representation helpers. Signed-off-by: Francesco Romani <[email protected]>
- Loading branch information
Showing
7 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
// | ||
|
||
package memory | ||
|
||
// TODO review | ||
type Hugepages struct { | ||
SizeKB int | ||
FreeAmount int | ||
TotalAmount int | ||
} | ||
|
||
// TODO: String() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
// | ||
|
||
package memory | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"github.com/jaypipes/ghw/pkg/context" | ||
"github.com/jaypipes/ghw/pkg/linuxpath" | ||
"github.com/jaypipes/ghw/pkg/util" | ||
) | ||
|
||
func HugepagesForNode(ctx *context.Context, nodeID int) ([]*Hugepages, error) { | ||
paths := linuxpath.New(ctx) | ||
path := filepath.Join( | ||
paths.SysDevicesSystemNode, | ||
fmt.Sprintf("node%d", nodeID), | ||
"hugepages", | ||
) | ||
hugepages := []*Hugepages{} | ||
|
||
entries, err := ioutil.ReadDir(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, entry := range entries { | ||
entryName := entry.Name() | ||
entryPath := filepath.Join(path, entryName) | ||
var hugepageSizeKB int | ||
if n, err := fmt.Sscanf(entryName, "hugepages-%dkB", &hugepageSizeKB); n != 1 || err != nil { | ||
ctx.Warn("malformed entry on %q: %v", entryPath, err) | ||
continue | ||
} | ||
|
||
freeCount := util.SafeIntFromFile(ctx, filepath.Join(path, entryName, "free_hugepages")) | ||
if freeCount < 0 { | ||
ctx.Warn("failed to read free hugepages on %q", entryPath) | ||
continue | ||
} | ||
|
||
totalCount := util.SafeIntFromFile(ctx, filepath.Join(path, entryName, "nr_hugepages")) | ||
if totalCount < 0 { | ||
ctx.Warn("failed to read total hugepages on %q", entryPath) | ||
continue | ||
} | ||
|
||
hugepages = append(hugepages, &Hugepages{ | ||
SizeKB: hugepageSizeKB, | ||
FreeAmount: freeCount, | ||
TotalAmount: totalCount, | ||
}) | ||
} | ||
|
||
return hugepages, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-154 Bytes
(100%)
testdata/snapshots/linux-amd64-8581cf3a529e5d8b97ea876eade2f60d.tar.gz
Binary file not shown.