Skip to content

Commit

Permalink
all migrations work but still have memory leak, apparent during |mass
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Aug 30, 2023
1 parent 1c53ccb commit 2d16543
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
31 changes: 13 additions & 18 deletions pkg/noun/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,12 @@ _ca_reclaim_half(void)
u3m_bail(c3__meme);
}
// XX reclaim from persistent cache?
// fprintf(stderr, "allocate: checking if persistent cache is empty\r\n");
// if ( (0 == u3R->cax.per_p) ||
// (0 == u3to(u3h_root, u3R->cax.per_p)->use_w) )
// {
// fprintf(stderr, "allocate: reclaim: persistent memo cache: empty\r\n");
// u3m_bail(c3__meme);
// }
if ( (0 == u3R->cax.per_p) ||
(0 == u3to(u3h_root, u3R->cax.per_p)->use_w) )
{
fprintf(stderr, "allocate: reclaim: persistent memo cache: empty\r\n");
u3m_bail(c3__meme);
}

#if 1
fprintf(stderr, "allocate: reclaim: half of %d entries\r\n",
Expand All @@ -444,10 +443,10 @@ _ca_reclaim_half(void)
u3h_trim_to(u3R->cax.har_p, u3to(u3h_root, u3R->cax.har_p)->use_w / 2);

// XX reclaim from persistent cache?
// fprintf(stderr, "allocate: reclaim: half of %d persistent entries\r\n",
// u3to(u3h_root, u3R->cax.per_p)->use_w);
fprintf(stderr, "allocate: reclaim: half of %d persistent entries\r\n",
u3to(u3h_root, u3R->cax.per_p)->use_w);

// u3h_trim_to(u3R->cax.per_p, u3to(u3h_root, u3R->cax.per_p)->use_w / 2);
u3h_trim_to(u3R->cax.per_p, u3to(u3h_root, u3R->cax.per_p)->use_w / 2);
#else
/* brutal and guaranteed effective
*/
Expand Down Expand Up @@ -2169,7 +2168,6 @@ u3a_mark_road(FILE* fil_u)
tot_w += u3a_maid(fil_u, " profile doss", u3a_mark_noun(u3R->pro.day));
tot_w += u3a_maid(fil_u, " new profile trace", u3a_mark_noun(u3R->pro.trace));
tot_w += u3a_maid(fil_u, " transient memoization cache", u3h_mark(u3R->cax.har_p));
fprintf(stderr, "u3a_mark_road: persistent cache\r\n");
tot_w += u3a_maid(fil_u, " persistent memoization cache", u3h_mark(u3R->cax.per_p));
return u3a_maid(fil_u, "total road stuff", tot_w);
}
Expand All @@ -2185,9 +2183,8 @@ u3a_reclaim(void)
u3R->cax.har_p = u3h_new();

// XX clear the persistent cache?
// fprintf(stderr, "u3a_reclaim: freeing persistent cache\r\n");
// u3h_free(u3R->cax.per_p);
// u3R->cax.per_p = u3h_new();
u3h_free(u3R->cax.per_p);
u3R->cax.per_p = u3h_new();
}

/* u3a_rewrite_compact(): rewrite pointers in ad-hoc persistent road structures.
Expand All @@ -2203,8 +2200,7 @@ u3a_rewrite_compact(void)
u3a_rewrite_noun(u3R->pro.trace);
u3h_rewrite(u3R->cax.har_p);
// XX rewrite persistent cache?
// fprintf(stderr, "u3a_rewrite_compact: rewrite persistent cache\r\n");
// u3h_rewrite(u3R->cax.per_p);
u3h_rewrite(u3R->cax.per_p);

u3R->ski.gul = u3a_rewritten_noun(u3R->ski.gul);
u3R->bug.tax = u3a_rewritten_noun(u3R->bug.tax);
Expand All @@ -2214,8 +2210,7 @@ u3a_rewrite_compact(void)
u3R->pro.trace = u3a_rewritten_noun(u3R->pro.trace);
u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p);
// XX persistent cache?
// fprintf(stderr, "u3a_rewrite_compact: rewritten persistent cache\r\n");
// u3R->cax.per_p = u3a_rewritten(u3R->cax.per_p);
u3R->cax.per_p = u3a_rewritten(u3R->cax.per_p);
}

/* _ca_print_box(): heuristically print the contents of an allocation box.
Expand Down
13 changes: 8 additions & 5 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// @file

#include "manage.h"
#include "urth.h"

#include <ctype.h>
#include <errno.h>
Expand Down Expand Up @@ -2394,6 +2395,7 @@ _migrate_memoization()
c3_w *mem_w = u3_Loom + u3C.walign_w;
c3_w len_w = u3C.wor_i - u3C.walign_w;
c3_w suz_w = c3_wiseof(u3v_home_v0);
// XX check this later
c3_w *mut_w = c3_align(mem_w + len_w - suz_w, u3C.balign_d, C3_ALGLO);

// old road
Expand All @@ -2402,8 +2404,8 @@ _migrate_memoization()
size_t ruz_t = sizeof(u3a_road_v0);

// new home, new road
u3v_home hom_u;
u3a_road rod_u;
u3v_home hom_u = {0};
u3a_road rod_u = {0};

// copy members, one-by-one, from old road to new road
rod_u.par_p = rud_u->par_p;
Expand All @@ -2423,12 +2425,11 @@ _migrate_memoization()
rod_u.how.fag_w = rud_u->how.fag_w;

// XX destination buffer is size 196; is that because of padding?
memcpy(rod_u.all.fre_p, rud_u->all.fre_p, sizeof(u3_post) * u3a_fbox_no);
memcpy(rod_u.all.fre_p, rud_u->all.fre_p, sizeof(rud_u->all.fre_p));
rod_u.all.cel_p = rud_u->all.cel_p;
rod_u.all.fre_w = rud_u->all.fre_w;
rod_u.all.max_w = rud_u->all.max_w;

rod_u.jed = rud_u->jed;
rod_u.jed.hot_p = rud_u->jed.hot_p;
rod_u.jed.war_p = rud_u->jed.war_p;
rod_u.jed.cod_p = rud_u->jed.cod_p;
Expand All @@ -2453,14 +2454,16 @@ _migrate_memoization()
// carefully place new road over the old one
c3_w siz_w = c3_wiseof(u3v_home);
c3_w *mat_w = c3_align(mem_w + len_w - siz_w, u3C.balign_d, C3_ALGLO);
memcpy(&hum_u->rod_u, &rod_u, sizeof(u3a_road));
memcpy(mat_w, &rod_u, sizeof(u3a_road));

// update version
hum_u->ver_w = U3V_VER3;

u3H = (u3v_home*)hum_u;
u3R = &u3H->rod_u;

u3R->cax.per_p = u3h_new_cache(u3C.per_w);

u3m_pack();
}

Expand Down

0 comments on commit 2d16543

Please sign in to comment.