This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][RFC] Allow explicit shrinking of arena heaps using anenvironment variable
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>, Rich Felker <dalias at aerifal dot cx>, libc-alpha at sourceware dot org
- Date: Sat, 11 Aug 2012 13:15:12 -0400
- Subject: Re: [PATCH][RFC] Allow explicit shrinking of arena heaps using anenvironment variable
- References: <20120720223800.GB26330@sunsite.ms.mff.cuni.cz><20120720224417.E8BEF2C0CA@topped-with-meat.com><20120721061814.GC26330@sunsite.ms.mff.cuni.cz><20120721133217.GY544@brightrain.aerifal.cx><20120725183634.E0C5F2C0B1@topped-with-meat.com><CAHGf_=qCMy6K1MD4miN65GkMSumYTtH23xoFrfmCuh=WjybAVA@mail.gmail.com><20120730230006.355f9b67@spoyarek><5016D012.5000101@gmail.com><20120730191758.GX544@brightrain.aerifal.cx><CAHGf_=rRm4B4YCZKgos5hWN_QTYV76fAxcegO7D3x=4_A88Rvw@mail.gmail.com><20120731132705.GZ544@brightrain.aerifal.cx><CAHGf_=pN3KJGL_V1tQ2+o0=-RY4q2du7PJDnak9y7xyzYiH1tQ@mail.gmail.com><20120810235226.408e3cec@spoyarek><CADZpyiz05WnMqrREEtSs+oW_0Ld6hnfxbmFMk_hKYL-P_gFTag@mail.gmail.com><20120811205228.42ab905f@spoyarek>
On Sat, Aug 11, 2012 at 11:22 AM, Siddhesh Poyarekar
<siddhesh@redhat.com> wrote:
> Hi,
>
> Here you go Carlos:
That was an *excellent* re-cap and summary of the existing thread!
I really appreciate the effort you took to write this up.
> Based on this, I propose making the heap shrinking unconditionally use
> mmap(PROT_NONE, MAP_FIXED). I have been using the attached patch to do
> this since about 24 hours now on my Fedora 16 x86_64 without any
> problems. I have also verified that the patch does not cause any
> regressions in the testsuite.
This looks like a very reasonable solution.
Machines don't have infinite memory and we all want to get more out of
our systems, and this patch is a step towards that goal.
> ChangeLog:
>
> * malloc/arena.c (shrink_heap): Unconditionally release memory
> using mmap.
Some nits:
1. Please add a verbose comment about *why* we do this unconditionally
anymore and *why* we don't use MADV_DONTNEED.
diff --git a/malloc/arena.c b/malloc/arena.c
index 06bdd77..943ceb6 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -618,20 +618,14 @@ shrink_heap(heap_info *h, long diff)
new_size = (long)h->size - diff;
if(new_size < (long)sizeof(*h))
return -1;
+
[CAO] 2. Don't add spaces.
/* Try to re-map the extra heap space freshly to save memory, and
make it inaccessible. */
- if (__builtin_expect (__libc_enable_secure, 0))
- {
- if((char *)MMAP((char *)h + new_size, diff, PROT_NONE,
- MAP_FIXED) == (char *) MAP_FAILED)
- return -2;
- h->mprotect_size = new_size;
- }
- else
- madvise ((char *)h + new_size, diff, MADV_DONTNEED);
- /*fprintf(stderr, "shrink %p %08lx\n", h, new_size);*/
+ if((char *)MMAP((char *)h + new_size, diff, PROT_NONE,
[CAO] 3. Space after if, MMAP, and casts (even if the old code didn't).
+ MAP_FIXED) == (char *) MAP_FAILED)
[CAO] 4. This whole construct would be more understandable as:
[CAO] if ((char *) MMAP ((char *)h + new_size, diff, PROT_NONE, MAP_FIXED)
[CAO] == (char *) MAP_FAILED)
[CAO] i.e. break after operator.
+ return -2;
- h->size = new_size;
+ h->size = h->mprotect_size = new_size;
return 0;
}
OK with those changes.
Check it in on Wednesday to give other people some more review time.
Cheers,
Carlos.