]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make gcDrainN in terms of scan work
authorAustin Clements <austin@google.com>
Fri, 13 Mar 2015 18:01:16 +0000 (14:01 -0400)
committerAustin Clements <austin@google.com>
Tue, 21 Apr 2015 15:35:14 +0000 (15:35 +0000)
Currently, the "n" in gcDrainN is in terms of objects to scan. This is
used by gchelpwork to perform a limited amount of work on allocation,
but is a pretty arbitrary way to bound this amount of work since the
number of objects has little relation to how long they take to scan.

Modify gcDrainN to perform a fixed amount of scan work instead. For
now, gchelpwork still performs a fairly arbitrary amount of scan work,
but at least this is much more closely related to how long the work
will take. Shortly, we'll use this to precisely control the scan work
performed by mutator assists during allocation to achieve the heap
size goal.

Change-Id: I3cd07fe0516304298a0af188d0ccdf621d4651cc
Reviewed-on: https://go-review.googlesource.com/8835
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/mgcmark.go

index 38a24ff0e8818983b47cf5eab5a33cab523cf1bc..58682434284d83b1b1baa0f543fb6783f0ed2091 100644 (file)
@@ -190,8 +190,8 @@ func gchelpwork() {
                // be more cache friendly.
                var gcw gcWork
                gcw.initFromCache()
-               const n = len(workbuf{}.obj)
-               gcDrainN(&gcw, n) // drain upto one buffer's worth of objects
+               const helpScanWork = 500 // pointers to trace
+               gcDrainN(&gcw, helpScanWork)
                // TODO(austin): This is the vast majority of our
                // disposes. Instead of constantly disposing, keep a
                // per-P gcWork cache (probably combined with the
@@ -407,11 +407,16 @@ func gcDrain(gcw *gcWork, flushScanCredit int64) {
        checknocurrentwbuf()
 }
 
-// gcDrainN scans n objects, blackening grey objects.
+// gcDrainN blackens grey objects until it has performed roughly
+// scanWork units of scan work. This is best-effort, so it may perform
+// less work if it fails to get a work buffer. Otherwise, it will
+// perform at least n units of work, but may perform more because
+// scanning is always done in whole object increments.
 //go:nowritebarrier
-func gcDrainN(gcw *gcWork, n int) {
+func gcDrainN(gcw *gcWork, scanWork int64) {
        checknocurrentwbuf()
-       for i := 0; i < n; i++ {
+       targetScanWork := gcw.scanWork + scanWork
+       for gcw.scanWork < targetScanWork {
                // This might be a good place to add prefetch code...
                // if(wbuf.nobj > 4) {
                //         PREFETCH(wbuf->obj[wbuf.nobj - 3];