Skip to content

Commit

Permalink
nock: persistent caching improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 15, 2023
1 parent e82d5cd commit 9f3df42
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
/* u3a_is_atom(): yes if noun [som] is direct atom or indirect atom.
*/
# define u3a_is_atom(som) c3o(u3a_is_cat(som), \
u3a_is_pug(som))
u3a_is_pug(som))
# define u3ud(som) u3a_is_atom(som)

/* u3a_is_cell: yes if noun [som] is cell.
Expand Down
5 changes: 2 additions & 3 deletions pkg/noun/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*** corresponding to the 32-slot nodes for everything under
*** the root node.
***
*** We store an extra "freshly warm" bit for a simple
*** clock-algorithm reclamation policy, not yet implemented.
*** Search "clock algorithm" to figure it out.
*** We store an extra "freshly warm" bit and use it for a simple
*** clock-algorithm reclamation policy.
**/
/* u3h_slot: map slot.
**
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ _pave_parts(void)
{
// TODO: pass `u3_Host.ops_u.hap_w` into `noun` library as an argument and use
// as size of memo cache.
u3R->cax.har_p = u3h_new_cache(50000); // transient cache
u3R->cax.per_p = u3h_new_cache(50000); // persistent cache
u3R->cax.har_p = u3h_new_cache(50000); // transient
u3R->cax.per_p = u3h_new_cache(5000); // persistent
u3R->jed.war_p = u3h_new();
u3R->jed.cod_p = u3h_new();
u3R->jed.han_p = u3h_new();
Expand Down
13 changes: 7 additions & 6 deletions pkg/noun/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "vortex.h"
#include "xtract.h"
#include "zave.h"
#include "log.h"

// define to have each opcode printed as it executes,
// along with some other debugging info
Expand Down Expand Up @@ -1127,12 +1128,8 @@ _n_bint(u3_noun* ops, u3_noun hif, u3_noun nef, c3_o los_o, c3_o tel_o)

op_y = (c3y == los_o) ? SLIB : SKIB; // overflows to SLIS / SKIS
u3z_cid cid = u3z_memo_toss;
// skip over spot hints
// XX actually evaluate hod some day
while ( 11 == u3h(hod) && 1 == u3h(u3t(u3h(u3t(hod))))) {
hod = u3t(u3t(hod));
}
if ( (1 == u3h(hod)) && (0 != u3t(hod)) ) {
hod = u3r_skip(hod);
if ( c3y == u3du(hod) ) {
cid = u3z_memo_keep;
}
++tot_w; _n_emit(ops, u3nq(op_y, cid, mem_w, u3k(nef)));
Expand Down Expand Up @@ -2640,6 +2637,10 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off)
: ( 0 == u3R->ski.gul ) ) { // prevents userspace from persistence
u3z_save_m(u3h(o), 144 + c3__nock, u3t(o), x);
}
else if ( ( u3z_memo_keep == u3h(o) ) &&
( 0 != u3R->ski.gul ) ) {
u3l_log("nock: userspace can't save to persistent cache\r\n");
}
*top = x;
u3z(o);
BURN();
Expand Down
34 changes: 34 additions & 0 deletions pkg/noun/retrieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -1903,3 +1903,37 @@ u3r_mug(u3_noun veb)

return mug_l;
}

/* u3r_skip():
**
** Extract a constant from a formula, ignoring
** safe/static hints, doing no computation.
**
*/
u3_weak u3r_skip(u3_noun fol) {
while ( 1 ) {
if ( c3n == u3du(fol) ) {
return u3_none;
}
else switch ( u3h(fol) ) {
default:
return u3_none;
case 1:
return u3k(u3t(fol));
case 11: {
u3_noun arg = u3t(fol),
hod = u3h(arg);

if ( c3y == u3du(hod) ) {
u3_weak dug = u3r_skip(u3t(hod));
if ( u3_none == dug ) {
return u3_none;
}
u3z(dug);
}
fol = u3t(arg);
continue;
}
}
}
}
7 changes: 7 additions & 0 deletions pkg/noun/retrieve.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,11 @@
c3_y*
u3r_tape(u3_noun a);

/* u3r_skip():
**
** Extract a constant from a formula, ignoring
** safe/static hints, doing no computation.
*/
u3_weak u3r_skip(u3_noun fol);

#endif /* ifndef U3_RETRIEVE_H */
8 changes: 5 additions & 3 deletions pkg/noun/zave.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "allocate.h"
#include "hashtable.h"
#include "imprison.h"
#include "vortex.h"

/* u3z_key(): construct a memo cache-key. Arguments retained.
*/
Expand Down Expand Up @@ -57,16 +58,17 @@ u3z_find(u3z_cid cid, u3_noun key)
return u3h_get(_har(u3R, cid), key);
}
else {
u3a_road* rod_u = u3R;
// XX needs to be benchmarked (up vs. down search)
u3a_road* rod_u = &(u3H->rod_u);
while ( 1 ) {
u3_weak got = u3h_get(_har(rod_u, cid), key);
if ( u3_none != got ) {
return got;
}
if ( 0 == rod_u->par_p ) {
if ( 0 == rod_u->kid_p ) {
return u3_none;
}
rod_u = u3to(u3a_road, rod_u->par_p);
rod_u = u3to(u3a_road, rod_u->kid_p);
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/vere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ genrule(
if check && sleep 10 && check; then
echo "boot success"
lensa hood "+hood/exit"
lensa hood '+hood/exit'
while [ -f ./pier/.vere.lock ]; do
echo "waiting for pier to shut down"
sleep 5
Expand Down

0 comments on commit 9f3df42

Please sign in to comment.