Skip to content

Commit 10c2c85

Browse files
committed
Backport Improve scalability of page allocator (JuliaLang#50137)
1 parent 1a4ded1 commit 10c2c85

File tree

7 files changed

+323
-529
lines changed

7 files changed

+323
-529
lines changed

src/gc-debug.c

Lines changed: 19 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@ jl_gc_pagemeta_t *jl_gc_page_metadata(void *data)
2727
// the end of the page.
2828
JL_DLLEXPORT jl_taggedvalue_t *jl_gc_find_taggedvalue_pool(char *p, size_t *osize_p)
2929
{
30-
if (!page_metadata(p))
30+
if (!gc_alloc_map_is_set(p))
3131
// Not in the pool
3232
return NULL;
33-
struct jl_gc_metadata_ext info = page_metadata_ext(p);
33+
jl_gc_pagemeta_t *meta = page_metadata(p);
3434
char *page_begin = gc_page_data(p) + GC_PAGE_OFFSET;
3535
// In the page header
3636
if (p < page_begin)
3737
return NULL;
3838
size_t ofs = p - page_begin;
39-
// Check if this is a free page
40-
if (!(info.pagetable0->allocmap[info.pagetable0_i32] & (uint32_t)(1 << info.pagetable0_i)))
41-
return NULL;
42-
int osize = info.meta->osize;
39+
int osize = meta->osize;
4340
// Shouldn't be needed, just in case
4441
if (osize == 0)
4542
return NULL;
@@ -111,44 +108,14 @@ static void gc_clear_mark_page(jl_gc_pagemeta_t *pg, int bits)
111108
}
112109
}
113110

114-
static void gc_clear_mark_pagetable0(pagetable0_t *pagetable0, int bits)
115-
{
116-
for (int pg_i = 0; pg_i < REGION0_PG_COUNT / 32; pg_i++) {
117-
uint32_t line = pagetable0->allocmap[pg_i];
118-
if (line) {
119-
for (int j = 0; j < 32; j++) {
120-
if ((line >> j) & 1) {
121-
gc_clear_mark_page(pagetable0->meta[pg_i * 32 + j], bits);
122-
}
123-
}
124-
}
125-
}
126-
}
127-
128-
static void gc_clear_mark_pagetable1(pagetable1_t *pagetable1, int bits)
129-
{
130-
for (int pg_i = 0; pg_i < REGION1_PG_COUNT / 32; pg_i++) {
131-
uint32_t line = pagetable1->allocmap0[pg_i];
132-
if (line) {
133-
for (int j = 0; j < 32; j++) {
134-
if ((line >> j) & 1) {
135-
gc_clear_mark_pagetable0(pagetable1->meta0[pg_i * 32 + j], bits);
136-
}
137-
}
138-
}
139-
}
140-
}
141-
142-
static void gc_clear_mark_pagetable(int bits)
111+
static void gc_clear_mark_outer(int bits)
143112
{
144-
for (int pg_i = 0; pg_i < (REGION2_PG_COUNT + 31) / 32; pg_i++) {
145-
uint32_t line = memory_map.allocmap1[pg_i];
146-
if (line) {
147-
for (int j = 0; j < 32; j++) {
148-
if ((line >> j) & 1) {
149-
gc_clear_mark_pagetable1(memory_map.meta1[pg_i * 32 + j], bits);
150-
}
151-
}
113+
for (int i = 0; i < gc_n_threads; i++) {
114+
jl_ptls_t ptls2 = gc_all_tls_states[i];
115+
jl_gc_pagemeta_t *pg = ptls2->page_metadata_allocd;
116+
while (pg != NULL) {
117+
gc_clear_mark_page(pg, bits);
118+
pg = pg->next;
152119
}
153120
}
154121
}
@@ -184,7 +151,7 @@ static void clear_mark(int bits)
184151
v = v->next;
185152
}
186153

187-
gc_clear_mark_pagetable(bits);
154+
gc_clear_mark_outer(bits);
188155
}
189156

190157
static void restore(void)
@@ -561,7 +528,6 @@ void gc_scrub_record_task(jl_task_t *t)
561528

562529
JL_NO_ASAN static void gc_scrub_range(char *low, char *high)
563530
{
564-
jl_ptls_t ptls = jl_current_task->ptls;
565531
jl_jmp_buf *old_buf = jl_get_safe_restore();
566532
jl_jmp_buf buf;
567533
if (jl_setjmp(buf, 0)) {
@@ -1168,7 +1134,7 @@ void gc_stats_big_obj(void)
11681134
static int64_t poolobj_sizes[4];
11691135
static int64_t empty_pages;
11701136

1171-
static void gc_count_pool_page(jl_gc_pagemeta_t *pg)
1137+
static void gc_count_pool_page(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT
11721138
{
11731139
int osize = pg->osize;
11741140
char *data = pg->data;
@@ -1187,44 +1153,16 @@ static void gc_count_pool_page(jl_gc_pagemeta_t *pg)
11871153
}
11881154
}
11891155

1190-
static void gc_count_pool_pagetable0(pagetable0_t *pagetable0)
1191-
{
1192-
for (int pg_i = 0; pg_i < REGION0_PG_COUNT / 32; pg_i++) {
1193-
uint32_t line = pagetable0->allocmap[pg_i];
1194-
if (line) {
1195-
for (int j = 0; j < 32; j++) {
1196-
if ((line >> j) & 1) {
1197-
gc_count_pool_page(pagetable0->meta[pg_i * 32 + j]);
1198-
}
1199-
}
1200-
}
1201-
}
1202-
}
1203-
1204-
static void gc_count_pool_pagetable1(pagetable1_t *pagetable1)
1205-
{
1206-
for (int pg_i = 0; pg_i < REGION1_PG_COUNT / 32; pg_i++) {
1207-
uint32_t line = pagetable1->allocmap0[pg_i];
1208-
if (line) {
1209-
for (int j = 0; j < 32; j++) {
1210-
if ((line >> j) & 1) {
1211-
gc_count_pool_pagetable0(pagetable1->meta0[pg_i * 32 + j]);
1212-
}
1213-
}
1214-
}
1215-
}
1216-
}
1217-
12181156
static void gc_count_pool_pagetable(void)
12191157
{
1220-
for (int pg_i = 0; pg_i < (REGION2_PG_COUNT + 31) / 32; pg_i++) {
1221-
uint32_t line = memory_map.allocmap1[pg_i];
1222-
if (line) {
1223-
for (int j = 0; j < 32; j++) {
1224-
if ((line >> j) & 1) {
1225-
gc_count_pool_pagetable1(memory_map.meta1[pg_i * 32 + j]);
1226-
}
1158+
for (int i = 0; i < gc_n_threads; i++) {
1159+
jl_ptls_t ptls2 = gc_all_tls_states[i];
1160+
jl_gc_pagemeta_t *pg = ptls2->page_metadata_allocd;
1161+
while (pg != NULL) {
1162+
if (gc_alloc_map_is_set(pg->data)) {
1163+
gc_count_pool_page(pg);
12271164
}
1165+
pg = pg->next;
12281166
}
12291167
}
12301168
}

0 commit comments

Comments
 (0)