diff options
author | Jim Meyering <jim@meyering.net> | 2001-04-13 07:15:06 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2001-04-13 07:15:06 +0000 |
commit | 66b1f79fb06d8d0715e74cedb848f245d404b5dd (patch) | |
tree | fce0f5b7cba5286c8c03a7a1d36bd0203850094f | |
parent | f9b3e59ae52b6f359d3e66dd66c926cd6b51a54c (diff) | |
download | coreutils-66b1f79fb06d8d0715e74cedb848f245d404b5dd.tar.xz |
(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.
-rw-r--r-- | src/sort.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/sort.c b/src/sort.c index 5d1a80a74..4cbb83509 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 |