From e622656538c1f2303c050a298da9558524ea02c3 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 4 Oct 2025 12:49:39 -0500 Subject: [PATCH] bmap: Tweaked bmap ranges, dropped in-flight tag for now New bmap range tags: LFS3_TAG_BMRANGE 0x033u v--- --11 --11 uuuu LFS3_TAG_BMFREE 0x0330 v--- --11 --11 ---- LFS3_TAG_BMINUSE 0x0331 v--- --11 --11 ---1 LFS3_TAG_BMERASED 0x0332 v--- --11 --11 --1- LFS3_TAG_BMBAD 0x0333 v--- --11 --11 --11 Note 0x334-0x33f are still reserved for future bmap tags, but the new encoding fits in the surprisingly common 2-bit subfield that may deduplicate some decoding code. Fitting in 2-bits is the main reason for this, now that in-flight ranges look like they won't be worth exploring further. Worst case we can always add more bm tags in the future. And it may even make sense to use an entire bit for in-flight tags, since in theory the concept can apply to more than just in-use blocks. --- Another benefit of this encoding: In-use vs free is a bit check, and I like the implication that an in-use + erased block can only be a bad block. No code changes: code stack ctx before: 37172 2352 684 after: 37172 (+0.0%) 2352 (+0.0%) 684 (+0.0%) code stack ctx bmap before: 38844 2456 800 bmap after: 38844 (+0.0%) 2456 (+0.0%) 800 (+0.0%) --- lfs3.c | 5 ++--- scripts/dbgbmap.py | 8 +++----- scripts/dbgbmapsvg.py | 8 +++----- scripts/dbgbtree.py | 8 +++----- scripts/dbglfs3.py | 8 +++----- scripts/dbgmtree.py | 8 +++----- scripts/dbgrbyd.py | 8 +++----- scripts/dbgtag.py | 8 +++----- tests/test_bmap.toml | 12 ++++++------ 9 files changed, 29 insertions(+), 44 deletions(-) diff --git a/lfs3.c b/lfs3.c index 0696d8d8..bd5af8b3 100644 --- a/lfs3.c +++ b/lfs3.c @@ -1063,10 +1063,9 @@ enum lfs3_tag { LFS3_TAG_MTREE = 0x032c, LFS3_TAG_BMRANGE = 0x0330, LFS3_TAG_BMFREE = 0x0330, - LFS3_TAG_BMINFLIGHT = 0x0331, - LFS3_TAG_BMINUSE = 0x0332, + LFS3_TAG_BMINUSE = 0x0331, + LFS3_TAG_BMERASED = 0x0332, LFS3_TAG_BMBAD = 0x0333, - LFS3_TAG_BMERASED = 0x0334, // user/sys attributes LFS3_TAG_ATTR = 0x0400, diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index 7eaedc77..e6c3388a 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -61,10 +61,9 @@ TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ---- -TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1 -TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1- +TAG_BMINUSE = 0x0331 # 0x0331 v--- --11 --11 ---1 +TAG_BMERASED = 0x0332 # 0x0332 v--- --11 --11 --1- TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11 -TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1-- TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa @@ -380,10 +379,9 @@ def tagrepr(tag, weight=None, size=None, *, else 'mdir' if (tag & 0xfff) == TAG_MDIR else 'mtree' if (tag & 0xfff) == TAG_MTREE else 'bmfree' if (tag & 0xfff) == TAG_BMFREE - else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE - else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmerased' if (tag & 0xfff) == TAG_BMERASED + else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmrange 0x%x' % (tag & 0xf) if (tag & 0xff0) == TAG_BMRANGE else 'struct 0x%02x' % (tag & 0xff), diff --git a/scripts/dbgbmapsvg.py b/scripts/dbgbmapsvg.py index 2f068f1b..83b9a45e 100755 --- a/scripts/dbgbmapsvg.py +++ b/scripts/dbgbmapsvg.py @@ -59,10 +59,9 @@ TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ---- -TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1 -TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1- +TAG_BMINUSE = 0x0331 # 0x0331 v--- --11 --11 ---1 +TAG_BMERASED = 0x0332 # 0x0332 v--- --11 --11 --1- TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11 -TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1-- TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa @@ -410,10 +409,9 @@ def tagrepr(tag, weight=None, size=None, *, else 'mdir' if (tag & 0xfff) == TAG_MDIR else 'mtree' if (tag & 0xfff) == TAG_MTREE else 'bmfree' if (tag & 0xfff) == TAG_BMFREE - else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE - else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmerased' if (tag & 0xfff) == TAG_BMERASED + else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmrange 0x%x' % (tag & 0xf) if (tag & 0xff0) == TAG_BMRANGE else 'struct 0x%02x' % (tag & 0xff), diff --git a/scripts/dbgbtree.py b/scripts/dbgbtree.py index bd36ef93..3150b610 100755 --- a/scripts/dbgbtree.py +++ b/scripts/dbgbtree.py @@ -50,10 +50,9 @@ TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ---- -TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1 -TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1- +TAG_BMINUSE = 0x0331 # 0x0331 v--- --11 --11 ---1 +TAG_BMERASED = 0x0332 # 0x0332 v--- --11 --11 --1- TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11 -TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1-- TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa @@ -256,10 +255,9 @@ def tagrepr(tag, weight=None, size=None, *, else 'mdir' if (tag & 0xfff) == TAG_MDIR else 'mtree' if (tag & 0xfff) == TAG_MTREE else 'bmfree' if (tag & 0xfff) == TAG_BMFREE - else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE - else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmerased' if (tag & 0xfff) == TAG_BMERASED + else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmrange 0x%x' % (tag & 0xf) if (tag & 0xff0) == TAG_BMRANGE else 'struct 0x%02x' % (tag & 0xff), diff --git a/scripts/dbglfs3.py b/scripts/dbglfs3.py index 055a4609..d702def6 100755 --- a/scripts/dbglfs3.py +++ b/scripts/dbglfs3.py @@ -51,10 +51,9 @@ TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ---- -TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1 -TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1- +TAG_BMINUSE = 0x0331 # 0x0331 v--- --11 --11 ---1 +TAG_BMERASED = 0x0332 # 0x0332 v--- --11 --11 --1- TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11 -TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1-- TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa @@ -305,10 +304,9 @@ def tagrepr(tag, weight=None, size=None, *, else 'mdir' if (tag & 0xfff) == TAG_MDIR else 'mtree' if (tag & 0xfff) == TAG_MTREE else 'bmfree' if (tag & 0xfff) == TAG_BMFREE - else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE - else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmerased' if (tag & 0xfff) == TAG_BMERASED + else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmrange 0x%x' % (tag & 0xf) if (tag & 0xff0) == TAG_BMRANGE else 'struct 0x%02x' % (tag & 0xff), diff --git a/scripts/dbgmtree.py b/scripts/dbgmtree.py index 56f84a69..8bbba8c6 100755 --- a/scripts/dbgmtree.py +++ b/scripts/dbgmtree.py @@ -50,10 +50,9 @@ TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ---- -TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1 -TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1- +TAG_BMINUSE = 0x0331 # 0x0331 v--- --11 --11 ---1 +TAG_BMERASED = 0x0332 # 0x0332 v--- --11 --11 --1- TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11 -TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1-- TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa @@ -271,10 +270,9 @@ def tagrepr(tag, weight=None, size=None, *, else 'mdir' if (tag & 0xfff) == TAG_MDIR else 'mtree' if (tag & 0xfff) == TAG_MTREE else 'bmfree' if (tag & 0xfff) == TAG_BMFREE - else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE - else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmerased' if (tag & 0xfff) == TAG_BMERASED + else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmrange 0x%x' % (tag & 0xf) if (tag & 0xff0) == TAG_BMRANGE else 'struct 0x%02x' % (tag & 0xff), diff --git a/scripts/dbgrbyd.py b/scripts/dbgrbyd.py index 864f8cb6..759292e6 100755 --- a/scripts/dbgrbyd.py +++ b/scripts/dbgrbyd.py @@ -60,10 +60,9 @@ TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ---- -TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1 -TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1- +TAG_BMINUSE = 0x0331 # 0x0331 v--- --11 --11 ---1 +TAG_BMERASED = 0x0332 # 0x0332 v--- --11 --11 --1- TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11 -TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1-- TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa @@ -259,10 +258,9 @@ def tagrepr(tag, weight=None, size=None, *, else 'mdir' if (tag & 0xfff) == TAG_MDIR else 'mtree' if (tag & 0xfff) == TAG_MTREE else 'bmfree' if (tag & 0xfff) == TAG_BMFREE - else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE - else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmerased' if (tag & 0xfff) == TAG_BMERASED + else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmrange 0x%x' % (tag & 0xf) if (tag & 0xff0) == TAG_BMRANGE else 'struct 0x%02x' % (tag & 0xff), diff --git a/scripts/dbgtag.py b/scripts/dbgtag.py index b1588ff0..9b7df928 100755 --- a/scripts/dbgtag.py +++ b/scripts/dbgtag.py @@ -43,10 +43,9 @@ TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ---- -TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1 -TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1- +TAG_BMINUSE = 0x0331 # 0x0331 v--- --11 --11 ---1 +TAG_BMERASED = 0x0332 # 0x0332 v--- --11 --11 --1- TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11 -TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1-- TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa @@ -163,10 +162,9 @@ def tagrepr(tag, weight=None, size=None, *, else 'mdir' if (tag & 0xfff) == TAG_MDIR else 'mtree' if (tag & 0xfff) == TAG_MTREE else 'bmfree' if (tag & 0xfff) == TAG_BMFREE - else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE - else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmerased' if (tag & 0xfff) == TAG_BMERASED + else 'bmbad' if (tag & 0xfff) == TAG_BMBAD else 'bmrange 0x%x' % (tag & 0xf) if (tag & 0xff0) == TAG_BMRANGE else 'struct 0x%02x' % (tag & 0xff), diff --git a/tests/test_bmap.toml b/tests/test_bmap.toml index 96ab895f..e8f3b196 100644 --- a/tests/test_bmap.toml +++ b/tests/test_bmap.toml @@ -83,9 +83,9 @@ code = ''' lfs3_bmap_set(&lfs3, &bmap, 8, LFS3_TAG_BMINUSE) => 0; lfs3_bmap_set(&lfs3, &bmap, 10, LFS3_TAG_BMINUSE) => 0; // replace those blocks as bad, this tests deleting ranges - lfs3_bmap_set(&lfs3, &bmap, 6, LFS3_TAG_BMINFLIGHT) => 0; - lfs3_bmap_set(&lfs3, &bmap, 8, LFS3_TAG_BMINFLIGHT) => 0; - lfs3_bmap_set(&lfs3, &bmap, 10, LFS3_TAG_BMINFLIGHT) => 0; + lfs3_bmap_set(&lfs3, &bmap, 6, LFS3_TAG_BMBAD) => 0; + lfs3_bmap_set(&lfs3, &bmap, 8, LFS3_TAG_BMBAD) => 0; + lfs3_bmap_set(&lfs3, &bmap, 10, LFS3_TAG_BMBAD) => 0; printf("bmap: w%d 0x%x.%x\n", bmap.r.weight, bmap.r.blocks[0], @@ -102,7 +102,7 @@ code = ''' assert(bid_ == 5); assert(weight_ == 6); lfs3_bmap_lookupnext(&lfs3, &bmap, 6, - &bid_, &weight_) => LFS3_TAG_BMINFLIGHT; + &bid_, &weight_) => LFS3_TAG_BMBAD; assert(bid_ == 6); assert(weight_ == 1); lfs3_bmap_lookupnext(&lfs3, &bmap, 7, @@ -110,7 +110,7 @@ code = ''' assert(bid_ == 7); assert(weight_ == 1); lfs3_bmap_lookupnext(&lfs3, &bmap, 8, - &bid_, &weight_) => LFS3_TAG_BMINFLIGHT; + &bid_, &weight_) => LFS3_TAG_BMBAD; assert(bid_ == 8); assert(weight_ == 1); lfs3_bmap_lookupnext(&lfs3, &bmap, 9, @@ -118,7 +118,7 @@ code = ''' assert(bid_ == 9); assert(weight_ == 1); lfs3_bmap_lookupnext(&lfs3, &bmap, 10, - &bid_, &weight_) => LFS3_TAG_BMINFLIGHT; + &bid_, &weight_) => LFS3_TAG_BMBAD; assert(bid_ == 10); assert(weight_ == 1); lfs3_bmap_lookupnext(&lfs3, &bmap, 11,