public static UnsafeExternalSorter createWithExistingInMemorySorter(
            TaskMemoryManager taskMemoryManager,
            TaskContext taskContext,
            RecordComparator recordComparator,
            PrefixComparator prefixComparator,
            int initialSize,
            long pageSizeBytes,
            UnsafeInMemorySorter inMemorySorter) throws IOException {
        UnsafeExternalSorter sorter = new UnsafeExternalSorter(
                taskMemoryManager,
                taskContext,
                recordComparator,
                prefixComparator,
                initialSize,
                pageSizeBytes,
                inMemorySorter);
        sorter.spill(Long.MAX_VALUE, sorter);
        // The external sorter will be used to insert records, in-memory sorter is not needed.
        sorter.inMemSorter = null;
        return sorter;
    }
Memory pages that hold the records being sorted. The pages in this list are freed when
spilling, although in principle we could recycle these pages across spills (on the other hand,
this might not be necessary if we maintained a pool of re-usable pages in the TaskMemoryManager
itself).
indexr-query-opt/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorter.java