t: Limited lfs3_alloc_ckpoint to LFS3_T_LOOKAHEAD
This was causing a problem where the bmap was being rebuilt on every
lfs3_trv_read, even though the traversal was opened LFS3_T_RDONLY!
Also added a note on why we don't need to traverse both the active and
on-disk bmaps. Counterintuitively, we don't need to because the new bmap
always contains the entirety of the on-disk bmap.
Code changes minimal:
code stack ctx
before: 36840 2368 684
after: 36856 (+0.0%) 2368 (+0.0%) 684 (+0.0%)
code stack ctx
bmap before: 38440 2400 812
bmap after: 38452 (+0.0%) 2400 (+0.0%) 812 (+0.0%)
This commit is contained in:
@@ -10284,6 +10284,11 @@ static lfs3_stag_t lfs3_mtree_traverse_(lfs3_t *lfs3, lfs3_trv_t *trv,
|
||||
lfs3_t_settstate(&trv->b.h.flags, LFS3_TSTATE_HANDLES);
|
||||
continue;
|
||||
// end of bmap? guess we're done
|
||||
//
|
||||
// note that new bmaps _always_ contains the entirety of
|
||||
// the previous bmap, this avoids needing to traverse
|
||||
// both the on-disk bmap and active bmap for things like
|
||||
// lookahead scans
|
||||
} else if (lfs3_t_tstate(trv->b.h.flags)
|
||||
== LFS3_TSTATE_BMAP) {
|
||||
lfs3_t_settstate(&trv->b.h.flags, LFS3_TSTATE_DONE);
|
||||
@@ -11369,6 +11374,10 @@ static int lfs3_alloc_rebuildbmap(lfs3_t *lfs3) {
|
||||
// this avoids extra writing at a risk of needing to reconstruct the
|
||||
// bmap if we lose power
|
||||
//
|
||||
// note that new bmaps _always_ contains the entirety of the
|
||||
// previous bmap, this avoids needing to traverse both the on-disk
|
||||
// bmap and active bmap for things like lookahead scans
|
||||
//
|
||||
// don't worry about window/known, lfs3_mdir_commit updates these
|
||||
// last minute before calculating gdeltas for a commit
|
||||
lfs3->lookahead.bmapped = lfs3->lookahead.ckpoint;
|
||||
@@ -16818,10 +16827,16 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_trv_t *trv,
|
||||
|
||||
while (pending && (lfs3_off_t)steps > 0) {
|
||||
// checkpoint the allocator to maximize any lookahead scans
|
||||
//
|
||||
// TODO how does the bmap interact with LFS3_T_LOOKAHEAD? Should
|
||||
// we populate it? use a different flag?
|
||||
//
|
||||
#ifndef LFS3_RDONLY
|
||||
int err = lfs3_alloc_ckpoint(lfs3);
|
||||
if (err) {
|
||||
return err;
|
||||
if (lfs3_t_islookahead(trv->b.h.flags)) {
|
||||
int err = lfs3_alloc_ckpoint(lfs3);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17059,10 +17074,16 @@ int lfs3_trv_read(lfs3_t *lfs3, lfs3_trv_t *trv,
|
||||
#endif
|
||||
|
||||
// checkpoint the allocator to maximize any lookahead scans
|
||||
//
|
||||
// TODO how does the bmap interact with LFS3_T_LOOKAHEAD? Should
|
||||
// we populate it? use a different flag?
|
||||
//
|
||||
#ifndef LFS3_RDONLY
|
||||
int err = lfs3_alloc_ckpoint(lfs3);
|
||||
if (err) {
|
||||
return err;
|
||||
if (lfs3_t_islookahead(trv->b.h.flags)) {
|
||||
int err = lfs3_alloc_ckpoint(lfs3);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user