]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit - libxfs/Makefile
xfs: use a b+tree for the in-core extent list
authorChristoph Hellwig <hch@lst.de>
Fri, 17 Nov 2017 04:11:35 +0000 (22:11 -0600)
committerEric Sandeen <sandeen@redhat.com>
Fri, 17 Nov 2017 04:11:35 +0000 (22:11 -0600)
commitb37d753d506f7714d669c8082a02295948238e90
tree9e03a5f3bc0fb8ac41dfd803727e189a8c1b19df
parentc2e6c70434f50d9f386aad3586dea38fcf55689d
xfs: use a b+tree for the in-core extent list

Source kernel commit: 6bdcf26ade8825ffcdc692338e715cd7ed0820d8

Replace the current linear list and the indirection array for the in-core
extent list with a b+tree to avoid the need for larger memory allocations
for the indirection array when lots of extents are present.  The current
extent list implementations leads to heavy pressure on the memory
allocator when modifying files with a high extent count, and can lead
to high latencies because of that.

The replacement is a b+tree with a few quirks.  The leaf nodes directly
store the extent record in two u64 values.  The encoding is a little bit
different from the existing in-core extent records so that the start
offset and length which are required for lookups can be retreived with
simple mask operations.  The inner nodes store a 64-bit key containing
the start offset in the first half of the node, and the pointers to the
next lower level in the second half.  In either case we walk the node
from the beginninig to the end and do a linear search, as that is more
efficient for the low number of cache lines touched during a search
(2 for the inner nodes, 4 for the leaf nodes) than a binary search.
We store termination markers (zero length for the leaf nodes, an
otherwise impossible high bit for the inner nodes) to terminate the key
list / records instead of storing a count to use the available cache
lines as efficiently as possible.

One quirk of the algorithm is that while we normally split a node half and
half like usual btree implementations we just spill over entries added at
the very end of the list to a new node on its own.  This means we get a
100% fill grade for the common cases of bulk insertion when reading an
inode into memory, and when only sequentially appending to a file.  The
downside is a slightly higher chance of splits on the first random
insertions.

Both insert and removal manually recurse into the lower levels, but
the bulk deletion of the whole tree is still implemented as a recursive
function call, although one limited by the overall depth and with very
little stack usage in every iteration.

For the first few extents we dynamically grow the list from a single
extent to the next powers of two until we have a first full leaf block
and that building the actual tree.

The code started out based on the generic lib/btree.c code from Joern
Engel based on earlier work from Peter Zijlstra, but has since been
rewritten beyond recognition.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
[sandeen: use uint32_t for rec_len, update trace macros & repair/]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
13 files changed:
include/libxfs.h
include/xfs_trace.h
libxfs/Makefile
libxfs/util.c
libxfs/xfs_bmap.c
libxfs/xfs_bmap_btree.c
libxfs/xfs_bmap_btree.h
libxfs/xfs_format.h
libxfs/xfs_iext_tree.c [new file with mode: 0644]
libxfs/xfs_inode_fork.c
libxfs/xfs_inode_fork.h
libxfs/xfs_types.h
repair/phase6.c