• Darrick J. Wong's avatar
    xfs: enable sorting of xfile-backed arrays · 232ea052
    Darrick J. Wong authored
    The btree bulk loading code requires that records be provided in the
    correct record sort order for the given btree type.  In general, repair
    code cannot be required to collect records in order, and it is not
    feasible to insert new records in the middle of an array to maintain
    sort order.
    
    Implement a sorting algorithm so that we can sort the records just prior
    to bulk loading.  In principle, an xfarray could consume many gigabytes
    of memory and its backing pages can be sent out to disk at any time.
    This means that we cannot map the entire array into memory at once, so
    we must find a way to divide the work into smaller portions (e.g. a
    page) that /can/ be mapped into memory.
    
    Quicksort seems like a reasonable fit for this purpose, since it uses a
    divide and conquer strategy to keep its average runtime logarithmic.
    The solution presented here is a port of the glibc implementation, which
    itself is derived from the median-of-three and tail call recursion
    strategies outlined by Sedgwick.
    
    Subsequent patches will optimize the implementation further by utilizing
    the kernel's heapsort on directly-mapped memory whenever possible, and
    improving the quicksort pivot selection algorithm to try to avoid O(n^2)
    collapses.
    
    Note: The sorting functionality gets its own patch because the basic big
    array mechanisms were plenty for a single code patch.
    Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
    Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
    232ea052
trace.h 36.6 KB