From e7b0a6a5e70ce463d1d13cbcc34c0f895b3d702a Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 17 Oct 2019 14:19:21 -0700 Subject: [PATCH 1/4] u3: print the size of the free lists on |mass --- pkg/urbit/worker/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index 7d3f3474d..5b9754bb0 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -306,6 +306,7 @@ _worker_grab(u3_noun sac, u3_noun ovo, u3_noun vir) tot_w += u3a_maid(fil_u, "effects", u3a_mark_noun(vir)); u3a_print_memory(fil_u, "total marked", tot_w); + u3a_print_memory(fil_u, "free lists", u3a_idle(u3R)); u3a_print_memory(fil_u, "sweep", u3a_sweep()); fflush(fil_u); From bf5a1276afab0c96db662030974138c227e55cb6 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 17 Oct 2019 15:50:04 -0700 Subject: [PATCH 2/4] u3: restore memory reclamation every 1k events --- pkg/urbit/worker/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index 5b9754bb0..67f8f4a2a 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -606,6 +606,15 @@ _worker_work_live(c3_d evt_d, u3_noun job) rec_o = c3y; pri = 0; } + // reclaim memory from persistent caches periodically + // + // XX this is a hack to work two things + // - bytecode caches grow rapidly and can't be simply capped + // - we don't make very effective use of our free lists + // + else { + rec_o = _(0 == (evt_d % 1000ULL)); + } // notify daemon of memory pressure via "fake" effect // From 1cfedf227331d4df9aaec5cfdc27f50f1195e6f1 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 17 Oct 2019 15:50:28 -0700 Subject: [PATCH 3/4] u3: statically measure memory on startup if < 1/2 the loom is free --- pkg/urbit/worker/main.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index 67f8f4a2a..28211c24c 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -898,6 +898,21 @@ _worker_poke(void* vod_p, u3_noun mat) } } +/* _worker_static_grab(): garbage collect, checking for profiling. RETAIN. +*/ +static void +_worker_static_grab(void) +{ + c3_assert( u3R == &(u3H->rod_u) ); + + fprintf(stderr, "work: measuring memory:\r\n"); + u3a_print_memory(stderr, "total marked", u3m_mark(stderr)); + u3a_print_memory(stderr, "free lists", u3a_idle(u3R)); + u3a_print_memory(stderr, "sweep", u3a_sweep()); + fprintf(stderr, "\r\n"); + fflush(stderr); +} + /* u3_worker_boot(): send startup message to manager. */ void @@ -927,6 +942,18 @@ u3_worker_boot(void) u3l_log("work: play %" PRIu64 "\r\n", nex_d); _worker_send(u3nc(c3__play, dat)); + + // measure/print static memory usage if < 1/2 of the loom is available + // + { + c3_w pen_w = u3a_open(u3R); + + if ( !(pen_w > (1 << 28)) ) { + fprintf(stderr, "\r\n"); + u3a_print_memory(stderr, "work: contiguous free space", pen_w); + _worker_static_grab(); + } + } } /* main(): main() when run as urbit-worker From 85a656471f64eff1faebbdc0ac54be590dce7942 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 17 Oct 2019 15:57:19 -0700 Subject: [PATCH 4/4] u3: removes "worker_send_replace" printf --- pkg/urbit/worker/main.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index 28211c24c..b63c6c87d 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -341,10 +341,6 @@ _worker_send(u3_noun job) static void _worker_send_replace(c3_d evt_d, u3_noun job) { - u3l_log("worker_send_replace %" PRIu64 " %s\r\n", - evt_d, - u3r_string(u3h(u3t(u3t(job))))); - _worker_send(u3nt(c3__work, u3i_chubs(1, &evt_d), u3ke_jam(u3nc(u3V.mug_l, job))));