Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support write multiple items into cgroup v2 file #4182

Conversation

smileusd
Copy link

@smileusd smileusd commented Feb 1, 2024

This pr is a supplement for cgroup v2 file value write. 
I met that after calculating in kubelet, i got a configs.Resources contains the cup,memory,pid and also cgroup v2 field like io.max and io.weight. the map of Unified in the config might be like: 
{"io.max": "252:1 riops=1000 wiops=1000 \n 252:2 riops=2000 wiops=2000", "io.weight": "252:1 300 \n 252:2 500" }
Currently the unified set can not support write multiple line in one cgroup file.

// {"io.max": "252:1 riops=1000 wiops=1000 \n 252:2 riops=2000 wiops=2000"}
items := strings.Split(v, "\n")
for _, item := range items {
if err := cgroups.WriteFile(m.dirPath, k, item); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why is this writing two lines instead of overwriting them?

If you had a test case for this, I could have answered myself by looking at that ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cgroup file is also like a map. if the key is the same, the new one will override old one, but if it is different key, like different device number, the will add a new line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to add test case at here, there is the test by my environment

root@tess-node-6bg2h:/sys/fs/cgroup/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod02d6c4d8_0888_464a_9037_7238679d4174.slice# cat io.max 
252:0 rbps=1048576 wbps=1048576 riops=100 wiops=100
253:0 rbps=1048576 wbps=1048576 riops=100 wiops=100
root@tess-node-6bg2h:/sys/fs/cgroup/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod02d6c4d8_0888_464a_9037_7238679d4174.slice# echo  "252:16 rbps=1048576 wbps=1048576 riops=100 wiops=100" > io.max 
root@tess-node-6bg2h:/sys/fs/cgroup/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod02d6c4d8_0888_464a_9037_7238679d4174.slice# cat io.max 
252:16 rbps=1048576 wbps=1048576 riops=100 wiops=100
252:0 rbps=1048576 wbps=1048576 riops=100 wiops=100
253:0 rbps=1048576 wbps=1048576 riops=100 wiops=100

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added test case in pr @rata

@kolyshkin
Copy link
Contributor

@smileusd perhaps you can set io.max not via unified but via linux.resources.blockIO.weightDevice

@smileusd
Copy link
Author

smileusd commented Feb 2, 2024

@smileusd perhaps you can set io.max not via unified but via linux.resources.blockIO.weightDevice

@kolyshkin

// WeightDevice struct holds a `major:minor weight`|`major:minor leaf_weight` pair
type WeightDevice struct {
	blockIODevice
	// Weight is the bandwidth rate for the device, range is from 10 to 1000
	Weight uint16 `json:"weight"`
	// LeafWeight is the bandwidth rate for the device while competing with the cgroup's child cgroups, range is from 10 to 1000, cfq scheduler only
	LeafWeight uint16 `json:"leafWeight"`
}

Looks like it is only for io.weight not io.max. And actually cgroup v2 io.weight value range should be [1, 10000] not [10, 1000] So i think that should only for cgroup v1 might.

@kolyshkin

This comment was marked as outdated.

@smileusd smileusd force-pushed the set-multiple-value-for-cgroup-v2 branch from caf1cd6 to c61eeb2 Compare February 4, 2024 02:41
@kolyshkin
Copy link
Contributor

@smileusd does #4186 fixes your issue?

@kolyshkin
Copy link
Contributor

@smileusd it's a bit weird that you took my code (from #4186) and put it into your patch without even mentioning it.

@kolyshkin
Copy link
Contributor

Looks like it is only for io.weight not io.max. And actually cgroup v2 io.weight value range should be [1, 10000] not [10, 1000] So i think that should only for cgroup v1 might.

I'm sorry for pointing your into the wrong setting.

What I meant to say is you should use BlkioThrottleReadBpsDevice, BlkioThrottleWriteBpsDevice, BlkioThrottleReadIOPSDevice, and BlkioThrottleWriteIOPSDevice. Those settings are translated by runc to writes into io.max (as you can see in the source code if you grep for io.max).

@kolyshkin
Copy link
Contributor

Closing in favor of #4186.

@kolyshkin kolyshkin closed this Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants