This repository was archived by the owner on Sep 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -344,8 +344,17 @@ function check_cpu_shares() {
344344 local shares=$1
345345
346346 if [ -v CGROUP_V2 ]; then
347- local weight=$(( 1 + ((shares - 2 ) * 9999 ) / 262142 ))
348- check_cpu_weight " $weight "
347+ # Same formula as ConvertCPUSharesToCgroupV2Value.
348+ local weight
349+ weight=$( awk -v shares=" $shares " '
350+ BEGIN {
351+ if (shares == 0) { print 0; exit }
352+ if (shares <= 2) { print 1; exit }
353+ if (shares >= 262144) { print 10000; exit }
354+ l = log(shares) / log(2)
355+ exponent = (l*l + 125*l) / 612.0 - 7.0/34.0
356+ print int(exp(exponent * log(10)) + 0.99)
357+ }' )
349358 else
350359 check_cgroup_value " cpu.shares" " $shares "
351360 check_systemd_value " CPUShares" " $shares "
Original file line number Diff line number Diff line change 545545 runc run -d --console-socket " $CONSOLE_SOCKET " test_update
546546 [ " $status " -eq 0 ]
547547
548- # check that initial values were properly set
549- check_cpu_quota 500000 1000000 " 500ms"
550- # initial cpu shares of 100 corresponds to weight of 4
551- check_cpu_weight 4
548+ # Check that initial values (from setup) were properly set.
549+ check_cpu_quota 500000 1000000
550+ check_cpu_shares 100
552551 check_systemd_value " TasksMax" 20
553552
554553 runc update -r - test_update << EOF
You can’t perform that action at this time.
0 commit comments