From a6b12d89bd0bb60bcf0e85d6d10dc5ea641c6b98 Mon Sep 17 00:00:00 2001 From: barter-simsum Date: Tue, 2 Apr 2024 14:35:21 -0400 Subject: [PATCH] pma: _bt_state_meta_new leave second metapage zeroed There's no reason to initialize anything but the first metapage and it's probably less error prone to leave the second metapage zeroed. On sync, the first metapage will get memcpy'd to the second, so why partially write some of the data now? --- rust/ares_pma/c-src/btree.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/rust/ares_pma/c-src/btree.c b/rust/ares_pma/c-src/btree.c index 694d843..605b789 100644 --- a/rust/ares_pma/c-src/btree.c +++ b/rust/ares_pma/c-src/btree.c @@ -2311,7 +2311,7 @@ _bt_state_read_header(BT_state *state) static int _bt_state_meta_new(BT_state *state) { - BT_page *p1, *p2; + BT_page *p1; BT_meta meta = {0}; TRACE(); @@ -2335,14 +2335,11 @@ _bt_state_meta_new(BT_state *state) meta.depth = 1; meta.flags = BP_META; - /* initialize the metapages */ + /* initialize the first metapage */ p1 = &((BT_page *)state->map)[0]; - p2 = &((BT_page *)state->map)[1]; /* copy the metadata into the metapages */ memcpy(METADATA(p1), &meta, sizeof meta); - /* ;;: writing to the second metapage really isn't necessary and it's probably better to leave it zeroed */ - /* memcpy(METADATA(p2), &meta, sizeof meta); */ /* only the active metapage should be writable (first page) */ if (mprotect(BT_MAPADDR, BT_META_SECTION_WIDTH, BT_PROT_CLEAN) != 0) {