Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 May 2021 11:27:55 -0700
From:      Cyril Zhang <cyril@freebsdfoundation.org>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: patch: Change default sorting algorithm in sort(1)
Message-ID:  <CAAmMA2gpbRU8sRJaEt5b83wjfO99V4C4xWBYC7Pyr6qeiR1-Xw@mail.gmail.com>
In-Reply-To: <63875688-33d3-d5a9-008f-4b8f53542434@selasky.org>
References:  <CAAmMA2gwbTrBqPyFNsEEOixsvUeXj8EUD-pkhUyF9QpYXD9=qw@mail.gmail.com> <63875688-33d3-d5a9-008f-4b8f53542434@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, May 18, 2021 at 2:24 AM Hans Petter Selasky <hps@selasky.org> wrote:
> Will this affect small-memory systems ability to sort data?

It shouldn't. The sort program already allocates a large amount of
memory during the preprocessing stage, far more than the amount of
bytes in the input file (which is a wholly separate issue from the one
at hand). The extra memory required for mergesort is much smaller than
that, even in the worst case where each line of input contains only a
single character.

The sort program also has a mechanism to use temporary files in order
to handle cases where the system runs out of memory. This is
documented in the -S flag:

-S size, --buffer-size=size
    Use size for the maximum size of the memory buffer.  Size modi-
    fiers %,b,K,M,G,T,P,E,Z,Y can be used.  If a memory limit is not
    explicitly specified, sort takes up to about 90% of available
    memory.  If the file size is too big to fit into the memory buf-
    fer, the temporary disk files are used to perform the sorting.

So a small-memory system could set the -S flag to allow for some extra
memory for use with mergesort.

Finally, the --heapsort and --quicksort flags will still be available,
if memory conservation is truly needed.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAAmMA2gpbRU8sRJaEt5b83wjfO99V4C4xWBYC7Pyr6qeiR1-Xw>