diff --git a/machine/machine.go b/machine/machine.go index bde4ea02..34ed9b99 100644 --- a/machine/machine.go +++ b/machine/machine.go @@ -194,6 +194,8 @@ func getNodeIdFromCpuBus(cpuBusPath string, threadId int) (int, error) { } // GetHugePagesInfo returns information about pre-allocated huge pages +// hugepagesDirectory should be top directory of hugepages +// Such as: /sys/kernel/mm/hugepages/ func GetHugePagesInfo(hugepagesDirectory string) ([]info.HugePagesInfo, error) { var hugePagesInfo []info.HugePagesInfo files, err := ioutil.ReadDir(hugepagesDirectory) diff --git a/machine/testdata/hugepages/hugepages-1048576kB/nr_hugepages b/machine/testdata/hugepages/hugepages-1048576kB/nr_hugepages new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/machine/testdata/hugepages/hugepages-1048576kB/nr_hugepages @@ -0,0 +1 @@ +1 diff --git a/machine/testdata/hugepages/hugepages-2048kB/nr_hugepages b/machine/testdata/hugepages/hugepages-2048kB/nr_hugepages new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/machine/testdata/hugepages/hugepages-2048kB/nr_hugepages @@ -0,0 +1 @@ +2 diff --git a/machine/topology_test.go b/machine/topology_test.go index 5144daf0..2f40d5e0 100644 --- a/machine/topology_test.go +++ b/machine/topology_test.go @@ -143,3 +143,26 @@ func TestTopologyNodeId(t *testing.T) { t.Errorf("Expected core 1234 , found %d", val) } } + +func TestGetHugePagesInfo(t *testing.T) { + testPath := "./testdata/hugepages/" + expected := []info.HugePagesInfo{ + { + NumPages: 1, + PageSize: 1048576, + }, + { + NumPages: 2, + PageSize: 2048, + }, + } + + val, err := GetHugePagesInfo(testPath) + if err != nil { + t.Errorf("Failed to GetHugePagesInfo() for sample path %s: %v", testPath, err) + } + + if !reflect.DeepEqual(expected, val) { + t.Errorf("Expected HugePagesInfo %+v, got %+v", expected, val) + } +}