Skip to content

Commit bda4be4

Browse files
authored
Move constants and add comments for stress copying (#1008)
Move the constant `DEFRAG_HEADROOM_PERCENT` to `crate::policy::immix` so that all constants needed to be modified to stress copying are adjacent. Add a comment about how to change those constants and the reasons behind.
1 parent 1254d94 commit bda4be4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/policy/immix/defrag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Defrag {
4545
const NUM_BINS: usize = (Block::LINES >> 1) + 1;
4646
const DEFRAG_LINE_REUSE_RATIO: f32 = 0.99;
4747
const MIN_SPILL_THRESHOLD: usize = 2;
48-
const DEFRAG_HEADROOM_PERCENT: usize = 2;
48+
const DEFRAG_HEADROOM_PERCENT: usize = super::DEFRAG_HEADROOM_PERCENT;
4949

5050
/// Allocate a new local histogram.
5151
pub const fn new_histogram(&self) -> Histogram {

src/policy/immix/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,31 @@ pub const BLOCK_ONLY: bool = false;
1717
/// Do we allow Immix to do defragmentation?
1818
pub const DEFRAG: bool = !cfg!(feature = "immix_non_moving"); // defrag if we are allowed to move.
1919

20+
// STRESS COPYING: Set the following options so that Immix will copy as many objects as possible.
21+
// Useful for debugging copying GC if you cannot use SemiSpace.
22+
//
23+
// | constant | when | value | comment |
24+
// |---------------------------|---------|---------|----------------------------------------------------------------------|
25+
// | `STRESS_DEFRAG` | default | `false` | By default, Immix only does defrag GC when necessary. |
26+
// | `STRESS_DEFRAG` | stress | `true` | Set to `true` to force every GC to be defrag GC. |
27+
// | | | | |
28+
// | `DEFRAG_EVERY_BLOCK` | default | `false` | By default, Immix only defrags the most heavily fragmented blocks. |
29+
// | `DEFRAG_EVERY_BLOCK` | stress | `true` | Set to `true` to make every block a defrag source. |
30+
// | | | | |
31+
// | `DEFRAG_HEADROOM_PERCENT` | default | `2` | Immix stops copying when space exhausted. |
32+
// | `DEFRAG_HEADROOM_PERCENT` | stress | `50` | Reserve enough headroom to copy all objects. 50% is like SemiSpace. |
33+
2034
/// Make every GC a defragment GC. (for debugging)
2135
pub const STRESS_DEFRAG: bool = false;
2236

2337
/// Mark every allocated block as defragmentation source before GC. (for debugging)
24-
/// Set both this and `STRESS_DEFRAG` to true to make Immix move as many objects as possible.
2538
pub const DEFRAG_EVERY_BLOCK: bool = false;
2639

40+
/// Percentage of heap size reserved for defragmentation.
41+
/// According to [this paper](https://doi.org/10.1145/1375581.1375586), Immix works well with
42+
/// headroom between 1% to 3% of the heap size.
43+
pub const DEFRAG_HEADROOM_PERCENT: usize = 2;
44+
2745
/// If Immix is used as a nursery space, do we prefer copy?
2846
pub const PREFER_COPY_ON_NURSERY_GC: bool =
2947
!cfg!(feature = "immix_non_moving") && !cfg!(feature = "sticky_immix_non_moving_nursery"); // copy nursery objects if we are allowed to move.

0 commit comments

Comments
 (0)