Reimplemented the internal opened-mdir linked-list

littlefs uses an invasive linked-list in open mdirs to keep any open
files/dirs (and some special mdirs) in sync during filesystem
operations. The main benefit of this is that the filesystem doesn't need
to know the number of open files at compile time.

The implementation here introduces a new type, lfsr_openedmdir_t, for
mdirs that want to participate in the opened-mdir linked-list. This
saves a couple words of memory in the cases where the mdir does not need
to participate in the opend-mdir linked-list.

Since we are creating quite a few more mdir structs in lfsr_mdir_commit now,
the size of this struct is valuable.

The implementation of lfsr_mdir_commit knew this was coming, so aside
from the new type, adding this feature was straightforward:

1. Update opened-mdirs based on in-flight attrs.
2. Update opened-mdirs rbyd state.
3. Mark any deleted opened-mdirs with the reserved mid -2.
4. Test.
This commit is contained in:
Christopher Haster
2023-05-24 16:17:46 -05:00
parent c60fa69ce1
commit 565c8cb9c7
3 changed files with 518 additions and 3 deletions
+11 -2
View File
@@ -371,8 +371,7 @@ typedef union lfsr_btree {
} lfsr_btree_t;
typedef struct lfsr_mdir {
// -3 => deleted
// -2 => an out-of-tree mdir
// -2 => deleted
// -1 => mroot
// >=0 => bid in the mtree
lfs_ssize_t mid;
@@ -380,6 +379,13 @@ typedef struct lfsr_mdir {
lfsr_rbyd_t rbyd;
} lfsr_mdir_t;
typedef struct lfsr_openedmdir {
struct lfsr_openedmdir *next;
// this rid is followed during splits
lfs_ssize_t rid;
lfsr_mdir_t mdir;
} lfsr_openedmdir_t;
typedef struct lfs_mdir {
lfs_block_t pair[2];
@@ -473,6 +479,9 @@ typedef struct lfs {
lfsr_mdir_t mroot;
lfsr_btree_t mtree;
// linked-list of opened mdirs
lfsr_openedmdir_t *opened;
#ifdef LFS_MIGRATE
struct lfs1 *lfs1;
#endif