diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index 353d7a01d..d84ed0238 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -58,6 +58,11 @@ var platformRunFlags = []cli.Flag{ Name: "remap-labels", Usage: "provide the user namespace ID remapping to the snapshotter via label options; requires snapshotter support", }, + cli.Float64Flag{ + Name: "cpus", + Usage: "set the CFS cpu qouta", + Value: 0.0, + }, } // NewContainer creates a new container @@ -179,6 +184,13 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli if context.Bool("seccomp") { opts = append(opts, seccomp.WithDefaultProfile()) } + if cpus := context.Float64("cpus"); cpus > 0.0 { + var ( + period = uint64(100000) + quota = int64(cpus * 100000.0) + ) + opts = append(opts, oci.WithCPUCFS(quota, period)) + } joinNs := context.StringSlice("with-ns") for _, ns := range joinNs { diff --git a/oci/spec_opts_unix.go b/oci/spec_opts_unix.go index bcabf0efb..972c11c8f 100644 --- a/oci/spec_opts_unix.go +++ b/oci/spec_opts_unix.go @@ -118,3 +118,10 @@ func deviceFromPath(path, permissions string) (*specs.LinuxDevice, error) { GID: &stat.Gid, }, nil } + +// WithCPUCFS sets the container's Completely fair scheduling (CFS) quota and period +func WithCPUCFS(quota int64, period uint64) SpecOpts { + return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error { + return nil + } +}