MCPcopy Create free account
hub / github.com/coder/envbox / SetContainerQuota

Function SetContainerQuota

dockerutil/container.go:145–154  ·  view source on GitHub ↗

SetContainerQuota writes a quota to its correct location for the inner container. HACK: until https://github.com/nestybox/sysbox/issues/582 is resolved, we need to copy the CPU quota and period from the outer container to the inner container to ensure that applications inside the container know how

(ctx context.Context, containerID string, quota xunix.CPUQuota)

Source from the content-addressed store, hash-verified

143// - /sys/fs/cgroup/cpu,cpuacct/<subpath>/syscont-cgroup-root/cpu.cfs_quota_us
144// - /sys/fs/cgroup/cpu,cpuacct/<subpath>/syscont-cgroup-root/cpu.cfs_period_us
145func SetContainerQuota(ctx context.Context, containerID string, quota xunix.CPUQuota) error {
146 switch quota.CGroup {
147 case xunix.CGroupV2:
148 return setContainerQuotaCGroupV2(ctx, containerID, quota)
149 case xunix.CGroupV1:
150 return setContainerQuotaCGroupV1(ctx, containerID, quota)
151 default:
152 return xerrors.Errorf("Unknown cgroup %d", quota.CGroup)
153 }
154}
155
156func setContainerQuotaCGroupV2(ctx context.Context, containerID string, quota xunix.CPUQuota) error {
157 var (

Callers 2

runDockerCVMFunction · 0.92
TestSetContainerQuotaFunction · 0.92

Calls 3

ErrorfMethod · 0.65

Tested by 1

TestSetContainerQuotaFunction · 0.74