Skip to content

Commit

Permalink
pma: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
barter-simsum committed Aug 9, 2024
1 parent d246052 commit c46f8cc
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions rust/ares_pma/c-src/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ _bt_nalloc(BT_state *state)

static int
_node_cow(BT_state *state, BT_page *node, pgno_t *pgno)
{ /* ;;: !!! HERE HERE HERE */
{
BT_page *ret = _bt_nalloc(state); /* ;;: todo: assert node has no dirty entries */
memcpy(ret->datk, node->datk, sizeof node->datk[0] * BT_DAT_MAXKEYS);
*pgno = _fo_get(state, ret);
Expand Down Expand Up @@ -693,7 +693,7 @@ _bt_find2(BT_state *state,
}

static void
_bt_root_new(BT_meta *meta, BT_page *root) /* ;;: todo: remove meta param */
_bt_root_new(BT_page *root)
{
/* The first usable address in the PMA is just beyond the btree segment */
root->datk[0].va = B2PAGES(BLK_BASE_LEN_TOTAL);
Expand Down Expand Up @@ -1570,22 +1570,6 @@ _bt_insert2(BT_state *state, vaof_t lo, vaof_t hi, pgno_t fo,
node->datk[childidx].fo = pgno;
_bt_dirtychild(node, childidx);
}
else {
#if 0 /* ;;: ... so where are we failing to mprotect
writable a dirty node? Doesn't really make
sense */
/* ;;: tmp **************************************************************/
BT_page *child = _node_get(state, node->datk[childidx].fo);
if (mprotect(child, sizeof(BT_page), BT_PROT_DIRTY) != 0) {
DPRINTF("mprotect of node: %p failed with %s", child, strerror(errno));
abort();
}
/* - *********************************************************************/
#endif
}
/* ;;: the issue seems to be fundamentally that we've marked a node as dirty
(and therefore not requiring an mprotect(DIRTY)) when it isn't in fact
dirty. The node while marked dirty, remains read-only - hence, SIGSEGV */

/* do we need to split the child node? */
if (N >= BT_DAT_MAXKEYS - 2) {
Expand Down Expand Up @@ -2419,7 +2403,7 @@ _bt_state_meta_inject_root(BT_state *state)
assert(state->nlist);
BT_meta *meta = state->meta_pages[state->which];
BT_page *root = _bt_nalloc(state);
_bt_root_new(meta, root);
_bt_root_new(root);
meta->root = _fo_get(state, root);
assert(meta->root == INITIAL_ROOTPG);
return BT_SUCC;
Expand Down Expand Up @@ -2806,7 +2790,7 @@ _bt_sync(BT_state *state, BT_page *node, uint8_t depth, uint8_t maxdepth)

/* do dfs */
for (size_t i = 0; i < N-1; i++) {
if (!_bt_ischilddirty(node, i)) /* ;;: consider removing case until dirty logic is foolproof */
if (!_bt_ischilddirty(node, i))
continue; /* not dirty. nothing to do */

BT_page *child = _node_get(state, node->datk[i].fo);
Expand All @@ -2818,9 +2802,7 @@ _bt_sync(BT_state *state, BT_page *node, uint8_t depth, uint8_t maxdepth)

e:
/* zero out the dirty bitmap */
/* ZERO(&node->head.dirty[0], sizeof node->head.dirty); */
for (size_t i = 0; i < 256; i++)
node->head.dirty[i] = 0;
ZERO(&node->head.dirty[0], sizeof node->head.dirty);

/* all modifications done in node, mark it read-only */
if (mprotect(node, sizeof(BT_page), BT_PROT_CLEAN) != 0) {
Expand Down

0 comments on commit c46f8cc

Please sign in to comment.