-
Notifications
You must be signed in to change notification settings - Fork 97
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
Limit memory resource usage for nydus daemon via cgroup #415
Limit memory resource usage for nydus daemon via cgroup #415
Conversation
pkg/daemon/daemon.go
Outdated
@@ -559,6 +562,38 @@ func (d *Daemon) ClearVestige() { | |||
d.ResetClient() | |||
} | |||
|
|||
func (d *Daemon) AddCgroup(pid int) error { |
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 we should implement a cgroup manager and add the daemon to it, instead add the method AddCgroup
, DeleteCgroup
on *Daemon
. One reason is that maybe we need to support containerized snapshotter/nydusd to limit resource usage and process management in the future.
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.
Got it. I will refactor this 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.
Agree. We should support resources limitation based on both raw cgroup controller and containers
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.
Is it based on cgroup v1 or v2?
It is based on cgroup v1. |
Is it possible to depend cgroup v2? |
May we implement both v1 and v2? Group v2 depends on the Linux kernel. On my machine, it mounts the cgroup v1 file system by default. |
2cb65c5
to
d0d9f04
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #415 +/- ##
==========================================
+ Coverage 37.70% 37.88% +0.17%
==========================================
Files 59 60 +1
Lines 6996 7061 +65
==========================================
+ Hits 2638 2675 +37
- Misses 4047 4073 +26
- Partials 311 313 +2
|
caab0fb
to
f20f46e
Compare
d3f42df
to
66d32b1
Compare
5f00416
to
83d2797
Compare
This PR introduce a cgroup interface for nydusd daemon Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
83d2797
to
b81c6d7
Compare
snapshot/snapshot.go
Outdated
Name: "nydusd", | ||
Config: cgroupConfig, | ||
}) | ||
if err != nil && (err != cgroup.ErrCgroupNotSupported || err != v2.ErrRootMemorySubtreeControllerNotEnableed) { |
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.
typo “Enableed” or this can be named to xxxDisabled
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.
Good point. Fixed.
|
||
var ( | ||
sysinfo *syscall.Sysinfo_t | ||
) |
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.
Can you try sync.Once to initialize the global sysinfo?
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.
It somewhat not threaded safe
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.
Done.
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
} | ||
func (cg Cgroup) AddProc(pid int) error { | ||
if cg.manager != nil { | ||
err := cg.manager.AddProc(uint64(pid)) |
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.
Need move the process out from controller if nydusd dies or exits normally?
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.
The process will be automatically removed if nydusd dies. The cgroups library in containerd does not have this method either.
1ec7551
to
438d963
Compare
The parser package aims to parse configuration data to expected units Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
The cgroup manager aims to manager the lifetime of daemon's cgroup and add nydusd to this cgroup for memory resource limitation and reclaim. Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
refer to moby/moby#43093 Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
438d963
to
5d9bdba
Compare
Nydus-snapshotter does not have a maximum memory limit by default. This can lead to host invalidity. Now, we put snapshotter and daemon in different cgroup to limit the maximum available memory.
This PR adds two entries to the configuration file.