-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgroup: make paths available, simplify getting manager #3216
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
097c6d7
libct/cg: simplify getting cgroup manager
kolyshkin 6c5441e
libct/cg/fs: move paths init to NewManager
kolyshkin fcc4816
libct/cg/fs: document path removal
kolyshkin b14a6cf
libct/cg/sd/v1: move path init to NewLegacyManager
kolyshkin 39be6e9
libct/cg/fs2: minor optimization
kolyshkin 9a2146f
libct/cg/sd/v2: move path init to NewUnifiedManager
kolyshkin 1af4ed1
libct/cg/sd/v2: move fsMgr init to NewUnifiedManager
kolyshkin 57edce4
libct/cg: add Resources=nil unit test
kolyshkin 99ddc1b
libct/cg/fs: rm m.config == nil checks
kolyshkin 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 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
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,44 @@ | ||
package manager | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/opencontainers/runc/libcontainer/configs" | ||
) | ||
|
||
// TestNilResources checks that a cgroup manager do not panic when | ||
// config.Resources is nil. While it does not make sense to use a | ||
// manager with no resources, it should not result in a panic. | ||
// | ||
// This tests either v1 or v2 managers (both fs and systemd), | ||
// depending on what cgroup version is available on the host. | ||
func TestNilResources(t *testing.T) { | ||
for _, sd := range []bool{false, true} { | ||
cg := &configs.Cgroup{} // .Resources is nil | ||
cg.Systemd = sd | ||
mgr, err := New(cg) | ||
if err != nil { | ||
// Some managers require non-nil Resources during | ||
// instantiation -- provide and retry. In such case | ||
// we're mostly testing Set(nil) below. | ||
cg.Resources = &configs.Resources{} | ||
mgr, err = New(cg) | ||
if err != nil { | ||
t.Error(err) | ||
continue | ||
} | ||
} | ||
_ = mgr.Apply(-1) | ||
_ = mgr.Set(nil) | ||
_ = mgr.Freeze(configs.Thawed) | ||
_ = mgr.Exists() | ||
_, _ = mgr.GetAllPids() | ||
_, _ = mgr.GetCgroups() | ||
_, _ = mgr.GetFreezerState() | ||
_ = mgr.Path("") | ||
_ = mgr.GetPaths() | ||
_, _ = mgr.GetStats() | ||
_, _ = mgr.OOMKillCount() | ||
_ = mgr.Destroy() | ||
} | ||
} |
Oops, something went wrong.
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'm not 100% sure this is the right thing to do. Maybe we should not require it.
It is required because
runc/libcontainer/cgroups/fs/cpu.go
Lines 26 to 29 in 79185bc
runc/libcontainer/cgroups/fs/cpuset.go
Lines 150 to 166 in 79185bc
runc/libcontainer/cgroups/fs/devices.go
Line 24 in 79185bc
Now, we can modify all the three places to allow
nil
(and assume RT, cpus/mems, and SkipDevices are not set), and drop this requirement. After all, it is only for some specific cases, and not always required.Honestly I don't know which way is better.
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 that creating a cgroup should be separated from the applying values, so my preference is to allow nil at those 3 places and remove this check.
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.
Alas, with cgroup v1 it is not possible in some cases (outlined above), so as much as we want to separate create and set, we can not.
In this case, though, we can allow
nil
(the price to pay is to fail later on Apply in case either of CPU RT priority, cpus/mems, SkipDevices is set).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.
OTOH it's easier to require non-nil Resources here, otherwise it's hard to explain later why cpu/cpuset/devices configuration has unexpectedly failed.
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, let's leave it as is, unless there are other opinions.
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 it's better to leave it as-is for the moment. The fact that we need to configure other cgroups for cpu makes me think that allowing nil Resources will make this even more ugly than it is today.