coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] maint: cleanup size determination in sort [was: overly aggre


From: Jim Meyering
Subject: Re: [PATCH] maint: cleanup size determination in sort [was: overly aggressive memory usage by sort.c]
Date: Wed, 20 Jun 2012 09:16:40 +0200

Bernhard Voelker wrote:
> Here's a patch to move the code regarding physical/available/total
> memory down to where it's used (on top of your patch).

Thanks.  I've pushed that -- tweaked to move the rlimit declaration down, too:

>From daab10d9f58d62af896d6b33d06e0d4998f2f114 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Wed, 20 Jun 2012 07:57:31 +0200
Subject: [PATCH] maint: sort: style adjustment to help clarify size 
determination

* src/sort.c (default_sort_size): Move physmem code "down" to first use.
---
 src/sort.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index 2593a2a..5a48ce6 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1400,22 +1400,15 @@ specify_nthreads (int oi, char c, char const *s)
   return nthreads;
 }

-
 /* Return the default sort size.  */
 static size_t
 default_sort_size (void)
 {
-  /* Let MEM be available memory or 1/8 of total memory, whichever
-     is greater.  */
-  double avail = physmem_available ();
-  double total = physmem_total ();
-  double mem = MAX (avail, total / 8);
-  struct rlimit rlimit;
-
   /* 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.  */
   size_t size = SIZE_MAX;
+  struct rlimit rlimit;
   if (getrlimit (RLIMIT_DATA, &rlimit) == 0 && rlimit.rlim_cur < size)
     size = rlimit.rlim_cur;
 #ifdef RLIMIT_AS
@@ -1434,6 +1427,12 @@ default_sort_size (void)
     size = rlimit.rlim_cur / 16 * 15;
 #endif

+  /* Let MEM be available memory or 1/8 of total memory, whichever
+     is greater.  */
+  double avail = physmem_available ();
+  double total = physmem_total ();
+  double mem = MAX (avail, total / 8);
+
   /* 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.  */
--
1.7.11



reply via email to

[Prev in Thread] Current Thread [Next in Thread]