Reworked rbyd/btree/mdir structs again so redund blocks are at the end

For a couple reasons:

1. Organizing the overlaps this way avoid potential undefined behavior.
   It turns out C does define the overlap the "initial sequence" of
   union members, as long as the types are the same. But when we
   overlapped the block with the size/tag fields in lfsr_btree_t, it was
   probably undefined behavior.

   At the very least, it would introduce a need for quite a bit of
   preprocessing to make it work with different integer sizes and
   redundancy levels.

2. Overlapping the blocks at the end of the rbyd struct means our block
   array is natural ordered such that the first block is the "active"
   block, i.e. the block with the most recent revision count that passes
   checksums.

   This has been useful as a debugging tool, so I would like to continue
   the pattern. It is possible to mostly preserve this order with the
   previous method by intentional reversing the block array when
   logging or writing to disk, but it's a bit cumbersome.

2. It's unlikely we'll be able to use readonly variants of the rbyd/mdir
   structs for RAM savings. Unfortunately C makes this too cumbersome.
   Though if we do this should be revisited.

Here are the new overlaps. Note it's no longer possible to truncate the
types when readonly. If readonly struct are useful this will need to be
revisited again:

   lfsr_rbyd_t            lfsr_btree_t           lfsr_mdir_t
                                                  8b   8b   8b   8b
                                                .----+----+----+----.
    8b   8b   8b   8b      8b   8b   8b   8b    | mid.bid | mid.rid |
  .----+----+----+----.  .----+----+----+----.  |----+----+----+----|
  |       weight      |.>|       weight      |  |       weight      |
  |----+----+----+----|  |----+----+----+----|  |----+----+----+----|
  |       trunk       |  |   tag   |   size  |  |       trunk       |
  |----+----+----+----|  |----+----+----+----|  |----+----+----+----|
  |        off        |  |    inlined data   |  |        off        |
  |----+----+----+----|  |         |         |  |----+----+----+----|
  |        crc        |  |         v         |  |        crc        |
  |----+----+----+----|  |                   |  |----+----+----+----|
  |       block       |..|                   |.>|       blocks      |
  '----+----+----+----'  '----+----+----+----'  |                   |
                                                |                   |
                                                '----+----+----+----'
This commit is contained in:
Christopher Haster
2023-08-06 01:21:05 -05:00
parent fe941ef443
commit c37bab6040
3 changed files with 32 additions and 34 deletions
+7 -7
View File
@@ -3506,7 +3506,7 @@ code = '''
mid_.bid,
mid_.rid,
tag_,
mdir->u.m.blocks[1], mdir->u.m.blocks[0]);
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
// keep track of seen blocks
seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8);
@@ -3631,7 +3631,7 @@ code = '''
mid_.bid,
mid_.rid,
tag_,
mdir->u.m.blocks[1], mdir->u.m.blocks[0]);
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
// keep track of seen blocks
seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8);
@@ -3767,7 +3767,7 @@ code = '''
mid_.bid,
mid_.rid,
tag_,
mdir->u.m.blocks[1], mdir->u.m.blocks[0]);
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
// keep track of seen blocks
seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8);
@@ -3895,7 +3895,7 @@ code = '''
mid_.bid,
mid_.rid,
tag_,
mdir->u.m.blocks[1], mdir->u.m.blocks[0]);
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
// keep track of seen blocks
seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8);
@@ -4031,7 +4031,7 @@ code = '''
mid_.bid,
mid_.rid,
tag_,
mdir->u.m.blocks[1], mdir->u.m.blocks[0]);
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
// keep track of seen blocks
seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8);
@@ -4194,7 +4194,7 @@ code = '''
mid_.bid,
mid_.rid,
tag_,
mdir->u.m.blocks[1], mdir->u.m.blocks[0]);
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
// keep track of seen blocks
seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8);
@@ -4298,7 +4298,7 @@ code = '''
mid_.bid,
mid_.rid,
tag_,
mdir->u.m.blocks[1], mdir->u.m.blocks[0]);
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
} else {
// this shouldn't happen
printf("traversal: %d.%d 0x%x %d\n",