On 06/11/2012 07:24 PM, Paul Eggert wrote: > On 06/11/2012 01:47 PM, Voelker, Bernhard wrote: >> Am I wrong? > > I think so. The newly inserted code > "if (total * 0.75 < size) size = total * 0.75;" > is independent of the limits affected by > the ulimit and plimit commands. In your example > 'sort' will consume 4 * 15/16 GB if physmem_available > reports 4 GB available.
Thanks for the clarification. I was confused. Here's a patch to move the code regarding physical/available/total memory down to where it's used (on top of your patch). Have a nice day, Berny >From 1957c9a46e0427b2bbb346c2cb29710e7cbd6182 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker <[email protected]> Date: Thu, 14 Jun 2012 07:54:34 +0200 Subject: [PATCH] maint: cleanup size determination in sort * src/sort.c (default_sort_size): Move physmem code "down" to first use. --- src/sort.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sort.c b/src/sort.c index f21e092..c0d0c84 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1405,11 +1405,6 @@ specify_nthreads (int oi, char c, char const *s) 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, @@ -1435,6 +1430,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); + /* Similarly, leave a 1/4 margin for physical memory. */ if (total * 0.75 < size) size = total * 0.75; -- 1.7.7
