Conversation
|
You can read the Garbage collection part of this document first. https://github.com/golang/proposal/blob/master/design/48409-soft-memory-limit.md This implementation allows GOGCRATIO values from 1% to 99%, while the GC CPU limiter is designed around a 50% threshold. Above 50%, background mark workers alone can keep GC CPU usage over the limit. The limiter only disables GC assists; it does not reduce dedicated mark workers. |
@BoyaoWang430 Thanks for the information and the reference. This PR is backported from the openEuler(https://gitcode.com/openeuler/golang/pull/70). Would it be acceptable to tighten the upper limit of GOGCRATIO from 99 to 50, to keep it consistent with the GC CPU limiter's 50% threshold? |
With the existing rounding rule and its 30% relative-error tolerance, 38% is the highest integer setting that guarantees dedicated workers use strictly less than half of the P |
Port of https://gitcode.com/openeuler/golang/pull/70 to the ZTE RISC-V toolchain.
The concurrent GC previously reserved a fixed 25% of CPU for background marking. This change introduces the
GOGCRATIOenvironment variable (1–99, default 25) to let users trade mutator CPU for marking throughput per workload.Implementation:
gcController.gcRatiostores the configured utilization;readGOGCRATIOparses and clamps to[0.01, 0.99]; pacer (startCycle/endCycle) and GC CPU limiter (mgclimit) use the dynamic value. Tests updated; new benchmarkBenchmarkGCBackgroundadded.Benchmarks
Benchstat comparisons below:
GOGCRATIO=25 vs 50
(All B/op and allocs/op unchanged at 832.0 B and 3.000 allocs/op across all benchmarks.)
GOGCRATIO=25 vs 75
(B/op and allocs/op unchanged.)
GOGCRATIO=25 vs 100
(B/op and allocs/op unchanged.)
Conclusion
The knob works as intended:
Default GOGC=100 (common case): raising to 50/75 does not hurt on multi-core; only 100 causes slowdown due to GC CPU limiter engagement, confirming no regression.
GC-bound workloads (GOGC=5, dense): 75 is near-optimal, cutting time by 19–50% on 4–8 cores; 100 gives back some gain (limiter kicks in), 25 is under-provisioned.
Single core: higher GOGCRATIO always hurts (up to +140% at 100) because no parallelism exists for extra mark workers.
Geomean across all 27 configs: 25→50 -8.61%, 25→75 -10.60%, 25→100 +8.44%. The GC CPU limiter provides a safety ceiling against oversubscription.