Skip to content

Commit 089d971

Browse files
author
Mrunal Patel
authored
Merge pull request #175 from hmeng-19/add_generate_options
add new generate options for setting cpu/mem
2 parents 1a3f3c6 + 092cb7c commit 089d971

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

cmd/ocitools/generate.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ var generateFlags = []cli.Flag{
5959
cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"},
6060
cli.StringSliceFlag{Name: "label", Usage: "add annotations to the configuration e.g. key=value"},
6161
cli.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"},
62+
cli.Uint64Flag{Name: "linux-cpu-shares", Usage: "the relative share of CPU time available to the tasks in a cgroup"},
63+
cli.Uint64Flag{Name: "linux-cpu-period", Usage: "the CPU period to be used for hardcapping (in usecs)"},
64+
cli.Uint64Flag{Name: "linux-cpu-quota", Usage: "the allowed CPU time in a given period (in usecs)"},
65+
cli.Uint64Flag{Name: "linux-realtime-runtime", Usage: "the time realtime scheduling may use (in usecs)"},
66+
cli.Uint64Flag{Name: "linux-realtime-period", Usage: "CPU period to be used for realtime scheduling (in usecs)"},
67+
cli.StringFlag{Name: "linux-cpus", Usage: "CPUs to use within the cpuset (default is to use any CPU available)"},
68+
cli.StringFlag{Name: "linux-mems", Usage: "list of memory nodes in the cpuset (default is to use any available memory node)"},
69+
cli.Uint64Flag{Name: "linux-mem-limit", Usage: "memory limit (in bytes)"},
70+
cli.Uint64Flag{Name: "linux-mem-reservation", Usage: "memory reservation or soft limit (in bytes)"},
71+
cli.Uint64Flag{Name: "linux-mem-swap", Usage: "total memory limit (memory + swap) (in bytes)"},
72+
cli.Uint64Flag{Name: "linux-mem-kernel-limit", Usage: "kernel memory limit (in bytes)"},
73+
cli.Uint64Flag{Name: "linux-mem-kernel-tcp", Usage: "kernel memory limit for tcp (in bytes)"},
74+
cli.Uint64Flag{Name: "linux-mem-swappiness", Usage: "how aggressive the kernel will swap memory pages (Range from 0 to 100)"},
6275
}
6376

6477
var generateCommand = cli.Command{
@@ -324,6 +337,58 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
324337
g.SetLinuxResourcesOOMScoreAdj(context.Int("oom-score-adj"))
325338
}
326339

340+
if context.IsSet("linux-cpu-shares") {
341+
g.SetLinuxResourcesCPUShares(context.Uint64("linux-cpu-shares"))
342+
}
343+
344+
if context.IsSet("linux-cpu-period") {
345+
g.SetLinuxResourcesCPUPeriod(context.Uint64("linux-cpu-period"))
346+
}
347+
348+
if context.IsSet("linux-cpu-quota") {
349+
g.SetLinuxResourcesCPUQuota(context.Uint64("linux-cpu-quota"))
350+
}
351+
352+
if context.IsSet("linux-realtime-runtime") {
353+
g.SetLinuxResourcesCPURealtimeRuntime(context.Uint64("linux-realtime-runtime"))
354+
}
355+
356+
if context.IsSet("linux-realtime-period") {
357+
g.SetLinuxResourcesCPURealtimePeriod(context.Uint64("linux-realtime-period"))
358+
}
359+
360+
if context.IsSet("linux-cpus") {
361+
g.SetLinuxResourcesCPUCpus(context.String("linux-cpus"))
362+
}
363+
364+
if context.IsSet("linux-mems") {
365+
g.SetLinuxResourcesCPUMems(context.String("linux-mems"))
366+
}
367+
368+
if context.IsSet("linux-mem-limit") {
369+
g.SetLinuxResourcesMemoryLimit(context.Uint64("linux-mem-limit"))
370+
}
371+
372+
if context.IsSet("linux-mem-reservation") {
373+
g.SetLinuxResourcesMemoryReservation(context.Uint64("linux-mem-reservation"))
374+
}
375+
376+
if context.IsSet("linux-mem-swap") {
377+
g.SetLinuxResourcesMemorySwap(context.Uint64("linux-mem-swap"))
378+
}
379+
380+
if context.IsSet("linux-mem-kernel-limit") {
381+
g.SetLinuxResourcesMemoryKernel(context.Uint64("linux-mem-kernel-limit"))
382+
}
383+
384+
if context.IsSet("linux-mem-kernel-tcp") {
385+
g.SetLinuxResourcesMemoryKernelTCP(context.Uint64("linux-mem-kernel-tcp"))
386+
}
387+
388+
if context.IsSet("linux-mem-swappiness") {
389+
g.SetLinuxResourcesMemorySwappiness(context.Uint64("linux-mem-swappiness"))
390+
}
391+
327392
var sd string
328393
var sa, ss []string
329394

man/ocitools-generate.1.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,45 @@ read the configuration from `config.json`.
8787
**--label**=[]
8888
Add annotations to the configuration e.g. key=value.
8989

90+
**--linux-cpu-shares**=CPUSHARES
91+
Specifies a relative share of CPU time available to the tasks in a cgroup.
92+
93+
**--linux-cpu-period**=CPUPERIOD
94+
Specifies a period of time in microseconds for how regularly a cgroup's access to CPU resources should be reallocated (CFS scheduler only).
95+
96+
**--linux-cpu-quota**=CPUQUOTA
97+
Specifies the total amount of time in microseconds for which all tasks in a cgroup can run during one period.
98+
99+
**--linux-realtime-runtime**=REALTIMERUNTIME
100+
Specifies a period of time in microseconds for the longest continuous period in which the tasks in a cgroup have access to CPU resources.
101+
102+
**--linux-realtime-period**=REALTIMEPERIOD
103+
Sets the CPU period to be used for realtime scheduling (in usecs). Same as **--linux-cpu-period** but applies to realtime scheduler only.
104+
105+
**--linux-cpus**=CPUS
106+
Sets the CPUs to use within the cpuset (default is to use any CPU available).
107+
108+
**--linux-mems**=MEMS
109+
Sets the list of memory nodes in the cpuset (default is to use any available memory node).
110+
111+
**--linux-mem-limit**=MEMLIMIT
112+
Sets the limit of memory usage in bytes.
113+
114+
**--linux-mem-reservation**=MEMRESERVATION
115+
Sets the soft limit of memory usage in bytes.
116+
117+
**--linux-mem-swap**=MEMSWAP
118+
Sets the total memory limit (memory + swap) in bytes.
119+
120+
**--linux-mem-kernel-limit**=MEMKERNELLIMIT
121+
Sets the hard limit of kernel memory in bytes.
122+
123+
**--linux-mem-kernel-tcp**=MEMKERNELTCP
124+
Sets the hard limit of kernel TCP buffer memory in bytes.
125+
126+
**--linux-mem-swappiness**=MEMSWAPPINESS
127+
Sets the swappiness of how the kernel will swap memory pages (Range from 0 to 100).
128+
90129
**--mount**=*PATH*
91130
Use a mount namespace where *PATH* is an existing mount namespace file
92131
to join. The special *PATH* empty-string creates a new namespace.

0 commit comments

Comments
 (0)