From f2436a6867b1b2fa60eefeb7a586f8ecd1a6e17e Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 11 Oct 2023 10:07:45 -0400 Subject: [PATCH 1/5] u3: revises free-list bounds --- pkg/noun/allocate.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pkg/noun/allocate.c b/pkg/noun/allocate.c index ace4473a4a..8cf2daaff9 100644 --- a/pkg/noun/allocate.c +++ b/pkg/noun/allocate.c @@ -76,27 +76,28 @@ _box_count(c3_ws siz_ws) { } } while(0) /* _box_slot(): select the right free list to search for a block. - TODO: do we really need a loop to do this? - - so our free list logic looks like this: - siz_w < 6 words then [0] - siz_w < 16 then [1] - siz_w < 32 then [2] - siz_w < 64 then [3] - ... - siz_w > 4G then [26] +** +** siz_w == 6 words then [0] +** siz_w < 16 then [1] +** siz_w < 32 then [2] +** siz_w < 64 then [3] +** ... +** siz_w >= 2GB then [26] */ static c3_w _box_slot(c3_w siz_w) { - if ( siz_w < u3a_minimum ) { - return 0; - } + if ( u3a_minimum == siz_w ) return 0; + + c3_dessert( u3a_minimum <= siz_w ); - for (c3_w i_w = 1; i_w < u3a_fbox_no; i_w++) { - if ( siz_w < 16 ) return i_w; - siz_w = (siz_w + 1) >> 1; + { + c3_w bit_w = c3_bits_word(siz_w); + + if ( 5 > bit_w ) return 1; + if ( (u3a_fbox_no + 1) >= bit_w ) return bit_w - 3; } + return u3a_fbox_no - 1; } From a1d23cee125b8408cb692786b0a10ceb610389d3 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 11 Oct 2023 10:08:54 -0400 Subject: [PATCH 2/5] u3: adds free-list migration to account for new bounds --- pkg/noun/allocate.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ pkg/noun/allocate.h | 5 ++++ pkg/noun/manage.c | 4 +++ 3 files changed, 72 insertions(+) diff --git a/pkg/noun/allocate.c b/pkg/noun/allocate.c index 8cf2daaff9..a23c1231a2 100644 --- a/pkg/noun/allocate.c +++ b/pkg/noun/allocate.c @@ -2318,6 +2318,69 @@ u3a_idle(u3a_road* rod_u) return fre_w; } +/* u3a_ream(): ream free-lists. +*/ +void +u3a_ream(void) +{ + u3p(u3a_fbox) lit_p; + u3a_fbox* fox_u; + c3_w sel_w, i_w; + + for ( i_w = 0; i_w < u3a_fbox_no; i_w++ ) { + lit_p = u3R->all.fre_p[i_w]; + + while ( lit_p ) { + fox_u = u3to(u3a_fbox, lit_p); + lit_p = fox_u->nex_p; + sel_w = _box_slot(fox_u->box_u.siz_w); + + if ( sel_w != i_w ) { + // inlined _box_detach() + // + { + u3p(u3a_fbox) fre_p = u3of(u3a_fbox, &(fox_u->box_u)); + u3p(u3a_fbox) pre_p = u3to(u3a_fbox, fre_p)->pre_p; + u3p(u3a_fbox) nex_p = u3to(u3a_fbox, fre_p)->nex_p; + + if ( nex_p ) { + if ( u3to(u3a_fbox, nex_p)->pre_p != fre_p ) { + u3_assert(!"loom: corrupt"); + } + u3to(u3a_fbox, nex_p)->pre_p = pre_p; + } + if ( pre_p ) { + if( u3to(u3a_fbox, pre_p)->nex_p != fre_p ) { + u3_assert(!"loom: corrupt"); + } + u3to(u3a_fbox, pre_p)->nex_p = nex_p; + } + else { + if ( fre_p != u3R->all.fre_p[i_w] ) { + u3_assert(!"loom: corrupt"); + } + u3R->all.fre_p[i_w] = nex_p; + } + } + + // inlined _box_attach() + { + u3p(u3a_fbox) fre_p = u3of(u3a_fbox, &(fox_u->box_u)); + u3p(u3a_fbox)* pfr_p = &u3R->all.fre_p[sel_w]; + u3p(u3a_fbox) nex_p = *pfr_p; + + u3to(u3a_fbox, fre_p)->pre_p = 0; + u3to(u3a_fbox, fre_p)->nex_p = nex_p; + if ( nex_p ) { + u3to(u3a_fbox, nex_p)->pre_p = fre_p; + } + (*pfr_p) = fre_p; + } + } + } + } +} + /* u3a_sweep(): sweep a fully marked road. */ c3_w diff --git a/pkg/noun/allocate.h b/pkg/noun/allocate.h index 7355954abd..c6fab95102 100644 --- a/pkg/noun/allocate.h +++ b/pkg/noun/allocate.h @@ -683,6 +683,11 @@ c3_w u3a_idle(u3a_road* rod_u); + /* u3a_ream(): ream free-lists. + */ + void + u3a_ream(void); + /* u3a_sweep(): sweep a fully marked road. */ c3_w diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 5ff7d7b129..29833d001c 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -639,6 +639,10 @@ _find_home(void) } } + // XX move me + // + u3a_ream(); + /* As a further guard against any sneaky loom corruption */ u3a_loom_sane(); From 3553e43531eba85f7f8617152534000562dd7177 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 11 Oct 2023 10:31:41 -0400 Subject: [PATCH 3/5] u3: use u3a_celloc() in u3a_take() --- pkg/noun/allocate.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/noun/allocate.c b/pkg/noun/allocate.c index a23c1231a2..90f1b624fc 100644 --- a/pkg/noun/allocate.c +++ b/pkg/noun/allocate.c @@ -1123,9 +1123,7 @@ _ca_take_atom(u3a_atom* old_u) static inline u3_cell _ca_take_cell(u3a_cell* old_u, u3_noun hed, u3_noun tel) { - // XX use u3a_celloc? - // - c3_w* new_w = u3a_walloc(c3_wiseof(u3a_cell)); + c3_w* new_w = u3a_celloc(); u3a_cell* new_u = (u3a_cell*)(void *)new_w; u3_cell new = u3a_to_pom(u3a_outa(new_u)); From 2dc7d181de8b41d5989a5dbf424980645341904d Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 12 Oct 2023 21:50:58 -0400 Subject: [PATCH 4/5] u3: refactors _box_slot() --- pkg/noun/allocate.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/noun/allocate.c b/pkg/noun/allocate.c index 90f1b624fc..ae022592c2 100644 --- a/pkg/noun/allocate.c +++ b/pkg/noun/allocate.c @@ -87,18 +87,18 @@ _box_count(c3_ws siz_ws) { } static c3_w _box_slot(c3_w siz_w) { - if ( u3a_minimum == siz_w ) return 0; - - c3_dessert( u3a_minimum <= siz_w ); - - { - c3_w bit_w = c3_bits_word(siz_w); - - if ( 5 > bit_w ) return 1; - if ( (u3a_fbox_no + 1) >= bit_w ) return bit_w - 3; + if ( u3a_minimum == siz_w ) { + return 0; + } + else if ( !(siz_w >> 4) ) { + c3_dessert( u3a_minimum < siz_w ); + return 1; + } + else { + c3_w bit_w = c3_bits_word(siz_w) - 3; + c3_w max_w = u3a_fbox_no - 1; + return c3_min(bit_w, max_w); } - - return u3a_fbox_no - 1; } /* _box_make(): construct a box. From efe106650e8da7504b3aa3188875e9c7e06b2826 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 9 Nov 2023 15:42:34 -0500 Subject: [PATCH 5/5] u3: moves u3a_ream (free-list adjustment) into v3 migration --- pkg/noun/manage.c | 4 ---- pkg/noun/v3/allocate.h | 1 + pkg/noun/v3/manage.c | 3 +++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index fde676b463..2de555d58c 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -652,10 +652,6 @@ _find_home(void) } } - // XX move me - // - u3a_ream(); - /* As a further guard against any sneaky loom corruption */ u3a_loom_sane(); diff --git a/pkg/noun/v3/allocate.h b/pkg/noun/v3/allocate.h index bacc79e174..83db4a51b9 100644 --- a/pkg/noun/v3/allocate.h +++ b/pkg/noun/v3/allocate.h @@ -11,6 +11,7 @@ # define u3R_v3 u3a_Road # define u3a_v3_balign u3a_balign # define u3a_v3_road u3a_road +# define u3a_v3_ream u3a_ream # define u3a_v3_walign u3a_walign # define u3a_v3_walloc u3a_walloc diff --git a/pkg/noun/v3/manage.c b/pkg/noun/v3/manage.c index a15d5ad9be..9eb8a96cdb 100644 --- a/pkg/noun/v3/manage.c +++ b/pkg/noun/v3/manage.c @@ -100,6 +100,9 @@ u3m_v3_migrate() u3R_v3 = &u3H_v3->rod_u; u3H_v3->ver_w = U3V_VER3; + // recalculate free lists + u3a_v3_ream(); + // initialize persistent cache u3R_v3->cax.per_p = u3h_v3_new_cache(u3C.per_w);