From f642c0a5f58a727d219d13ce2779d7892c067fd7 Mon Sep 17 00:00:00 2001 From: Peteris Rudzusiks Date: Tue, 30 May 2023 16:20:58 +0200 Subject: [PATCH 1/2] ctr: add cpuset-cpus flag to 'ctr run' command This flag allows cpuset.cpus to be specified when starting a container. If provided, the container will use only the defined CPU cores. Signed-off-by: Peteris Rudzusiks --- cmd/ctr/commands/run/run_unix.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index 81ba9d111..10c93724c 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -82,6 +82,10 @@ var platformRunFlags = []cli.Flag{ Usage: "Set the cpu shares", Value: 1024, }, + cli.StringFlag{ + Name: "cpuset-cpus", + Usage: "Set the CPUs the container will run in (e.g., 1-2,4)", + }, } // NewContainer creates a new container @@ -293,6 +297,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli opts = append(opts, oci.WithCPUCFS(quota, period)) } + if cpusetCpus := context.String("cpuset-cpus"); len(cpusetCpus) > 0 { + opts = append(opts, oci.WithCPUs(cpusetCpus)) + } + if shares := context.Int("cpu-shares"); shares > 0 { opts = append(opts, oci.WithCPUShares(uint64(shares))) } From f2bc73782542b49bec465528c4bbc41f82ad5687 Mon Sep 17 00:00:00 2001 From: Peteris Rudzusiks Date: Tue, 30 May 2023 16:44:53 +0200 Subject: [PATCH 2/2] Add cpuset-mems flag to 'ctr run' command This flag allows cpuset.mems to be specified when running a container. If provided, the container will use only the defined memory nodes. Signed-off-by: Peteris Rudzusiks --- cmd/ctr/commands/run/run_unix.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index 10c93724c..0d003828d 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -86,6 +86,10 @@ var platformRunFlags = []cli.Flag{ Name: "cpuset-cpus", Usage: "Set the CPUs the container will run in (e.g., 1-2,4)", }, + cli.StringFlag{ + Name: "cpuset-mems", + Usage: "Set the memory nodes the container will run in (e.g., 1-2,4)", + }, } // NewContainer creates a new container @@ -301,6 +305,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli opts = append(opts, oci.WithCPUs(cpusetCpus)) } + if cpusetMems := context.String("cpuset-mems"); len(cpusetMems) > 0 { + opts = append(opts, oci.WithCPUsMems(cpusetMems)) + } + if shares := context.Int("cpu-shares"); shares > 0 { opts = append(opts, oci.WithCPUShares(uint64(shares))) }