Skip to content

Commit aea032a

Browse files
committed
Reduced the scope of LFS3_REVDBG/REVNOISE
LFS3_REVDBG introduced a lot of overhead for something I'm not sure anyone will actually use (I have enough tooling that the state of an rbyd is rarely a mystery, see dbgbmap.py). That, and we're running out of flags! So this reduces LFS3_REVDBG to just store one of "himb" in the first (lowest) byte of the revision count; information that is easily available: vvvv---- -------- -------- -------- vvvvrrrr rrrrrr-- -------- -------- vvvvrrrr rrrrrrnn nnnnnnnn nnnnnnnn vvvvrrrr rrrrrrnn nnnnnnnn dddddddd '-.''----.----''----.- - - '---.--' '------|----------|----------|---- 4-bit relocation revision '----------|----------|---- recycle-bits recycle counter '----------|---- pseudorandom noise (if revnoise) '---- h, i, m, or b (if revdbg) -11-1--- - h = mroot anchor -11-1--1 - i = mroot -11-11-1 - m = mdir -11---1- - b = btree node Some other notes: - Enabled LFS3_REVDBG and LFS3_REVNOISE to work together, now that LFS3_REVDBG doesn't consume all unused rev bits. Note that LFS3_REVDBG has priority over LFS3_REVNOISE, but _not_ recycle-bits, etc. Otherwise problems would happen for recycle-bits >2^20 (though do we care?). - Fixed an issue where using the gcksum as a noise source results in noise=0 when there is only an mroot. This is due to how we xor out the current mdir cksum during an mdir commit. Fixed by using gcksum_p instead of gcksum. - Added missing LFS3_I_REVDBG/REVNOISE flags in the tests, so now you can actually run the tests with LFS3_REVDBG/REVNOISE (this probably just fell out-of-date at some point). --- Curiously, despite LFS3_REVDBG/REVNOISE being disabled by default, this did save some code. I'm guessing the non-tail-call mtree/gbmap commit functions prevented some level of inlining?: code stack ctx before: 35964 2280 660 after: 35964 (+0.0%) 2280 (+0.0%) 660 (+0.0%) code stack ctx gbmap before: 38940 2296 772 gbmap after: 38828 (-0.3%) 2296 (+0.0%) 772 (+0.0%)
1 parent e196be5 commit aea032a

File tree

6 files changed

+353
-225
lines changed

6 files changed

+353
-225
lines changed

lfs3.c

Lines changed: 72 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -7526,19 +7526,6 @@ static inline bool lfs3_f_isgbmap(uint32_t flags) {
75267526
}
75277527
#endif
75287528

7529-
// other internal flags
7530-
#ifdef LFS3_REVDBG
7531-
static inline bool lfs3_i_isinmtree(uint32_t flags) {
7532-
return (flags & LFS3_i_INMODE) == LFS3_i_INMTREE;
7533-
}
7534-
#endif
7535-
7536-
#ifdef LFS3_REVDBG
7537-
static inline bool lfs3_i_isingbmap(uint32_t flags) {
7538-
return (flags & LFS3_i_INMODE) == LFS3_i_INGBMAP;
7539-
}
7540-
#endif
7541-
75427529

75437530

75447531
/// Handles - opened mdir things ///
@@ -7946,24 +7933,21 @@ static int lfs3_fs_consumegdelta(lfs3_t *lfs3, const lfs3_mdir_t *mdir) {
79467933

79477934
/// Revision count things ///
79487935

7949-
// in mdirs, our revision count is broken down into three parts:
7936+
// in mdirs, our revision count is broken down into 1-4 parts:
79507937
//
7938+
// vvvv---- -------- -------- --------
7939+
// vvvvrrrr rrrrrr-- -------- --------
79517940
// vvvvrrrr rrrrrrnn nnnnnnnn nnnnnnnn
7952-
// '-.''----.----''---------.--------'
7953-
// '------|---------------|---------- 4-bit relocation revision
7954-
// '---------------|---------- recycle-bits recycle counter
7955-
// '---------- pseudorandom noise (if revnoise)
7956-
//
7957-
// in revdbg mode, the bottom 24 bits are initialized with a hint based
7958-
// on rbyd type, though it may be overwritten by the recycle counter if
7959-
// it overlaps:
7960-
//
7961-
// vvvv---- --1----1 -11-1--1 -11-1--- (68 69 21 v0 hi!r) mroot anchor
7962-
// vvvv---- -111111- -111--1- -11-11-1 (6d 72 7e v0 mr~r) mroot
7963-
// vvvv---- -111111- -11--1-- -11-11-1 (6d 64 7e v0 md~r) mdir
7964-
// vvvv---- -111111- -111-1-- -11---1- (62 74 7e v0 bt~r) file btree node
7965-
// vvvv---- -111111- -11-11-1 -11---1- (62 6d 7e v0 bm~r) mtree node
7966-
// vvvv---- -111111- -11---1- -11---1- (62 62 7e v0 bb~r) gbmap node
7941+
// vvvvrrrr rrrrrrnn nnnnnnnn dddddddd
7942+
// '-.''----.----''----.- - - '---.--'
7943+
// '------|----------|----------|---- 4-bit relocation revision
7944+
// '----------|----------|---- recycle-bits recycle counter
7945+
// '----------|---- pseudorandom noise (if revnoise)
7946+
// '---- h, i, m, or b (if revdbg)
7947+
// -11-1--- - h = mroot anchor
7948+
// -11-1--1 - i = mroot
7949+
// -11-11-1 - m = mdir
7950+
// -11---1- - b = btree node
79677951
//
79687952

79697953
// needed in lfs3_rev_init
@@ -7979,24 +7963,32 @@ static inline uint32_t lfs3_rev_init(lfs3_t *lfs3, const lfs3_mdir_t *mdir,
79797963
rev &= ~((1 << 28)-1);
79807964
// increment revision
79817965
rev += 1 << 28;
7966+
// xor in pseudorandom noise?
7967+
#ifdef LFS3_REVNOISE
7968+
if (lfs3_m_isrevnoise(lfs3->flags)) {
7969+
rev ^= ((1 << (28-lfs3_smax(lfs3->recycle_bits, 0)))-1)
7970+
// we need to use gcksum_p because we have be in the
7971+
// middle of updating the gcksum
7972+
& lfs3->gcksum_p;
7973+
}
7974+
#endif
79827975
// include debug bits?
79837976
#ifdef LFS3_REVDBG
79847977
if (lfs3_m_isrevdbg(lfs3->flags)) {
7978+
uint32_t mask = (1 << (28-lfs3_smax(lfs3->recycle_bits, 0)))-1;
7979+
// mroot anchor?
7980+
if (lfs3_mdir_ismrootanchor(mdir)) {
7981+
rev = (rev & ~(mask & 0xff)) | (mask & 0x68);
79857982
// mroot?
7986-
if (mdir->mid <= -1 || lfs3_mdir_cmp(mdir, &lfs3->mroot) == 0) {
7987-
rev |= 0x007e726d; // mr~r
7983+
} else if (mdir->mid <= -1
7984+
|| lfs3_mdir_cmp(mdir, &lfs3->mroot) == 0) {
7985+
rev = (rev & ~(mask & 0xff)) | (mask & 0x69);
79887986
// mdir?
79897987
} else {
7990-
rev |= 0x007e646d; // md~r
7988+
rev = (rev & ~(mask & 0xff)) | (mask & 0x6d);
79917989
}
79927990
}
79937991
#endif
7994-
// xor in pseudorandom noise
7995-
#ifdef LFS3_REVNOISE
7996-
if (lfs3_m_isrevnoise(lfs3->flags)) {
7997-
rev ^= ((1 << (28-lfs3_smax(lfs3->recycle_bits, 0)))-1) & lfs3->gcksum;
7998-
}
7999-
#endif
80007992
return rev;
80017993
}
80027994
#endif
@@ -8007,26 +7999,20 @@ static inline uint32_t lfs3_rev_init(lfs3_t *lfs3, const lfs3_mdir_t *mdir,
80077999
static inline uint32_t lfs3_rev_btree(lfs3_t *lfs3) {
80088000
(void)lfs3;
80098001
uint32_t rev = 0;
8010-
// include debug bits?
8011-
#ifdef LFS3_REVDBG
8012-
if (lfs3_m_isrevdbg(lfs3->flags)) {
8013-
// mtree?
8014-
if (lfs3_i_isinmtree(lfs3->flags)) {
8015-
rev |= 0x007e6d62; // bm~r
8016-
// gbmap?
8017-
} else if (lfs3_i_isingbmap(lfs3->flags)) {
8018-
rev |= 0x007e6262; // bb~r
8019-
// file btree?
8020-
} else {
8021-
rev |= 0x007e7462; // bt~r
8022-
}
8023-
}
8024-
#endif
8025-
// xor in pseudorandom noise
8002+
// xor in pseudorandom noise?
80268003
#ifdef LFS3_REVNOISE
80278004
if (lfs3_m_isrevnoise(lfs3->flags)) {
80288005
// keep the top nibble zero
8029-
rev ^= 0x0fffffff & lfs3->gcksum;
8006+
rev ^= 0x0fffffff
8007+
// we need to use gcksum_p because we have be in the
8008+
// middle of updating the gcksum
8009+
& lfs3->gcksum_p;
8010+
}
8011+
#endif
8012+
// include debug bits?
8013+
#ifdef LFS3_REVDBG
8014+
if (lfs3_m_isrevdbg(lfs3->flags)) {
8015+
rev = (rev & ~0xff) | 0x62;
80308016
}
80318017
#endif
80328018
return rev;
@@ -8046,13 +8032,35 @@ static inline bool lfs3_rev_needsrelocation(lfs3_t *lfs3, uint32_t rev) {
80468032
#endif
80478033

80488034
#ifndef LFS3_RDONLY
8049-
static inline uint32_t lfs3_rev_inc(lfs3_t *lfs3, uint32_t rev) {
8035+
static inline uint32_t lfs3_rev_inc(lfs3_t *lfs3, const lfs3_mdir_t *mdir,
8036+
uint32_t rev) {
8037+
(void)mdir;
80508038
// increment recycle counter/revision
80518039
rev += 1 << (28-lfs3_smax(lfs3->recycle_bits, 0));
8052-
// xor in pseudorandom noise
8040+
// xor in pseudorandom noise?
80538041
#ifdef LFS3_REVNOISE
80548042
if (lfs3_m_isrevnoise(lfs3->flags)) {
8055-
rev ^= ((1 << (28-lfs3_smax(lfs3->recycle_bits, 0)))-1) & lfs3->gcksum;
8043+
rev ^= ((1 << (28-lfs3_smax(lfs3->recycle_bits, 0)))-1)
8044+
// we need to use gcksum_p because we have be in the
8045+
// middle of updating the gcksum
8046+
& lfs3->gcksum_p;
8047+
}
8048+
#endif
8049+
// include debug bits?
8050+
#ifdef LFS3_REVDBG
8051+
if (lfs3_m_isrevdbg(lfs3->flags)) {
8052+
uint32_t mask = (1 << (28-lfs3_smax(lfs3->recycle_bits, 0)))-1;
8053+
// mroot anchor?
8054+
if (lfs3_mdir_ismrootanchor(mdir)) {
8055+
rev = (rev & ~(mask & 0xff)) | (mask & 0x68);
8056+
// mroot?
8057+
} else if (mdir->mid <= -1
8058+
|| lfs3_mdir_cmp(mdir, &lfs3->mroot) == 0) {
8059+
rev = (rev & ~(mask & 0xff)) | (mask & 0x69);
8060+
// mdir?
8061+
} else {
8062+
rev = (rev & ~(mask & 0xff)) | (mask & 0x6d);
8063+
}
80568064
}
80578065
#endif
80588066
return rev;
@@ -8293,30 +8301,10 @@ static int lfs3_mtree_lookup(lfs3_t *lfs3, lfs3_smid_t mid,
82938301
}
82948302
}
82958303

8296-
// this is the same as lfs3_btree_commit, but we set the inmtree flag
8297-
// for debugging reasons
82988304
#ifndef LFS3_RDONLY
82998305
static int lfs3_mtree_commit(lfs3_t *lfs3, lfs3_btree_t *mtree,
83008306
lfs3_bid_t bid, const lfs3_rattr_t *rattrs, lfs3_size_t rattr_count) {
8301-
#ifdef LFS3_REVDBG
8302-
lfs3->flags |= LFS3_i_INMTREE;
8303-
#endif
8304-
8305-
int err = lfs3_btree_commit(lfs3, mtree, bid, rattrs, rattr_count);
8306-
if (err) {
8307-
goto failed;
8308-
}
8309-
8310-
#ifdef LFS3_REVDBG
8311-
lfs3->flags &= ~LFS3_i_INMTREE;
8312-
#endif
8313-
return 0;
8314-
8315-
failed:;
8316-
#ifdef LFS3_REVDBG
8317-
lfs3->flags &= ~LFS3_i_INMTREE;
8318-
#endif
8319-
return err;
8307+
return lfs3_btree_commit(lfs3, mtree, bid, rattrs, rattr_count);
83208308
}
83218309
#endif
83228310

@@ -8409,7 +8397,7 @@ static int lfs3_mdir_swap___(lfs3_t *lfs3, lfs3_mdir_t *mdir_,
84098397
// note we allow corrupt errors here, as long as they are consistent
84108398
rev = (err != LFS3_ERR_CORRUPT) ? lfs3_fromle32(&rev) : 0;
84118399
// increment our revision count
8412-
rev = lfs3_rev_inc(lfs3, rev);
8400+
rev = lfs3_rev_inc(lfs3, mdir_, rev);
84138401

84148402
// decide if we need to relocate
84158403
if (!force && lfs3_rev_needsrelocation(lfs3, rev)) {
@@ -10713,30 +10701,10 @@ static lfs3_stag_t lfs3_gbmap_lookupnext(lfs3_t *lfs3, lfs3_btree_t *gbmap,
1071310701
}
1071410702
#endif
1071510703

10716-
// this is the same as lfs3_btree_commit, but we set the ingbmap flag
10717-
// for debugging reasons
1071810704
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
1071910705
static int lfs3_gbmap_commit(lfs3_t *lfs3, lfs3_btree_t *gbmap,
1072010706
lfs3_bid_t bid, const lfs3_rattr_t *rattrs, lfs3_size_t rattr_count) {
10721-
#ifdef LFS3_REVDBG
10722-
lfs3->flags |= LFS3_i_INGBMAP;
10723-
#endif
10724-
10725-
int err = lfs3_btree_commit(lfs3, gbmap, bid, rattrs, rattr_count);
10726-
if (err) {
10727-
goto failed;
10728-
}
10729-
10730-
#ifdef LFS3_REVDBG
10731-
lfs3->flags &= ~LFS3_i_INGBMAP;
10732-
#endif
10733-
return 0;
10734-
10735-
failed:;
10736-
#ifdef LFS3_REVDBG
10737-
lfs3->flags &= ~LFS3_i_INGBMAP;
10738-
#endif
10739-
return err;
10707+
return lfs3_btree_commit(lfs3, gbmap, bid, rattrs, rattr_count);
1074010708
}
1074110709
#endif
1074210710

@@ -14968,11 +14936,6 @@ static int lfs3_init(lfs3_t *lfs3, uint32_t flags,
1496814936
| LFS3_IFDEF_CKMETAPARITY(LFS3_M_CKMETAPARITY, 0)
1496914937
| LFS3_IFDEF_CKDATACKSUMS(LFS3_M_CKDATACKSUMS, 0)
1497014938
| LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, 0))) == 0);
14971-
// LFS3_M_REVDBG and LFS3_M_REVNOISE are incompatible
14972-
#if defined(LFS3_REVNOISE) && defined(LFS3_REVDBG)
14973-
LFS3_ASSERT(!lfs3_m_isrevdbg(flags) || !lfs3_m_isrevnoise(flags));
14974-
#endif
14975-
1497614939
// TODO this all needs to be cleaned up
1497714940
lfs3->cfg = cfg;
1497814941
int err = 0;
@@ -16032,10 +15995,6 @@ int lfs3_unmount(lfs3_t *lfs3) {
1603215995

1603315996
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
1603415997
static int lfs3_formatgbmap(lfs3_t *lfs3) {
16035-
#ifdef LFS3_REVDBG
16036-
lfs3->flags |= LFS3_i_INGBMAP;
16037-
#endif
16038-
1603915998
// TODO should we try multiple blocks?
1604015999
//
1604116000
// TODO if we try multiple blocks we should update test_badblocks
@@ -16052,14 +16011,14 @@ static int lfs3_formatgbmap(lfs3_t *lfs3) {
1605216011

1605316012
int err = lfs3_bd_erase(lfs3, lfs3->gbmap.b.r.blocks[0]);
1605416013
if (err) {
16055-
goto failed;
16014+
return err;
1605616015
}
1605716016

1605816017
#if defined(LFS3_REVDBG) || defined(LFS3_REVNOISE)
1605916018
// append a revision count?
1606016019
err = lfs3_rbyd_appendrev(lfs3, &lfs3->gbmap.b.r, lfs3_rev_btree(lfs3));
1606116020
if (err) {
16062-
goto failed;
16021+
return err;
1606316022
}
1606416023
#endif
1606516024

@@ -16071,19 +16030,10 @@ static int lfs3_formatgbmap(lfs3_t *lfs3) {
1607116030
? LFS3_RATTR(LFS3_TAG_BMFREE, +(lfs3->block_count - 3))
1607216031
: LFS3_RATTR_NOOP()));
1607316032
if (err) {
16074-
goto failed;
16033+
return err;
1607516034
}
1607616035

16077-
#ifdef LFS3_REVDBG
16078-
lfs3->flags &= ~LFS3_i_INGBMAP;
16079-
#endif
1608016036
return 0;
16081-
16082-
failed:;
16083-
#ifdef LFS3_REVDBG
16084-
lfs3->flags &= ~LFS3_i_INGBMAP;
16085-
#endif
16086-
return err;
1608716037
}
1608816038
#endif
1608916039

lfs3.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,6 @@ enum lfs3_type {
296296
#define LFS3_I_GBMAP 0x01000000 // Global on-disk block-map in use
297297
#endif
298298

299-
// internally used flags, don't use these
300-
#ifdef LFS3_REVDBG
301-
#define LFS3_i_INMODE 0x00030000 // Btree commit mode
302-
#define LFS3_i_INMTREE 0x00010000 // Committing to mtree
303-
#define LFS3_i_INGBMAP 0x00020000 // Committing to gbmap
304-
#endif
305-
306299

307300
// Block types
308301
enum lfs3_btype {

lfs3_util.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,24 @@
215215
#define LFS3_IFDEF_REVDBG(a, b) (b)
216216
#endif
217217

218+
#ifdef LFS3_YES_REVDBG
219+
#define LFS3_IFDEF_YES_REVDBG(a, b) (a)
220+
#else
221+
#define LFS3_IFDEF_YES_REVDBG(a, b) (b)
222+
#endif
223+
218224
#ifdef LFS3_REVNOISE
219225
#define LFS3_IFDEF_REVNOISE(a, b) (a)
220226
#else
221227
#define LFS3_IFDEF_REVNOISE(a, b) (b)
222228
#endif
223229

230+
#ifdef LFS3_YES_REVNOISE
231+
#define LFS3_IFDEF_YES_REVNOISE(a, b) (a)
232+
#else
233+
#define LFS3_IFDEF_YES_REVNOISE(a, b) (b)
234+
#endif
235+
224236
#ifdef LFS3_CKPROGS
225237
#define LFS3_IFDEF_CKPROGS(a, b) (a)
226238
#else

0 commit comments

Comments
 (0)