From b720a44d65e1f3b1e1fccac6323a03d331eebf0b Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Sat, 19 Mar 2016 23:31:00 +0000 Subject: [PATCH] Improving design document with references and separating ideas from current implementation. Copied from Perforce Change: 190214 ServerID: perforce.ravenbrook.com --- mps/code/config.h | 2 +- mps/design/write-barrier.txt | 38 ++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/mps/code/config.h b/mps/code/config.h index 40702f86312..b7de3a7a227 100644 --- a/mps/code/config.h +++ b/mps/code/config.h @@ -675,7 +675,7 @@ * TODO: These settings were determined by trial and error, but should * be based on measurement of the protection overhead on each * platform. We know it's extremely different between OS X and - * Windows, for example. + * Windows, for example. See design.mps.write-barrier.improv.by-os. * * TODO: Consider basing the count on the amount of time that has * passed in the mutator rather than the number of scans. diff --git a/mps/design/write-barrier.txt b/mps/design/write-barrier.txt index 2a712ddd99c..affdaa49c5d 100644 --- a/mps/design/write-barrier.txt +++ b/mps/design/write-barrier.txt @@ -39,12 +39,9 @@ logical AND operation. Write barrier deferral ---------------------- -.deferral: The overheads hardware barriers varies widely between -operating systems. On Windows it is very cheap to change memory -protection and to handle protecion faults. On OS X it is very -expensive. The balance between barriers and scanning work is -different. There is no point in spending 1000 CPU units raising a -write barrier to avoid 10 CPU units of scanning cost. +.deferral: Both scanning and the write barrier cost CPU time, and +these must be balanced. There is no point spending 1000 CPU units +raising a write barrier to avoid 10 CPU units of scanning cost. The MPS balances these costs with write barrier deferral. The write barrier is not immediately raised when a segment is scanned. Instead, @@ -60,13 +57,38 @@ three events: 3. a barrier hit (``WB_DEFER_HIT``) -See also job003975. + +Improvements +------------ + +.improv.by-os: The overheads hardware barriers varies widely between +operating systems. On Windows it is very cheap to change memory +protection and to handle protecion faults. On OS X it is very +expensive. The balance between barriers and scanning work is +different. We should measure the relative costs and tune the deferral +for each separately. + +.improv.balance: Hardware costs of write barriers vary by OS, but +scanning costs vary depending on many factors including client code. +The MPS could dynamically measure these costs, perhaps using fast +cycle counters such as RDTSC, and use this to dynamically balance the +write barrier deferral. +References +---------- + +.. [job003975] "Poor performance due to imbalance between protection + and scanning costs"; Richard Brooksby; Ravenbrook + Limited; 2016-03-11; + . + + Document History ---------------- -- 2016-03-19 RB_ Created. +- 2016-03-19 RB_ Created during preparation of + branch/2016-03-13/defer-write-barrier for [job003975]_. .. _RB: http://www.ravenbrook.com/consultants/rb/