Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MEMPROFILE code for the new garbage collector #37246

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 58 additions & 51 deletions src/gc-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,12 @@ static void gc_verify_tags_page(jl_gc_pagemeta_t *pg)
}
// check for p in new newpages list
jl_taggedvalue_t *halfpages = p->newpages;
while (halfpages) {
if (halfpages) {
char *cur_page = gc_page_data((char*)halfpages - 1);
if (cur_page == data) {
lim = (char*)halfpages - 1;
break;
}
halfpages = *(jl_taggedvalue_t**)cur_page;
}
// compute the freelist_map
if (pg->nfree) {
Expand Down Expand Up @@ -1021,53 +1020,51 @@ void gc_debug_init(void)
static size_t pool_stats(jl_gc_pool_t *p, size_t *pwaste, size_t *np,
size_t *pnold)
{
jl_taggedvalue_t *v;
jl_gc_pagemeta_t *pg = p->pages;
jl_taggedvalue_t *halfpages = p->newpages;
size_t osize = p->osize;
size_t nused=0, nfree=0, npgs=0, nold = 0;
size_t nused=0, nfree=0, npgs=0, nold=0;

while (pg != NULL) {
if (halfpages != NULL) {
npgs++;
v = (jl_taggedvalue_t*)(pg->data + GC_PAGE_OFFSET);
char *lim = (char*)v + GC_PAGE_SZ - GC_PAGE_OFFSET - osize;
char *v = gc_page_data(halfpages) + GC_PAGE_OFFSET;
char *lim = (char*)halfpages - 1;
int i = 0;
while ((char*)v <= lim) {
if (!gc_marked(v->bits.gc)) {
while (v <= lim) {
if (!gc_marked(((jl_taggedvalue_t*)v)->bits.gc)) {
nfree++;
}
else {
nused++;
if (v->bits.gc == GC_OLD_MARKED) {
if (((jl_taggedvalue_t*)v)->bits.gc == GC_OLD_MARKED) {
nold++;
}
}
v = (jl_taggedvalue_t*)((char*)v + osize);
v = v + osize;
i++;
}
jl_gc_pagemeta_t *nextpg = NULL;
pg = nextpg;
// only the first page is allocated on
}
*pwaste = npgs * GC_PAGE_SZ - (nused * p->osize);
*np = npgs;
*pnold = nold;
if (npgs != 0) {
jl_safe_printf("%4d : %7d/%7d objects (%3d%% old), %5d pages, %5d kB, %5d kB waste\n",
jl_safe_printf("%4d : %7lld/%7lld objects (%3lld%% old), %5lld pages, %5lld kB, %5lld kB waste\n",
p->osize,
nused,
nused+nfree,
nused ? (nold*100)/nused : 0,
npgs,
(nused*p->osize)/1024,
*pwaste/1024);
(long long)nused,
(long long)(nused + nfree),
(long long)(nused ? (nold * 100) / nused : 0),
(long long)npgs,
(long long)((nused * p->osize) / 1024),
(long long)(*pwaste / 1024));
}
return nused*p->osize;
}

void gc_stats_all_pool(void)
{
size_t nb=0, w, tw=0, no=0,tp=0, nold=0,noldbytes=0, np, nol;
size_t nb=0, w, tw=0, no=0, tp=0, nold=0, noldbytes=0, np, nol;
for (int i = 0; i < JL_GC_N_POOLS; i++) {
for (int t_i = 0;t_i < jl_n_threads;t_i++) {
for (int t_i = 0; t_i < jl_n_threads; t_i++) {
jl_ptls_t ptls2 = jl_all_tls_states[t_i];
size_t b = pool_stats(&ptls2->heap.norm_pools[i], &w, &np, &nol);
nb += b;
Expand All @@ -1078,44 +1075,54 @@ void gc_stats_all_pool(void)
noldbytes += nol * ptls2->heap.norm_pools[i].osize;
}
}
jl_safe_printf("%d objects (%d%% old), %d kB (%d%% old) total allocated, %d total fragments (%d%% overhead), in %d pages\n",
no, (nold*100)/no, nb/1024, (noldbytes*100)/nb, tw, (tw*100)/nb, tp);
jl_safe_printf("%lld objects (%lld%% old), %lld kB (%lld%% old) total allocated, "
"%lld total fragments (%lld%% overhead), in %lld pages\n",
(long long)no,
(long long)(no ? (nold * 100) / no : 0),
(long long)(nb / 1024),
(long long)(nb ? (noldbytes * 100) / nb : 0),
(long long)tw,
(long long)(nb ? (tw * 100) / nb : 0),
(long long)tp);
}

void gc_stats_big_obj(void)
{
bigval_t *v = current_heap->big_objects;
size_t nused=0, nbytes=0;
while (v != NULL) {
if (gc_marked(v->bits.gc)) {
nused++;
nbytes += v->sz&~3;
size_t nused=0, nbytes=0, nused_old=0, nbytes_old=0;
for (int t_i = 0; t_i < jl_n_threads; t_i++) {
jl_ptls_t ptls2 = jl_all_tls_states[t_i];
bigval_t *v = ptls2->heap.big_objects;
while (v != NULL) {
if (gc_marked(v->bits.gc)) {
nused++;
nbytes += v->sz & ~3;
}
v = v->next;
}
v = v->next;
}
v = big_objects_marked;
size_t nused_old=0, nbytes_old=0;
while (v != NULL) {
if (gc_marked(v->bits.gc)) {
nused_old++;
nbytes_old += v->sz&~3;
v = big_objects_marked;
while (v != NULL) {
if (gc_marked(v->bits.gc)) {
nused_old++;
nbytes_old += v->sz & ~3;
}
v = v->next;
}
v = v->next;
}

mallocarray_t *ma = current_heap->mallocarrays;
while (ma != NULL) {
if (gc_marked(jl_astaggedvalue(ma->a)->bits.gc)) {
nused++;
nbytes += array_nbytes(ma->a);
mallocarray_t *ma = ptls2->heap.mallocarrays;
while (ma != NULL) {
if (gc_marked(jl_astaggedvalue(ma->a)->bits.gc)) {
nused++;
nbytes += jl_array_nbytes(ma->a);
}
ma = ma->next;
}
ma = ma->next;
}

jl_safe_printf("%d kB (%d%% old) in %d large objects (%d%% old)\n",
(nbytes + nbytes_old)/1024,
nbytes + nbytes_old ? (nbytes_old*100)/(nbytes + nbytes_old) : 0,
nused + nused_old, nused+nused_old ? (nused_old*100)/(nused + nused_old) : 0);
jl_safe_printf("%lld kB (%lld%% old) in %lld large objects (%lld%% old)\n",
(long long)((nbytes + nbytes_old) / 1024),
(long long)(nbytes + nbytes_old ? (nbytes_old * 100) / (nbytes + nbytes_old) : 0),
(long long)(nused + nused_old),
(long long)(nused + nused_old ? (nused_old * 100) / (nused + nused_old) : 0));
}
#endif //MEMPROFILE

Expand Down
12 changes: 6 additions & 6 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ void jl_gc_reset_alloc_count(void) JL_NOTSAFEPOINT
reset_thread_gc_counts();
}

static size_t array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT
size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT
{
size_t sz = 0;
int isbitsunion = jl_array_isbitsunion(a);
Expand All @@ -1049,7 +1049,7 @@ static void jl_gc_free_array(jl_array_t *a) JL_NOTSAFEPOINT
jl_free_aligned(d);
else
free(d);
gc_num.freed += array_nbytes(a);
gc_num.freed += jl_array_nbytes(a);
}
}

Expand Down Expand Up @@ -2411,17 +2411,17 @@ mark: {
verify_parent1("array", new_obj, &val_buf, "buffer ('loc' addr is meaningless)");
(void)val_buf;
gc_setmark_buf_(ptls, (char*)a->data - a->offset * a->elsize,
bits, array_nbytes(a));
bits, jl_array_nbytes(a));
}
else if (flags.how == 2) {
if (update_meta || foreign_alloc) {
objprofile_count(jl_malloc_tag, bits == GC_OLD_MARKED,
array_nbytes(a));
jl_array_nbytes(a));
if (bits == GC_OLD_MARKED) {
ptls->gc_cache.perm_scanned_bytes += array_nbytes(a);
ptls->gc_cache.perm_scanned_bytes += jl_array_nbytes(a);
}
else {
ptls->gc_cache.scanned_bytes += array_nbytes(a);
ptls->gc_cache.scanned_bytes += jl_array_nbytes(a);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ void gc_stats_big_obj(void);
// For debugging
void gc_count_pool(void);

size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT;

#ifdef __cplusplus
}
#endif
Expand Down