]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: by default, do not exceed 3/4 of physical memory
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 10 Jul 2012 23:14:33 +0000 (16:14 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 10 Jul 2012 23:16:33 +0000 (16:16 -0700)
* src/sort.c (default_sort_size): Do not exceed 3/4 of total memory.
See Jeff Janes's bug report in
<http://lists.gnu.org/archive/html/coreutils/2012-06/msg00018.html>.

src/sort.c

index 10103e962d06531e01675ece0cfdbf2b4439c06f..85d7869de737d98bf87cc767c4fb5cb24e16fc83 100644 (file)
@@ -1412,9 +1412,10 @@ specify_nthreads (int oi, char c, char const *s)
 static size_t
 default_sort_size (void)
 {
-  /* Let SIZE be MEM, but no more than the maximum object size or
-     system resource limits.  Don't bother to check for values like
-     RLIM_INFINITY since in practice they are not much less than SIZE_MAX.  */
+  /* Let SIZE be MEM, but no more than the maximum object size,
+     total memory, or system resource limits.  Don't bother to check
+     for values like RLIM_INFINITY since in practice they are not much
+     less than SIZE_MAX.  */
   size_t size = SIZE_MAX;
   struct rlimit rlimit;
   if (getrlimit (RLIMIT_DATA, &rlimit) == 0 && rlimit.rlim_cur < size)
@@ -1441,6 +1442,10 @@ default_sort_size (void)
   double total = physmem_total ();
   double mem = MAX (avail, total / 8);
 
+  /* Leave a 1/4 margin for physical memory.  */
+  if (total * 0.75 < size)
+    size = total * 0.75;
+
   /* Return the minimum of MEM and SIZE, but no less than
      MIN_SORT_SIZE.  Avoid the MIN macro here, as it is not quite
      right when only one argument is floating point.  */