Skip to content

Commit

Permalink
Fix issue in decommit_ephemeral_segment_pages (segment case). (dotnet…
Browse files Browse the repository at this point in the history
…#59989)

We assume that we can use half the free list space in gen 0 for new allocation. If that is too optimistic, we may allocate into decommitted memory and crash in the allocator. That is because there is a race condition between the allocating thread and the decommitting thread - we decided to avoid that by making sure we would never decommit memory that we may allocate in gen 0.

There are two reasons why assuming we can use half the free list space for new allocations may be too optimistic:
 - if we allocate large objects in gen 0, we may not have free spaces of the necessary size available.
- when background GC goes into background_ephemeral_sweep, it deletes and rebuilds the free list for gen 0. A thread trying to allocate during that time may see a completely empty free list.
  • Loading branch information
PeterSolMS authored Oct 8, 2021
1 parent 2880cc1 commit 971479e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38748,7 +38748,7 @@ void gc_heap::decommit_ephemeral_segment_pages()

dynamic_data* dd0 = dynamic_data_of (0);

ptrdiff_t desired_allocation = estimate_gen_growth (soh_gen0) +
ptrdiff_t desired_allocation = dd_new_allocation (dd0) +
estimate_gen_growth (soh_gen1) +
loh_size_threshold;

Expand Down

0 comments on commit 971479e

Please sign in to comment.