From: Jim Meyering Date: Fri, 13 Apr 2001 07:15:06 +0000 (+0000) Subject: (RLIMIT_AS): Do not define; just use conditional X-Git-Tag: FILEUTILS-4_0_44~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=66b1f79fb06d8d0715e74cedb848f245d404b5dd;p=thirdparty%2Fcoreutils.git (RLIMIT_AS): Do not define; just use conditional 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. --- diff --git a/src/sort.c b/src/sort.c index 5d1a80a749..4cbb835096 100644 --- a/src/sort.c +++ b/src/sort.c @@ -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