gbmap: Added LFS3_T_REBUILDGBMAP and friends
This adds LFS3_T_REBUILDGBMAP and friends, and enables incremental gbmap
rebuilds as a part of gc/traversal work:
LFS3_M_REBUILDGBMAP 0x00000400 Rebuild the gbmap
LFS3_GC_REBUILDGBMAP 0x00000400 Rebuild the gbmap
LFS3_I_REBUILDGBMAP 0x00000400 The gbmap is not full
LFS3_T_REBUILDGBMAP 0x00000400 Rebuild the gbmap
On paper, this is more or less identical to repopulating the lookahead
buffer -- traverse the filesystem, mark blocks as in-use, adopt the new
gbmap/lookahead buffer on success -- but a couple nuances make
rebuilding the gbmap a bit trickier:
- Unlike the lookahead buffer, which eagerly zeros in allocation, we
need an explicit zeroing pass before we start marking blocks as
in-use. This means multiple traversals can potentially conflict with
each other, risking the adoption of a clobbered gbmap.
- The gbmap, which stores information on disk, relies on block
allocation and the temporary "in-flight window" defined by allocator
ckpoints to avoid circular block states during gbmap rebuilds. This
makes gbmap rebuilds sensitive to allocator ckpoints, which we
consider more-or-less a noop in other parts of the system.
Though now that I'm writing this, it might have been possible to
instead include gbmap rebuild snapshots in fs traversals... but that
would probably have been much more complicated.
- Rebuilding the gbmap requires writing to disk and is generally much
more expensive/destructive. We want to avoid trying to rebuild the
gbmap when it's not possible to actually make progress.
On top of this, the current trv-clobber system is a delicate,
error-prone mess.
---
To simplify everything related to gbmap rebuilds, I added a new
internal traversal flag: LFS3_t_CKPOINTED:
LFS3_t_CKPOINTED 0x04000000 Filesystem ckpointed during traversal
LFS3_t_CKPOINTED is set, unconditionally, on all open traversals in
lfs3_alloc_ckpoint, and provides a simple, robust mechanism for checking
if _any_ allocator checkpoints have occured since a traversal was
started. Since lfs3_alloc_ckpoint is required before any block
allocation, this provides a strong guarantee that nothing funny happened
to any allocator state during a traversal.
This makes lfs3_alloc_ckpoint a bit less cheap, but the strong
guarantees that allocator state is unmodified during traversal are well
worth it.
This makes both lookahead and gbmap passes simpler, safer, and easier to
reason about.
I'd like to adopt something similar+stronger for LFs3_t_MUTATED, and
reduce this back to two flags, but that can be a future commit.
---
Unfortunately due to the potential for recursion, this ended up reusing
less logic between lfs3_alloc_rebuildgbmap and lfs3_mtree_gc than I had
hoped, but at like the main chunks (lfs3_alloc_remap,
lfs3_gbmap_setbptr, lfs3_alloc_adoptgbmap) could be split out into
common functions.
The result is a decent chunk of code and stack, but the value is high as
incremental gbmap rebuilds are the only option to reduce the latency
spikes introduced by the gbmap allocator (it's not significantly worse
than the lookahead buffer, but both do require traversing the entire
filesystem):
code stack ctx
before: 37164 2352 684
after: 37208 (+0.1%) 2360 (+0.3%) 684 (+0.0%)
code stack ctx
gbmap before: 39708 2376 848
gbmap after: 40100 (+1.0%) 2432 (+2.4%) 848 (+0.0%)
Note the gbmap build is now measured with LFS3_GBMAP=1, instead of
LFS3_YES_GBMAP=1 (maybe-gbmap) as before. This includes the cost of
mkgbmap, lfs3_f_isgbmap, etc.
This commit is contained in:
+13
-7
@@ -90,6 +90,7 @@ FLAGS = [
|
||||
|
||||
('M_MKCONSISTENT', 0x00000100, "Make the filesystem consistent" ),
|
||||
('M_LOOKAHEAD', 0x00000200, "Populate lookahead buffer" ),
|
||||
('M_REBUILDGBMAP', 0x00000400, "Rebuild the gbmap" ),
|
||||
('M_COMPACT', 0x00000800, "Compact metadata logs" ),
|
||||
('M_CKMETA', 0x00001000, "Check metadata checksums" ),
|
||||
('M_CKDATA', 0x00002000, "Check metadata + data checksums" ),
|
||||
@@ -97,6 +98,7 @@ FLAGS = [
|
||||
# GC flags
|
||||
('GC_MKCONSISTENT',0x00000100, "Make the filesystem consistent" ),
|
||||
('GC_LOOKAHEAD', 0x00000200, "Populate lookahead buffer" ),
|
||||
('GC_REBUILDGBMAP',0x00000400, "Rebuild the gbmap" ),
|
||||
('GC_COMPACT', 0x00000800, "Compact metadata logs" ),
|
||||
('GC_CKMETA', 0x00001000, "Check metadata checksums" ),
|
||||
('GC_CKDATA', 0x00002000, "Check metadata + data checksums" ),
|
||||
@@ -114,6 +116,7 @@ FLAGS = [
|
||||
|
||||
('I_MKCONSISTENT', 0x00000100, "Filesystem needs mkconsistent to write" ),
|
||||
('I_LOOKAHEAD', 0x00000200, "Lookahead buffer is not full" ),
|
||||
('I_REBUILDGBMAP', 0x00000400, "The gbmap is not full" ),
|
||||
('I_COMPACT', 0x00000800, "Filesystem may have uncompacted metadata" ),
|
||||
('I_CKMETA', 0x00001000, "Metadata checksums not checked recently" ),
|
||||
('I_CKDATA', 0x00002000, "Data checksums not checked recently" ),
|
||||
@@ -132,6 +135,7 @@ FLAGS = [
|
||||
('T_MKCONSISTENT',
|
||||
0x00000100, "Make the filesystem consistent" ),
|
||||
('T_LOOKAHEAD', 0x00000200, "Populate lookahead buffer" ),
|
||||
('T_REBUILDGBMAP', 0x00000400, "Rebuild the gbmap" ),
|
||||
('T_COMPACT', 0x00000800, "Compact metadata logs" ),
|
||||
('T_CKMETA', 0x00001000, "Check metadata checksums" ),
|
||||
('T_CKDATA', 0x00002000, "Check metadata + data checksums" ),
|
||||
@@ -149,18 +153,20 @@ FLAGS = [
|
||||
0x00000000, "Tstate = mroot-anchor" ),
|
||||
('^_MROOTCHAIN', 0x00010000, "Tstate = mroot-chain" ),
|
||||
('^_MTREE', 0x00020000, "Tstate = mtree" ),
|
||||
('^_BMAP', 0x00030000, "Tstate = bmap" ),
|
||||
('^_MDIRS', 0x00040000, "Tstate = mtree-mdirs" ),
|
||||
('^_MDIR', 0x00050000, "Tstate = mdir" ),
|
||||
('^_BTREE', 0x00060000, "Tstate = btree" ),
|
||||
('^_HANDLES', 0x00070000, "Tstate = open-mdirs" ),
|
||||
('^_HBTREE', 0x00080000, "Tstate = open-btree" ),
|
||||
('^_DONE', 0x00090000, "Tstate = done" ),
|
||||
('^_MDIRS', 0x00030000, "Tstate = mtree-mdirs" ),
|
||||
('^_MDIR', 0x00040000, "Tstate = mdir" ),
|
||||
('^_BTREE', 0x00050000, "Tstate = btree" ),
|
||||
('^_HANDLES', 0x00060000, "Tstate = open-mdirs" ),
|
||||
('^_HBTREE', 0x00070000, "Tstate = open-btree" ),
|
||||
('^_GBMAP', 0x00080000, "Tstate = gbmap" ),
|
||||
('^_GBMAP_P', 0x00090000, "Tstate = gbmap_p" ),
|
||||
('^_DONE', 0x000a0000, "Tstate = done" ),
|
||||
('t_BTYPE', 0x00f00000, "The current block type" ),
|
||||
('^_MDIR', 0x00100000, "Btype = mdir" ),
|
||||
('^_BTREE', 0x00200000, "Btype = btree" ),
|
||||
('^_DATA', 0x00300000, "Btype = data" ),
|
||||
('t_ZOMBIE', 0x08000000, "File has been removed" ),
|
||||
('t_CKPOINTED', 0x04000000, "Filesystem ckpointed during traversal" ),
|
||||
('t_DIRTY', 0x02000000, "Filesystem modified during traversal" ),
|
||||
('t_MUTATED', 0x01000000, "Filesystem modified by traversal" ),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user