Skip to content

Commit 8f8cc56

Browse files
committed
WIP: Commit reason tracking
1 parent bd052be commit 8f8cc56

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/coreclr/gc/gc.cpp

+20-19
Original file line numberDiff line numberDiff line change
@@ -6066,6 +6066,7 @@ void gc_heap::release_segment (heap_segment* sg)
60666066
FIRE_EVENT(GCFreeSegment_V1, heap_segment_mem(sg));
60676067
size_t reserved_size = (uint8_t*)heap_segment_reserved (sg) - (uint8_t*)sg;
60686068
reduce_committed_bytes (
6069+
28973,
60696070
sg,
60706071
((uint8_t*)heap_segment_committed (sg) - (uint8_t*)sg),
60716072
(int) heap_segment_oh (sg)
@@ -7289,7 +7290,7 @@ bool gc_heap::virtual_alloc_commit_for_heap (void* addr, size_t size, int h_numb
72897290
return GCToOSInterface::VirtualCommit(addr, size);
72907291
}
72917292

7292-
bool gc_heap::virtual_commit (void* address, size_t size, int bucket, int h_number, bool* hard_limit_exceeded_p)
7293+
bool gc_heap::virtual_commit (int reason, void* address, size_t size, int bucket, int h_number, bool* hard_limit_exceeded_p)
72937294
{
72947295
/**
72957296
* Here are all the possible cases for the commits:
@@ -7309,7 +7310,7 @@ bool gc_heap::virtual_commit (void* address, size_t size, int bucket, int h_numb
73097310
assert(bucket != recorded_committed_free_bucket);
73107311
#endif //USE_REGIONS
73117312

7312-
STRESS_LOG_VA (1, ("commit-accounting: commit in %d [%p, %p) for heap %d", bucket, address, ((uint8_t*)address + size), h_number));
7313+
STRESS_LOG_VA (1, ("commit-accounting: commit in %d [%p, %p) for heap %d with reason %d", bucket, address, ((uint8_t*)address + size), h_number, reason));
73137314
bool should_count =
73147315
#ifdef USE_REGIONS
73157316
true;
@@ -7402,12 +7403,12 @@ bool gc_heap::virtual_commit (void* address, size_t size, int bucket, int h_numb
74027403
return commit_succeeded_p;
74037404
}
74047405

7405-
void gc_heap::reduce_committed_bytes (void* address, size_t size, int bucket, int h_number, bool decommit_succeeded_p)
7406+
void gc_heap::reduce_committed_bytes (int reason, void* address, size_t size, int bucket, int h_number, bool decommit_succeeded_p)
74067407
{
74077408
assert(0 <= bucket && bucket < recorded_committed_bucket_counts);
74087409
assert(bucket < total_oh_count || h_number == -1);
74097410

7410-
STRESS_LOG_VA (1, ("commit-accounting: decommit in %d [%p, %p) for heap %d", bucket, address, ((uint8_t*)address + size), h_number));
7411+
STRESS_LOG_VA (1, ("commit-accounting: decommit in %d [%p, %p) for heap %d with reason", bucket, address, ((uint8_t*)address + size), h_number, reason));
74117412

74127413
#ifndef USE_REGIONS
74137414
if (bucket != recorded_committed_ignored_bucket)
@@ -7435,7 +7436,7 @@ void gc_heap::reduce_committed_bytes (void* address, size_t size, int bucket, in
74357436
}
74367437
}
74377438

7438-
bool gc_heap::virtual_decommit (void* address, size_t size, int bucket, int h_number)
7439+
bool gc_heap::virtual_decommit (int reason, void* address, size_t size, int bucket, int h_number)
74397440
{
74407441
/**
74417442
* Here are all possible cases for the decommits:
@@ -7450,7 +7451,7 @@ bool gc_heap::virtual_decommit (void* address, size_t size, int bucket, int h_nu
74507451

74517452
bool decommit_succeeded_p = ((bucket != recorded_committed_bookkeeping_bucket) && use_large_pages_p) ? true : GCToOSInterface::VirtualDecommit (address, size);
74527453

7453-
reduce_committed_bytes (address, size, bucket, h_number, decommit_succeeded_p);
7454+
reduce_committed_bytes (reason, address, size, bucket, h_number, decommit_succeeded_p);
74547455

74557456
return decommit_succeeded_p;
74567457
}
@@ -9086,7 +9087,7 @@ void gc_heap::destroy_card_table_helper (uint32_t* c_table)
90869087
uint8_t* highest = card_table_highest_address (c_table);
90879088
get_card_table_element_layout(lowest, highest, card_table_element_layout);
90889089
size_t result = card_table_element_layout[seg_mapping_table_element + 1];
9089-
gc_heap::reduce_committed_bytes (&card_table_refcount(c_table), result, recorded_committed_bookkeeping_bucket, -1, true);
9090+
gc_heap::reduce_committed_bytes (28972, &card_table_refcount(c_table), result, recorded_committed_bookkeeping_bucket, -1, true);
90909091

90919092
// If we don't put the mark array committed in the ignored bucket, then this is where to account for the decommit of it
90929093
}
@@ -9346,7 +9347,7 @@ bool gc_heap::inplace_commit_card_table (uint8_t* from, uint8_t* to)
93469347
bool succeed;
93479348
if (commit_sizes[i] > 0)
93489349
{
9349-
succeed = virtual_commit (commit_begins[i], commit_sizes[i], recorded_committed_bookkeeping_bucket);
9350+
succeed = virtual_commit (28967, commit_begins[i], commit_sizes[i], recorded_committed_bookkeeping_bucket);
93509351
if (!succeed)
93519352
{
93529353
failed_commit = i;
@@ -9368,7 +9369,7 @@ bool gc_heap::inplace_commit_card_table (uint8_t* from, uint8_t* to)
93689369
bool succeed;
93699370
if (commit_sizes[i] > 0)
93709371
{
9371-
succeed = virtual_decommit (commit_begins[i], commit_sizes[i], recorded_committed_bookkeeping_bucket);
9372+
succeed = virtual_decommit (28968, commit_begins[i], commit_sizes[i], recorded_committed_bookkeeping_bucket);
93729373
assert (succeed);
93739374
}
93749375
}
@@ -9419,7 +9420,7 @@ uint32_t* gc_heap::make_card_table (uint8_t* start, uint8_t* end)
94199420
// in case of background gc, the mark array will be committed separately (per segment).
94209421
size_t commit_size = card_table_element_layout[seg_mapping_table_element + 1];
94219422

9422-
if (!virtual_commit (mem, commit_size, recorded_committed_bookkeeping_bucket))
9423+
if (!virtual_commit (28960, mem, commit_size, recorded_committed_bookkeeping_bucket))
94239424
{
94249425
dprintf (1, ("Card table commit failed"));
94259426
GCToOSInterface::VirtualRelease (mem, alloc_size);
@@ -9594,7 +9595,7 @@ int gc_heap::grow_brick_card_tables (uint8_t* start,
95949595
// in case of background gc, the mark array will be committed separately (per segment).
95959596
size_t commit_size = card_table_element_layout[seg_mapping_table_element + 1];
95969597

9597-
if (!virtual_commit (mem, commit_size, recorded_committed_bookkeeping_bucket))
9598+
if (!virtual_commit (28961, mem, commit_size, recorded_committed_bookkeeping_bucket))
95989599
{
95999600
dprintf (GC_TABLE_LOG, ("Table commit failed"));
96009601
set_fgm_result (fgm_commit_table, commit_size, uoh_p);
@@ -12274,7 +12275,7 @@ heap_segment* gc_heap::make_heap_segment (uint8_t* new_pages, size_t size, gc_he
1227412275
0;
1227512276
#endif //MULTIPLE_HEAPS
1227612277

12277-
if (!virtual_commit (new_pages, initial_commit, oh, h_number))
12278+
if (!virtual_commit (28962, new_pages, initial_commit, oh, h_number))
1227812279
{
1227912280
return 0;
1228012281
}
@@ -12460,7 +12461,7 @@ size_t gc_heap::decommit_heap_segment_pages_worker (heap_segment* seg,
1246012461
ptrdiff_t size = heap_segment_committed (seg) - page_start;
1246112462
if (size > 0)
1246212463
{
12463-
bool decommit_succeeded_p = virtual_decommit (page_start, (size_t)size, heap_segment_oh (seg), heap_number);
12464+
bool decommit_succeeded_p = virtual_decommit (28963, page_start, (size_t)size, heap_segment_oh (seg), heap_number);
1246412465
if (decommit_succeeded_p)
1246512466
{
1246612467
dprintf (3, ("Decommitting heap segment [%zx, %zx[(%zd)",
@@ -12501,7 +12502,7 @@ void gc_heap::decommit_heap_segment (heap_segment* seg)
1250112502

1250212503
assert (heap_segment_committed (seg) >= page_start);
1250312504
size_t size = heap_segment_committed (seg) - page_start;
12504-
bool decommit_succeeded_p = virtual_decommit (page_start, size, heap_segment_oh (seg), heap_number);
12505+
bool decommit_succeeded_p = virtual_decommit (28964, page_start, size, heap_segment_oh (seg), heap_number);
1250512506

1250612507
if (decommit_succeeded_p)
1250712508
{
@@ -13269,7 +13270,7 @@ void gc_heap::distribute_free_regions()
1326913270
size_t end_space = heap_segment_committed (region) - aligned_allocated;
1327013271
if (end_space > 0)
1327113272
{
13272-
virtual_decommit (aligned_allocated, end_space, gen_to_oh (i), hn);
13273+
virtual_decommit (28969, aligned_allocated, end_space, gen_to_oh (i), hn);
1327313274
heap_segment_committed (region) = aligned_allocated;
1327413275
heap_segment_used (region) = min (heap_segment_used (region), heap_segment_committed (region));
1327513276
assert (heap_segment_committed (region) > heap_segment_mem (region));
@@ -15463,7 +15464,7 @@ BOOL gc_heap::grow_heap_segment (heap_segment* seg, uint8_t* high_address, bool*
1546315464
"Growing heap_segment: %zx high address: %zx\n",
1546415465
(size_t)seg, (size_t)high_address);
1546515466

15466-
bool ret = virtual_commit (heap_segment_committed (seg), c_size, heap_segment_oh (seg), heap_number, hard_limit_exceeded_p);
15467+
bool ret = virtual_commit (28965, heap_segment_committed (seg), c_size, heap_segment_oh (seg), heap_number, hard_limit_exceeded_p);
1546715468
if (ret)
1546815469
{
1546915470
heap_segment_committed (seg) += c_size;
@@ -37731,7 +37732,7 @@ BOOL gc_heap::commit_mark_array_by_range (uint8_t* begin, uint8_t* end, uint32_t
3773137732
size));
3773237733
#endif //SIMPLE_DPRINTF
3773337734

37734-
if (virtual_commit (commit_start, size, recorded_committed_mark_array_bucket))
37735+
if (virtual_commit (28966, commit_start, size, recorded_committed_mark_array_bucket))
3773537736
{
3773637737
// We can only verify the mark array is cleared from begin to end, the first and the last
3773737738
// page aren't necessarily all cleared 'cause they could be used by other segments or
@@ -37956,7 +37957,7 @@ void gc_heap::decommit_mark_array_by_seg (heap_segment* seg)
3795637957

3795737958
if (decommit_start < decommit_end)
3795837959
{
37959-
if (!virtual_decommit (decommit_start, size, recorded_committed_mark_array_bucket))
37960+
if (!virtual_decommit (28970, decommit_start, size, recorded_committed_mark_array_bucket))
3796037961
{
3796137962
dprintf (GC_TABLE_LOG, ("decommit on %p for %zd bytes failed",
3796237963
decommit_start, size));
@@ -44167,7 +44168,7 @@ size_t gc_heap::decommit_region (heap_segment* region, int bucket, int h_number)
4416744168
uint8_t* page_start = align_lower_page (get_region_start (region));
4416844169
uint8_t* decommit_end = heap_segment_committed (region);
4416944170
size_t decommit_size = decommit_end - page_start;
44170-
bool decommit_succeeded_p = virtual_decommit (page_start, decommit_size, bucket, h_number);
44171+
bool decommit_succeeded_p = virtual_decommit (28971, page_start, decommit_size, bucket, h_number);
4417144172
bool require_clearing_memory_p = !decommit_succeeded_p || use_large_pages_p;
4417244173
dprintf (REGIONS_LOG, ("decommitted region %p(%p-%p) (%zu bytes) - success: %d",
4417344174
region,

src/coreclr/gc/gcpriv.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2393,9 +2393,9 @@ class gc_heap
23932393
#endif //USE_REGIONS
23942394
PER_HEAP_METHOD void decommit_heap_segment (heap_segment* seg);
23952395
PER_HEAP_ISOLATED_METHOD bool virtual_alloc_commit_for_heap (void* addr, size_t size, int h_number);
2396-
PER_HEAP_ISOLATED_METHOD bool virtual_commit (void* address, size_t size, int bucket, int h_number=-1, bool* hard_limit_exceeded_p=NULL);
2397-
PER_HEAP_ISOLATED_METHOD bool virtual_decommit (void* address, size_t size, int bucket, int h_number=-1);
2398-
PER_HEAP_ISOLATED_METHOD void reduce_committed_bytes (void* address, size_t size, int bucket, int h_number, bool decommit_succeeded_p);
2396+
PER_HEAP_ISOLATED_METHOD bool virtual_commit (int reason, void* address, size_t size, int bucket, int h_number=-1, bool* hard_limit_exceeded_p=NULL);
2397+
PER_HEAP_ISOLATED_METHOD bool virtual_decommit (int reason, void* address, size_t size, int bucket, int h_number=-1);
2398+
PER_HEAP_ISOLATED_METHOD void reduce_committed_bytes (int reason, void* address, size_t size, int bucket, int h_number, bool decommit_succeeded_p);
23992399
friend void destroy_card_table (uint32_t*);
24002400
PER_HEAP_ISOLATED_METHOD void destroy_card_table_helper (uint32_t* c_table);
24012401
PER_HEAP_ISOLATED_METHOD void virtual_free (void* add, size_t size, heap_segment* sg=NULL);

0 commit comments

Comments
 (0)