Skip to content

Commit a141bc3

Browse files
authored
Merge pull request #163 from shwestrick/cgc-controls
Some runtime controls for CGC
2 parents 0595da0 + 020f4e8 commit a141bc3

10 files changed

Lines changed: 58 additions & 3 deletions

File tree

basis-library/mpl/gc.sig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ sig
2424
val numberSuspectsMarked: unit -> IntInf.int
2525
val numberSuspectsCleared: unit -> IntInf.int
2626

27+
val getControlMaxCCDepth: unit -> int
28+
2729
(* The following are all cumulative statistics (initially 0, and only
2830
* increase throughout execution).
2931
*

basis-library/mpl/gc.sml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ struct
4343
fun numberEntanglementsDetected () =
4444
C_UIntmax.toLargeInt (GC.numberEntanglementsDetected (gcState ()))
4545

46+
fun getControlMaxCCDepth () =
47+
Word32.toInt (GC.getControlMaxCCDepth (gcState ()))
48+
4649
fun numberSuspectsMarked () =
4750
C_UIntmax.toLargeInt (GC.numberSuspectsMarked (gcState ()))
4851

basis-library/primitive/prim-mlton.sml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ structure GC =
149149
val setSummary = _import "GC_setControlsSummary" private: GCState.t * bool -> unit;
150150
val unpack = _import "GC_unpack" runtime private: GCState.t -> unit;
151151

152+
val getControlMaxCCDepth = _import "GC_getControlMaxCCDepth" runtime private: GCState.t -> Word32.word;
153+
152154
(* SAM_NOTE: TODO: move these to prim-mpl.sml *)
153155
val getLocalGCMillisecondsOfProc = _import "GC_getLocalGCMillisecondsOfProc" runtime private : GCState.t * Word32.word -> C_UIntmax.t;
154156
val getPromoMillisecondsOfProc = _import "GC_getPromoMillisecondsOfProc" runtime private : GCState.t * Word32.word -> C_UIntmax.t;

basis-library/schedulers/shh/Scheduler.sml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ struct
4343
| SOME m => depth < m
4444
end
4545

46+
val maxCCDepth = MPL.GC.getControlMaxCCDepth ()
47+
4648
val P = MLton.Parallel.numberOfProcessors
4749
val internalGCThresh = Real.toInt IEEEReal.TO_POSINF
4850
((Math.log10(Real.fromInt P)) / (Math.log10 (2.0)))
@@ -426,7 +428,7 @@ struct
426428
val depth = HH.getDepth thread
427429
in
428430
(* if ccOkayAtThisDepth andalso depth = 1 then *)
429-
if ccOkayAtThisDepth andalso depth >= 1 andalso depth <= 3 then
431+
if ccOkayAtThisDepth andalso depth >= 1 andalso depth <= maxCCDepth then
430432
forkGC thread depth (f, g)
431433
else if depth < Queue.capacity andalso depthOkayForDECheck depth then
432434
parfork thread depth (f, g)

basis-library/schedulers/shh/sources.mlb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local
22
$(SML_LIB)/basis/basis.mlb
33
$(SML_LIB)/basis/mlton.mlb
4+
$(SML_LIB)/basis/mpl.mlb
45
$(SML_LIB)/basis/unsafe.mlb
56

67
local

runtime/gc/controls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ struct HM_HierarchicalHeapConfig {
3434
/* smallest amount for a CC */
3535
size_t minCCSize;
3636

37+
size_t maxCCChainLength;
38+
double ccThresholdRatio;
39+
uint32_t maxCCDepth;
40+
3741
/* the shallowest depth that will be claimed for a local
3842
* collection. */
3943
uint32_t minLocalDepth;

runtime/gc/gc_state.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ void GC_setControlsRusageMeasureGC (GC_state s, Bool_t b) {
7777
s->controls->rusageMeasureGC = (bool)b;
7878
}
7979

80+
uint32_t GC_getControlMaxCCDepth(GC_state s) {
81+
return (uint32_t)s->controls->hhConfig.maxCCDepth;
82+
}
83+
8084
// SAM_NOTE: TODO: remove this and replace with blocks statistics
8185
size_t GC_getMaxChunkPoolOccupancy (void) {
8286
return 0;

runtime/gc/gc_state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ PRIVATE uintmax_t GC_numChecksSkipped(GC_state s);
143143
PRIVATE uintmax_t GC_numSuspectsMarked(GC_state s);
144144
PRIVATE uintmax_t GC_numSuspectsCleared(GC_state s);
145145

146+
PRIVATE uint32_t GC_getControlMaxCCDepth(GC_state s);
147+
146148
PRIVATE pointer GC_getCallFromCHandlerThread (GC_state s);
147149
PRIVATE void GC_setCallFromCHandlerThreads (GC_state s, pointer p);
148150
PRIVATE pointer GC_getCurrentThread (GC_state s);

runtime/gc/hierarchical-heap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ bool checkPolicyforRoot(
804804
cursor = cursor->subHeapForCC)
805805
{
806806
chainLen++;
807-
if (chainLen > 2)
807+
if (chainLen > s->controls->hhConfig.maxCCChainLength)
808808
return FALSE;
809809
}
810810

@@ -817,7 +817,7 @@ bool checkPolicyforRoot(
817817
HM_HH_getConcurrentPack(cursor)->bytesSurvivedLastCollection;
818818
}
819819

820-
if((2*bytesSurvived) >
820+
if((s->controls->hhConfig.ccThresholdRatio * bytesSurvived) >
821821
(HM_HH_getConcurrentPack(hh)->bytesAllocatedSinceLastCollection)
822822
|| bytesSurvived == 0) {
823823
// if (!HM_HH_getConcurrentPack(hh)->shouldCollect) {

runtime/gc/init.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,16 @@ int processAtMLton (GC_state s, int start, int argc, char **argv,
355355
if (s->controls->hhConfig.collectionThresholdRatio < 1.0) {
356356
die("%s collection-threshold-ratio must be at least 1.0", atName);
357357
}
358+
} else if (0 == strcmp (arg, "cc-threshold-ratio")) {
359+
i++;
360+
if (i == argc || (0 == strcmp (argv[i], "--"))) {
361+
die ("%s cc-threshold-ratio missing argument.", atName);
362+
}
363+
364+
s->controls->hhConfig.ccThresholdRatio = stringToFloat(argv[i++]);
365+
if (s->controls->hhConfig.ccThresholdRatio <= 1.0) {
366+
die("%s cc-threshold-ratio must be > 1.0", atName);
367+
}
358368
} else if (0 == strcmp(arg, "min-collection-size")) {
359369
i++;
360370
if (i == argc || (0 == strcmp (argv[i], "--"))) {
@@ -369,6 +379,17 @@ int processAtMLton (GC_state s, int start, int argc, char **argv,
369379
}
370380

371381
s->controls->hhConfig.minCCSize = stringToBytes(argv[i++]);
382+
} else if (0 == strcmp(arg, "max-cc-chain-length")) {
383+
i++;
384+
if (i == argc || (0 == strcmp (argv[i], "--"))) {
385+
die ("%s max-cc-chain-length missing argument.", atName);
386+
}
387+
388+
int len = stringToInt(argv[i++]);
389+
if (len <= 0) {
390+
die ("%s max-cc-chain-length must be >= 1", atName);
391+
}
392+
s->controls->hhConfig.maxCCChainLength = len;
372393
} else if (0 == strcmp(arg, "min-collection-depth")) {
373394
i++;
374395
if (i == argc || (0 == strcmp (argv[i], "--"))) {
@@ -380,6 +401,17 @@ int processAtMLton (GC_state s, int start, int argc, char **argv,
380401
die ("%s min-collection-depth must be > 0", atName);
381402
}
382403
s->controls->hhConfig.minLocalDepth = minDepth;
404+
} else if (0 == strcmp(arg, "max-cc-depth")) {
405+
i++;
406+
if (i == argc || (0 == strcmp (argv[i], "--"))) {
407+
die ("%s max-cc-depth missing argument.", atName);
408+
}
409+
410+
int maxd = stringToInt(argv[i++]);
411+
if (maxd < 0) {
412+
die ("%s max-cc-depth must be >= 0", atName);
413+
}
414+
s->controls->hhConfig.maxCCDepth = maxd;
383415
} else if (0 == strcmp(arg, "trace-buffer-size")) {
384416
i++;
385417
if (i == argc || (0 == strcmp (argv[i], "--"))) {
@@ -434,6 +466,9 @@ int GC_init (GC_state s, int argc, char **argv) {
434466
s->controls->hhConfig.collectionThresholdRatio = 8.0;
435467
s->controls->hhConfig.minCollectionSize = 1024L * 1024L;
436468
s->controls->hhConfig.minCCSize = 1024L * 1024L;
469+
s->controls->hhConfig.maxCCChainLength = 2;
470+
s->controls->hhConfig.ccThresholdRatio = 2.0f;
471+
s->controls->hhConfig.maxCCDepth = 3;
437472
s->controls->hhConfig.minLocalDepth = 2;
438473
s->controls->rusageMeasureGC = FALSE;
439474
s->controls->summary = FALSE;

0 commit comments

Comments
 (0)