Skip to content

Commit 43bf2c8

Browse files
authored
ensure GC_FINAL_STATS is consistent with new page metadata layout (#50374)
* ensure GC_FINAL_STATS is consistent with new page metadata layout
1 parent ecca2c5 commit 43bf2c8

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

src/gc-debug.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -744,45 +744,37 @@ void gc_final_pause_end(int64_t t0, int64_t tend)
744744

745745
static void gc_stats_pagetable0(pagetable0_t *pagetable0, unsigned *p0)
746746
{
747-
for (int pg_i = 0; pg_i < REGION0_PG_COUNT / 32; pg_i++) {
748-
uint32_t line = pagetable0->allocmap[pg_i] | pagetable0->freemap[pg_i];
749-
if (line) {
750-
for (int j = 0; j < 32; j++) {
751-
if ((line >> j) & 1) {
752-
(*p0)++;
753-
}
754-
}
747+
for (int pg_i = 0; pg_i < REGION0_PG_COUNT; pg_i++) {
748+
uint8_t meta = pagetable0->meta[pg_i];
749+
assert(meta == GC_PAGE_UNMAPPED || meta == GC_PAGE_ALLOCATED ||
750+
meta == GC_PAGE_LAZILY_FREED || meta == GC_PAGE_FREED);
751+
if (meta != GC_PAGE_UNMAPPED) {
752+
(*p0)++;
755753
}
756754
}
757755
}
758756

759757
static void gc_stats_pagetable1(pagetable1_t *pagetable1, unsigned *p1, unsigned *p0)
760758
{
761-
for (int pg_i = 0; pg_i < REGION1_PG_COUNT / 32; pg_i++) {
762-
uint32_t line = pagetable1->allocmap0[pg_i] | pagetable1->freemap0[pg_i];
763-
if (line) {
764-
for (int j = 0; j < 32; j++) {
765-
if ((line >> j) & 1) {
766-
(*p1)++;
767-
gc_stats_pagetable0(pagetable1->meta0[pg_i * 32 + j], p0);
768-
}
769-
}
759+
for (int pg_i = 0; pg_i < REGION1_PG_COUNT; pg_i++) {
760+
pagetable0_t *pagetable0 = pagetable1->meta0[pg_i];
761+
if (pagetable0 == NULL) {
762+
continue;
770763
}
764+
(*p1)++;
765+
gc_stats_pagetable0(pagetable0, p0);
771766
}
772767
}
773768

774769
static void gc_stats_pagetable(unsigned *p2, unsigned *p1, unsigned *p0)
775770
{
776-
for (int pg_i = 0; pg_i < (REGION2_PG_COUNT + 31) / 32; pg_i++) {
777-
uint32_t line = memory_map.allocmap1[pg_i] | memory_map.freemap1[pg_i];
778-
if (line) {
779-
for (int j = 0; j < 32; j++) {
780-
if ((line >> j) & 1) {
781-
(*p2)++;
782-
gc_stats_pagetable1(memory_map.meta1[pg_i * 32 + j], p1, p0);
783-
}
784-
}
771+
for (int pg_i = 0; pg_i < REGION2_PG_COUNT; pg_i++) {
772+
pagetable1_t *pagetable1 = alloc_map.meta1[pg_i];
773+
if (pagetable1 == NULL) {
774+
continue;
785775
}
776+
(*p2)++;
777+
gc_stats_pagetable1(pagetable1, p1, p0);
786778
}
787779
}
788780

@@ -791,7 +783,7 @@ void jl_print_gc_stats(JL_STREAM *s)
791783
#ifdef _OS_LINUX_
792784
malloc_stats();
793785
#endif
794-
double ptime = jl_clock_now() - process_t0;
786+
double ptime = jl_hrtime() - process_t0;
795787
jl_safe_printf("exec time\t%.5f sec\n", ptime);
796788
if (gc_num.pause > 0) {
797789
jl_safe_printf("gc time \t%.5f sec (%2.1f%%) in %d (%d full) collections\n",
@@ -1012,7 +1004,7 @@ void jl_gc_debug_init(void)
10121004
#endif
10131005

10141006
#ifdef GC_FINAL_STATS
1015-
process_t0 = jl_clock_now();
1007+
process_t0 = jl_hrtime();
10161008
#endif
10171009
}
10181010

src/gc-pages.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ NOINLINE jl_gc_pagemeta_t *jl_gc_alloc_page(void) JL_NOTSAFEPOINT
100100
// try to get page from `pool_lazily_freed`
101101
meta = pop_lf_page_metadata_back(&global_page_pool_lazily_freed);
102102
if (meta != NULL) {
103-
gc_alloc_map_set(meta->data, 1);
103+
gc_alloc_map_set(meta->data, GC_PAGE_ALLOCATED);
104104
// page is already mapped
105105
return meta;
106106
}
107107

108108
// try to get page from `pool_clean`
109109
meta = pop_lf_page_metadata_back(&global_page_pool_clean);
110110
if (meta != NULL) {
111-
gc_alloc_map_set(meta->data, 1);
111+
gc_alloc_map_set(meta->data, GC_PAGE_ALLOCATED);
112112
goto exit;
113113
}
114114

115115
// try to get page from `pool_freed`
116116
meta = pop_lf_page_metadata_back(&global_page_pool_freed);
117117
if (meta != NULL) {
118-
gc_alloc_map_set(meta->data, 1);
118+
gc_alloc_map_set(meta->data, GC_PAGE_ALLOCATED);
119119
goto exit;
120120
}
121121

@@ -155,7 +155,7 @@ NOINLINE jl_gc_pagemeta_t *jl_gc_alloc_page(void) JL_NOTSAFEPOINT
155155
void jl_gc_free_page(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT
156156
{
157157
void *p = pg->data;
158-
gc_alloc_map_set((char*)p, 0);
158+
gc_alloc_map_set((char*)p, GC_PAGE_FREED);
159159
// tell the OS we don't need these pages right now
160160
size_t decommit_size = GC_PAGE_SZ;
161161
if (GC_PAGE_SZ < jl_page_size) {

src/gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
14511451
push_lf_page_metadata_back(&global_page_pool_freed, pg);
14521452
}
14531453
else {
1454+
gc_alloc_map_set(pg->data, GC_PAGE_LAZILY_FREED);
14541455
push_lf_page_metadata_back(&global_page_pool_lazily_freed, pg);
14551456
}
14561457
#else

src/gc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ typedef struct {
257257
pagetable1_t *meta1[REGION2_PG_COUNT];
258258
} pagetable_t;
259259

260+
#define GC_PAGE_UNMAPPED 0
261+
#define GC_PAGE_ALLOCATED 1
262+
#define GC_PAGE_LAZILY_FREED 2
263+
#define GC_PAGE_FREED 3
264+
260265
extern pagetable_t alloc_map;
261266

262267
STATIC_INLINE uint8_t gc_alloc_map_is_set(char *_data) JL_NOTSAFEPOINT
@@ -272,7 +277,7 @@ STATIC_INLINE uint8_t gc_alloc_map_is_set(char *_data) JL_NOTSAFEPOINT
272277
if (r0 == NULL)
273278
return 0;
274279
i = REGION0_INDEX(data);
275-
return r0->meta[i];
280+
return (r0->meta[i] == GC_PAGE_ALLOCATED);
276281
}
277282

278283
STATIC_INLINE void gc_alloc_map_set(char *_data, uint8_t v) JL_NOTSAFEPOINT

0 commit comments

Comments
 (0)