]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(RLIMIT_AS): Do not define; just use conditional
authorJim Meyering <jim@meyering.net>
Fri, 13 Apr 2001 07:15:06 +0000 (07:15 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 13 Apr 2001 07:15:06 +0000 (07:15 +0000)
code, since RLIMIT_RSS is similar (and is not standardized).
(default_sort_size): Don't allocate more than the RSS limit,
if this host has such a limit.

src/sort.c

index 5d1a80a74993db6bb2e56df51dd78e469d334df2..4cbb835096770efb0763ddeda606b2a05a620737 100644 (file)
@@ -46,9 +46,6 @@
 struct rlimit { size_t rlim_cur; };
 # define getrlimit(Resource, Rlp) (-1)
 #endif
-#ifndef RLIMIT_AS
-# define RLIMIT_AS RLIMIT_DATA
-#endif
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "sort"
@@ -665,11 +662,22 @@ default_sort_size (void)
     size = mem;
   if (getrlimit (RLIMIT_DATA, &rlimit) == 0 && rlimit.rlim_cur < size)
     size = rlimit.rlim_cur;
+#ifdef RLIMIT_AS
   if (getrlimit (RLIMIT_AS, &rlimit) == 0 && rlimit.rlim_cur < size)
     size = rlimit.rlim_cur;
+#endif
+
+  /* Leave a large safety margin for the above limits, as failure can
+     occur when they are exceeded.  */
+  size /= 2;
+
+#ifdef RLIMIT_RSS
+  if (getrlimit (RLIMIT_RSS, &rlimit) == 0 && rlimit.rlim_cur < size)
+    size = rlimit.rlim_cur;
+#endif
 
-  /* Use half of SIZE, but no less than the minimum.  */
-  return MAX (size / 2, MIN_SORT_SIZE);
+  /* Use no less than the minimum.  */
+  return MAX (size, MIN_SORT_SIZE);
 }
 
 /* Return the sort buffer size to use with the input files identified