Skip to content

Commit

Permalink
blkiodev: limit blkio device's read/write Bps/IOps
Browse files Browse the repository at this point in the history
fixes AliyunContainerService#2509

Signed-off-by: Leno Hou <lenohou@gmail.com>
  • Loading branch information
houstar committed Dec 14, 2018
1 parent 6dbedc4 commit 2c30f10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (uc *UpdateCommand) addFlags() {
flagSet.StringSliceVarP(&uc.labels, "label", "l", nil, "Set label for container")
flagSet.StringVar(&uc.restartPolicy, "restart", "", "Restart policy to apply when container exits")
flagSet.StringSliceVar(&uc.diskQuota, "disk-quota", nil, "Update disk quota for container(/=10g)")
flagSet.Var(&uc.blkioDeviceReadBps, "device-read-bps", "Limit read rate (bytes per second) from a device")
flagSet.Var(&uc.blkioDeviceWriteBps, "device-write-bps", "Limit write rate (bytes per second) from a device")
flagSet.Var(&uc.blkioDeviceReadIOps, "device-read-iops", "Limit read rate (bytes per second) from a device")
flagSet.Var(&uc.blkioDeviceWriteIOps, "device-write-iops", "Limit write rate (bytes per second) from a device")
}

// updateRun is the entry of update command.
Expand All @@ -74,15 +78,19 @@ func (uc *UpdateCommand) updateRun(args []string) error {
}

resource := types.Resources{
CPUPeriod: uc.cpuperiod,
CPUShares: uc.cpushare,
CPUQuota: uc.cpuquota,
CpusetCpus: uc.cpusetcpus,
CpusetMems: uc.cpusetmems,
DiskQuota: diskQuota,
Memory: memory,
MemorySwap: memorySwap,
BlkioWeight: uc.blkioWeight,
CPUPeriod: uc.cpuperiod,
CPUShares: uc.cpushare,
CPUQuota: uc.cpuquota,
CpusetCpus: uc.cpusetcpus,
CpusetMems: uc.cpusetmems,
DiskQuota: diskQuota,
Memory: memory,
MemorySwap: memorySwap,
BlkioWeight: uc.blkioWeight,
BlkioDeviceReadBps: uc.blkioDeviceReadBps.Value(),
BlkioDeviceWriteBps: uc.blkioDeviceWriteBps.Value(),
BlkioDeviceReadIOps: uc.blkioDeviceReadIOps.Value(),
BlkioDeviceWriteIOps: uc.blkioDeviceWriteIOps.Value(),
}

restartPolicy, err := opts.ParseRestartPolicy(uc.restartPolicy)
Expand Down
2 changes: 1 addition & 1 deletion cri/v1alpha2/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ func parseResourcesFromCRI(runtimeResources *runtime.LinuxContainerResources) ap
BlkioDeviceWriteBps: parseThrottleDeviceFromCRI(runtimeResources.GetBlkioDeviceWriteBps()),
BlkioDeviceReadIOps: parseThrottleDeviceFromCRI(runtimeResources.GetBlkioDeviceRead_IOps()),
BlkioDeviceWriteIOps: parseThrottleDeviceFromCRI(runtimeResources.GetBlkioDeviceWrite_IOps()),
DiskQuota: runtimeResources.GetDiskQuota(),
DiskQuota: runtimeResources.GetDiskQuota(),
KernelMemory: runtimeResources.GetKernelMemory(),
MemoryReservation: runtimeResources.GetMemoryReservation(),
MemorySwappiness: memorySwappiness,
Expand Down

0 comments on commit 2c30f10

Please sign in to comment.