This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 315
Add systemd support cpu.cfs_quota_us and cpu.cfs_period_us #371
Merged
mrunalp
merged 1 commit into
docker-archive:master
from
coolljt0725:add_support_cpu_cfs_quota
Feb 17, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -150,6 +150,12 @@ func Apply(c *cgroups.Cgroup, pid int) (map[string]string, error) { | |
| return nil, err | ||
| } | ||
|
|
||
| // TODO: CpuQuota and CpuPeriod not available in systemd | ||
| // we need to manually join the cpu.cfs_quota_us and cpu.cfs_period_us | ||
| if err := joinCpu(c, pid); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is CpuPeriod? We should support both of them. |
||
| // -1 disables memorySwap | ||
| if c.MemorySwap >= 0 && c.Memory != 0 { | ||
| if err := joinMemory(c, pid); err != nil { | ||
|
|
@@ -196,6 +202,24 @@ func writeFile(dir, file, data string) error { | |
| return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700) | ||
| } | ||
|
|
||
| func joinCpu(c *cgroups.Cgroup, pid int) error { | ||
| path, err := getSubsystemPath(c, "cpu") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if c.CpuQuota != 0 { | ||
| if err = ioutil.WriteFile(filepath.Join(path, "cpu.cfs_quota_us"), []byte(strconv.FormatInt(c.CpuQuota, 10)), 0700); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| if c.CpuPeriod != 0 { | ||
| if err = ioutil.WriteFile(filepath.Join(path, "cpu.cfs_period_us"), []byte(strconv.FormatInt(c.CpuPeriod, 10)), 0700); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func joinFreezer(c *cgroups.Cgroup, pid int) error { | ||
| path, err := getSubsystemPath(c, "freezer") | ||
| if err != nil { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not a TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still true that native systemd API doesn't support period and quota, right? We are using the filesystem path directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think the comment is accurate.