Repository: opencontainers/runc
File: libcontainer/cgroups/fs/cpu.go (Go)

Code before:
			return fmt.Errorf("the maximum allowed cpu-shares is %d", sharesRead)
		} else if shares < sharesRead {
			return fmt.Errorf("the minimum allowed cpu-shares is %d", sharesRead)
		}
	}

	var period string
	if r.CpuPeriod != 0 {
		period = strconv.FormatUint(r.CpuPeriod, 10)
		if err := cgroups.WriteFile(path, "cpu.cfs_period_us", period); err != nil {
			// Sometimes when the period to be set is smaller
			// than the current one, it is rejected by the kernel
			// (EINVAL) as old_quota/new_period exceeds the parent
			// cgroup quota limit. If this happens and the quota is
			// going to be set, ignore the error for now and retry
			// after setting the quota.
			if !errors.Is(err, unix.EINVAL) || r.CpuQuota == 0 {
				return err
			}
		} else {
			period = ""
		}
	}

	var burst string
	if r.CpuBurst != 0 {
		burst = strconv.FormatUint(r.CpuBurst, 10)
		if err := cgroups.WriteFile(path, "cpu.cfs_burst_us", burst); err != nil {
			// this is a special trick for burst feature, the current systemd and low version of kernel will not support it.
			// So, an `no such file or directory` error would be raised, and we can ignore it .
			if !errors.Is(err, unix.ENOENT) {
				// Sometimes when the burst to be set is larger
				// than the current one, it is rejected by the kernel
				// (EINVAL) as old_quota/new_burst exceeds the parent
				// cgroup quota limit. If this happens and the quota is
				// going to be set, ignore the error for now and retry
				// after setting the quota.
				if !errors.Is(err, unix.EINVAL) || r.CpuQuota == 0 {
					return err
				}
			}
		} else {
			burst = ""
		}
	}
	if r.CpuQuota != 0 {
		if err := cgroups.WriteFile(path, "cpu.cfs_quota_us", strconv.FormatInt(r.CpuQuota, 10)); err != nil {
			return err
		}
		if period != "" {
			if err := cgroups.WriteFile(path, "cpu.cfs_period_us", period); err != nil {

Review comment (suggestion):
If we want to clear `cpu-burst`, the value should be 0. So we should change `r.CpuBurst` to a pointer and to check whether this is nil or not.

Code after:
			return fmt.Errorf("the maximum allowed cpu-shares is %d", sharesRead)
		} else if shares < sharesRead {
			return fmt.Errorf("the minimum allowed cpu-shares is %d", sharesRead)
		}
	}

	var period string
	if r.CpuPeriod != 0 {
		period = strconv.FormatUint(r.CpuPeriod, 10)
		if err := cgroups.WriteFile(path, "cpu.cfs_period_us", period); err != nil {
			// Sometimes when the period to be set is smaller
			// than the current one, it is rejected by the kernel
			// (EINVAL) as old_quota/new_period exceeds the parent
			// cgroup quota limit. If this happens and the quota is
			// going to be set, ignore the error for now and retry
			// after setting the quota.
			if !errors.Is(err, unix.EINVAL) || r.CpuQuota == 0 {
				return err
			}
		} else {
			period = ""
		}
	}

	var burst string
	if r.CpuBurst != nil {
		burst = strconv.FormatUint(*r.CpuBurst, 10)
		if err := cgroups.WriteFile(path, "cpu.cfs_burst_us", burst); err != nil {
			// this is a special trick for burst feature, the current systemd and low version of kernel will not support it.
			// So, an `no such file or directory` error would be raised, and we can ignore it .
			if !errors.Is(err, unix.ENOENT) {
				// Sometimes when the burst to be set is larger
				// than the current one, it is rejected by the kernel
				// (EINVAL) as old_quota/new_burst exceeds the parent
				// cgroup quota limit. If this happens and the quota is
				// going to be set, ignore the error for now and retry
				// after setting the quota.
				if !errors.Is(err, unix.EINVAL) || r.CpuQuota == 0 {
					return err
				}
			}
		} else {
			burst = ""
		}
	}
	if r.CpuQuota != 0 {
		if err := cgroups.WriteFile(path, "cpu.cfs_quota_us", strconv.FormatInt(r.CpuQuota, 10)); err != nil {
			return err
		}
		if period != "" {
			if err := cgroups.WriteFile(path, "cpu.cfs_period_us", period); err != nil {