This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from Mashimiao/support-hugetlb-set-and-getstats
hugetlb: Add support of Set and GetStats function
- Loading branch information
Showing
9 changed files
with
248 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package fs | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/docker/libcontainer/cgroups" | ||
"github.com/docker/libcontainer/configs" | ||
) | ||
|
||
const ( | ||
hugetlbUsageContents = "128\n" | ||
hugetlbMaxUsageContents = "256\n" | ||
hugetlbFailcnt = "100\n" | ||
) | ||
|
||
var ( | ||
hugePageSize, _ = cgroups.GetHugePageSize() | ||
usage = strings.Join([]string{"hugetlb", hugePageSize[0], "usage_in_bytes"}, ".") | ||
limit = strings.Join([]string{"hugetlb", hugePageSize[0], "limit_in_bytes"}, ".") | ||
maxUsage = strings.Join([]string{"hugetlb", hugePageSize[0], "max_usage_in_bytes"}, ".") | ||
failcnt = strings.Join([]string{"hugetlb", hugePageSize[0], "failcnt"}, ".") | ||
) | ||
|
||
func TestHugetlbSetHugetlb(t *testing.T) { | ||
helper := NewCgroupTestUtil("hugetlb", t) | ||
defer helper.cleanup() | ||
|
||
const ( | ||
hugetlbBefore = 256 | ||
hugetlbAfter = 512 | ||
) | ||
|
||
helper.writeFileContents(map[string]string{ | ||
limit: strconv.Itoa(hugetlbBefore), | ||
}) | ||
|
||
helper.CgroupData.c.HugetlbLimit = []*configs.HugepageLimit{ | ||
{ | ||
Pagesize: hugePageSize[0], | ||
Limit: hugetlbAfter, | ||
}, | ||
} | ||
hugetlb := &HugetlbGroup{} | ||
if err := hugetlb.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
value, err := getCgroupParamUint(helper.CgroupPath, limit) | ||
if err != nil { | ||
t.Fatalf("Failed to parse %s - %s", limit, err) | ||
} | ||
if value != hugetlbAfter { | ||
t.Fatalf("Set hugetlb.limit_in_bytes failed. Expected: %v, Got: %v", hugetlbAfter, value) | ||
} | ||
} | ||
|
||
func TestHugetlbStats(t *testing.T) { | ||
helper := NewCgroupTestUtil("hugetlb", t) | ||
defer helper.cleanup() | ||
helper.writeFileContents(map[string]string{ | ||
usage: hugetlbUsageContents, | ||
maxUsage: hugetlbMaxUsageContents, | ||
failcnt: hugetlbFailcnt, | ||
}) | ||
|
||
hugetlb := &HugetlbGroup{} | ||
actualStats := *cgroups.NewStats() | ||
err := hugetlb.GetStats(helper.CgroupPath, &actualStats) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
expectedStats := cgroups.HugetlbStats{Usage: 128, MaxUsage: 256, Failcnt: 100} | ||
expectHugetlbStatEquals(t, expectedStats, actualStats.HugetlbStats[hugePageSize[0]]) | ||
} | ||
|
||
func TestHugetlbStatsNoUsageFile(t *testing.T) { | ||
helper := NewCgroupTestUtil("hugetlb", t) | ||
defer helper.cleanup() | ||
helper.writeFileContents(map[string]string{ | ||
maxUsage: hugetlbMaxUsageContents, | ||
}) | ||
|
||
hugetlb := &HugetlbGroup{} | ||
actualStats := *cgroups.NewStats() | ||
err := hugetlb.GetStats(helper.CgroupPath, &actualStats) | ||
if err == nil { | ||
t.Fatal("Expected failure") | ||
} | ||
} | ||
|
||
func TestHugetlbStatsNoMaxUsageFile(t *testing.T) { | ||
helper := NewCgroupTestUtil("hugetlb", t) | ||
defer helper.cleanup() | ||
helper.writeFileContents(map[string]string{ | ||
usage: hugetlbUsageContents, | ||
}) | ||
|
||
hugetlb := &HugetlbGroup{} | ||
actualStats := *cgroups.NewStats() | ||
err := hugetlb.GetStats(helper.CgroupPath, &actualStats) | ||
if err == nil { | ||
t.Fatal("Expected failure") | ||
} | ||
} | ||
|
||
func TestHugetlbStatsBadUsageFile(t *testing.T) { | ||
helper := NewCgroupTestUtil("hugetlb", t) | ||
defer helper.cleanup() | ||
helper.writeFileContents(map[string]string{ | ||
usage: "bad", | ||
maxUsage: hugetlbMaxUsageContents, | ||
}) | ||
|
||
hugetlb := &HugetlbGroup{} | ||
actualStats := *cgroups.NewStats() | ||
err := hugetlb.GetStats(helper.CgroupPath, &actualStats) | ||
if err == nil { | ||
t.Fatal("Expected failure") | ||
} | ||
} | ||
|
||
func TestHugetlbStatsBadMaxUsageFile(t *testing.T) { | ||
helper := NewCgroupTestUtil("hugetlb", t) | ||
defer helper.cleanup() | ||
helper.writeFileContents(map[string]string{ | ||
usage: hugetlbUsageContents, | ||
maxUsage: "bad", | ||
}) | ||
|
||
hugetlb := &HugetlbGroup{} | ||
actualStats := *cgroups.NewStats() | ||
err := hugetlb.GetStats(helper.CgroupPath, &actualStats) | ||
if err == nil { | ||
t.Fatal("Expected failure") | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package configs | ||
|
||
type HugepageLimit struct { | ||
// which type of hugepage to limit. | ||
Pagesize string `json:"page_size"` | ||
|
||
// usage limit for hugepage. | ||
Limit int `json:"limit"` | ||
} |