Skip to content

Commit

Permalink
add cpuset-cpus cpuset-mems,cpu-quota,cpu-period
Browse files Browse the repository at this point in the history
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
  • Loading branch information
ningmingxiao committed Jan 10, 2022
1 parent e785883 commit 2c684c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/nerdctl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ func setCreateFlags(cmd *cobra.Command) {
return []string{"host", "private"}, cobra.ShellCompDirectiveNoFileComp
})
cmd.Flags().String("cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)")
cmd.Flags().String("cpuset-mems", "", "MEMs in which to allow execution")
cmd.Flags().Int("cpu-shares", 0, "CPU shares (relative weight)")
cmd.Flags().Int64("cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
cmd.Flags().Uint64("cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period")
// device is defined as StringSlice, not StringArray, to allow specifying "--device=DEV1,DEV2" (compatible with Podman)
cmd.Flags().StringSlice("device", nil, "Add a host device to the container")
// ulimit is defined as StringSlice, not StringArray, to allow specifying "--ulimit=ULIMIT1,ULIMIT2" (compatible with Podman)
Expand Down
17 changes: 16 additions & 1 deletion cmd/nerdctl/run_cgroup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,22 @@ func generateCgroupOpts(cmd *cobra.Command, id string) ([]oci.SpecOpts, error) {
if cpuset != "" {
opts = append(opts, oci.WithCPUs(cpuset))
}

cpuQuota, err := cmd.Flags().GetInt64("cpu-quota")
if err != nil {
return nil, err
}
cpuPeriod, err := cmd.Flags().GetUint64("cpu-period")
if err != nil {
return nil, err
}
opts = append(opts, oci.WithCPUCFS(cpuQuota, cpuPeriod))
cpusetMems, err := cmd.Flags().GetString("cpuset-mems")
if err != nil {
return nil, err
}
if cpuMems != "" {
opts = append(opts, oci.WithCPUsMems(cpusetMems))
}
if memStr != "" {
mem64, err := units.RAMInBytes(memStr)
if err != nil {
Expand Down

0 comments on commit 2c684c9

Please sign in to comment.