xfs: convert xfarray insertion sort to heapsort using scratchpad memory
authorDarrick J. Wong <djwong@kernel.org>
Thu, 10 Aug 2023 14:48:05 +0000 (07:48 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 10 Aug 2023 14:48:05 +0000 (07:48 -0700)
commitc390c6450318345b3caa1996a4ef1367477a5aa8
treef7265f351787d3f0c2a2e74e0a32875bc5d351fb
parent232ea052775f9d3f32c0275610f2638b97641c2a
xfs: convert xfarray insertion sort to heapsort using scratchpad memory

In the previous patch, we created a very basic quicksort implementation
for xfile arrays.  While the use of an alternate sorting algorithm to
avoid quicksort recursion on very small subsets reduces the runtime
modestly, we could do better than a load and store-heavy insertion sort,
particularly since each load and store requires a page mapping lookup in
the xfile.

For a small increase in kernel memory requirements, we could instead
bulk load the xfarray records into memory, use the kernel's existing
heapsort implementation to sort the records, and bulk store the memory
buffer back into the xfile.  On the author's computer, this reduces the
runtime by about 5% on a 500,000 element array.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Kent Overstreet <kent.overstreet@linux.dev>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/scrub/trace.h
fs/xfs/scrub/xfarray.c
fs/xfs/scrub/xfarray.h