-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
daemon: add nydusd process to specific cgroup
Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
- Loading branch information
Showing
16 changed files
with
556 additions
and
11 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
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,41 @@ | ||
/* | ||
* Copyright (c) 2023. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package cgroup | ||
|
||
import ( | ||
"github.com/containerd/cgroups" | ||
v1 "github.com/containerd/nydus-snapshotter/pkg/cgroup/v1" | ||
v2 "github.com/containerd/nydus-snapshotter/pkg/cgroup/v2" | ||
) | ||
|
||
const ( | ||
defaultSlice = "system.slice" | ||
) | ||
|
||
type Config struct { | ||
MemoryLimitInBytes int64 | ||
MemoryWatermarkScaleFactor int64 | ||
} | ||
|
||
type DaemonCgroup interface { | ||
// Delete the current cgroup. | ||
Delete() error | ||
// Add a process to current cgroup. | ||
AddProc(pid int) error | ||
} | ||
|
||
func createCgroup(name string, config Config) (DaemonCgroup, error) { | ||
if cgroups.Mode() == cgroups.Unified { | ||
return v2.NewCgroup(defaultSlice, name, config.MemoryLimitInBytes, config.MemoryWatermarkScaleFactor) | ||
} | ||
|
||
return v1.NewCgroup(defaultSlice, name, config.MemoryLimitInBytes, config.MemoryWatermarkScaleFactor) | ||
} | ||
|
||
func Supported() bool { | ||
return cgroups.Mode() != cgroups.Unavailable | ||
} |
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,41 @@ | ||
/* | ||
* Copyright (c) 2023. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package cgroup | ||
|
||
type Manager struct { | ||
name string | ||
config Config | ||
cgroup DaemonCgroup | ||
} | ||
|
||
type Opt struct { | ||
Name string | ||
Config Config | ||
} | ||
|
||
func NewManager(opt Opt) (*Manager, error) { | ||
cg, err := createCgroup(opt.Name, opt.Config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Manager{ | ||
name: opt.Name, | ||
config: opt.Config, | ||
cgroup: cg, | ||
}, nil | ||
} | ||
|
||
// Please make sure the *Manager is not null. | ||
func (m *Manager) AddProc(pid int) error { | ||
return m.cgroup.AddProc(pid) | ||
} | ||
|
||
// Please make sure the *Manager is not null. | ||
func (m *Manager) Delete() error { | ||
return m.cgroup.Delete() | ||
} |
Oops, something went wrong.