From 0e181024c00b746a930aab6a0cfd9162d7b67ae4 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Sat, 18 Dec 2010 05:27:46 +0000 Subject: sort: use at most 8 threads by default * src/sort.c (main): If --parallel isn't specified, restrict the number of threads to 8 by default. If the --parallel option is specified, then allow any number of threads to be set, independent of the number of processors on the system. * doc/coreutils.texi (sort invocation): Document the changes to determining the number of threads to use. Mention the memory overhead when using multiple threads. * tests/misc/sort-spinlock-abuse: Allow single core systems that support pthreads. * tests/misc/sort-stale-thread-mem: Likewise. * tests/misc/sort-unique-segv: Likewise. * NEWS: Mention the change in behaviour. --- src/sort.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/sort.c b/src/sort.c index 54dd81528..6cc058896 100644 --- a/src/sort.c +++ b/src/sort.c @@ -116,6 +116,10 @@ struct rlimit { size_t rlim_cur; }; this number has any practical effect. */ enum { SUBTHREAD_LINES_HEURISTIC = 4 }; +/* The number of threads after which there are + diminishing performance gains. */ +enum { DEFAULT_MAX_THREADS = 8 }; + /* Exit statuses. */ enum { @@ -455,7 +459,7 @@ Other options:\n\ -t, --field-separator=SEP use SEP instead of non-blank to blank transition\n\ -T, --temporary-directory=DIR use DIR for temporaries, not $TMPDIR or %s;\n\ multiple options specify multiple directories\n\ - --parallel=N limit the number of sorts run concurrently to N\n\ + --parallel=N change the number sorts run concurrently to N\n\ -u, --unique with -c, check for strict ordering;\n\ without -c, output only the first of an equal run\n\ "), DEFAULT_TMPDIR); @@ -4595,14 +4599,15 @@ main (int argc, char **argv) } else { - unsigned long int np2 = num_processors (NPROC_CURRENT_OVERRIDABLE); - if (!nthreads || nthreads > np2) - nthreads = np2; + if (!nthreads) + { + nthreads = MIN (DEFAULT_MAX_THREADS, + num_processors (NPROC_CURRENT_OVERRIDABLE)); + } /* Avoid integer overflow later. */ size_t nthreads_max = SIZE_MAX / (2 * sizeof (struct merge_node)); - if (nthreads_max < nthreads) - nthreads = nthreads_max; + nthreads = MIN (nthreads, nthreads_max); sort (files, nfiles, outfile, nthreads); } -- cgit v1.2.3-54-g00ecf