|
|
f57669 |
Description: Make trimming logic consistent.
|
|
|
f57669 |
Author: Carlos O'Donell
|
|
|
f57669 |
Origin: git://sourceware.org/git/glibc.git
|
|
|
f57669 |
Bug-RHEL: N/A
|
|
|
f57669 |
Bug-Fedora: N/A
|
|
|
f57669 |
Bug-Upstream: #17195
|
|
|
f57669 |
Upstream status: committed
|
|
|
f57669 |
|
|
|
f57669 |
commit e4bc326dbbf7328775fe7dd39de1178821363e0a
|
|
|
f57669 |
Author: Carlos O'Donell <carlos@systemhalted.org>
|
|
|
f57669 |
Date: Wed Oct 7 22:21:36 2015 -0400
|
|
|
f57669 |
|
|
|
f57669 |
malloc: Consistently apply trim_threshold to all heaps (Bug 17195)
|
|
|
f57669 |
|
|
|
f57669 |
In the per-thread arenas we apply trim_threshold-based checks
|
|
|
f57669 |
to the extra space between the pad and the top_area. This isn't
|
|
|
f57669 |
quite accurate and instead we should be harmonizing with the way
|
|
|
f57669 |
in which trim_treshold is applied everywhere else like sysrtim
|
|
|
f57669 |
and _int_free. The trimming check should be based on the size of
|
|
|
f57669 |
the top chunk and only the size of the top chunk. The following
|
|
|
f57669 |
patch harmonizes the trimming and make it consistent for the main
|
|
|
f57669 |
arena and thread arenas.
|
|
|
f57669 |
|
|
|
f57669 |
In the old code a large padding request might have meant that
|
|
|
f57669 |
trimming was not triggered. Now trimming is considered first based
|
|
|
f57669 |
on the chunk, then the pad is subtracted, and the remainder trimmed.
|
|
|
f57669 |
This is how all the other trimmings operate. I didn't measure the
|
|
|
f57669 |
performance difference of this change because it corrects what I
|
|
|
f57669 |
consider to be a behavioural anomaly. We'll need some profile driven
|
|
|
f57669 |
optimization to make this code better, and even there Ondrej and
|
|
|
f57669 |
others have better ideas on how to speedup malloc.
|
|
|
f57669 |
|
|
|
f57669 |
Tested on x86_64 with no regressions. Already reviewed by Siddhesh
|
|
|
f57669 |
Poyarekar and Mel Gorman here and discussed here:
|
|
|
f57669 |
https://sourceware.org/ml/libc-alpha/2015-05/msg00002.html
|
|
|
f57669 |
|
|
|
f57669 |
Index: glibc-2.17-c758a686/malloc/arena.c
|
|
|
f57669 |
===================================================================
|
|
|
f57669 |
--- glibc-2.17-c758a686.orig/malloc/arena.c
|
|
|
f57669 |
+++ glibc-2.17-c758a686/malloc/arena.c
|
|
|
f57669 |
@@ -697,14 +697,20 @@ heap_trim(heap_info *heap, size_t pad)
|
|
|
f57669 |
}
|
|
|
f57669 |
|
|
|
f57669 |
/* Uses similar logic for per-thread arenas as the main arena with systrim
|
|
|
f57669 |
- by preserving the top pad and at least a page. */
|
|
|
f57669 |
+ and _int_free by preserving the top pad and rounding down to the nearest
|
|
|
f57669 |
+ page. */
|
|
|
f57669 |
top_size = chunksize(top_chunk);
|
|
|
f57669 |
+ if ((unsigned long)(top_size) <
|
|
|
f57669 |
+ (unsigned long)(mp_.trim_threshold))
|
|
|
f57669 |
+ return 0;
|
|
|
f57669 |
+
|
|
|
f57669 |
top_area = top_size - MINSIZE - 1;
|
|
|
f57669 |
if (top_area <= pad)
|
|
|
f57669 |
return 0;
|
|
|
f57669 |
|
|
|
f57669 |
+ /* Release in pagesize units and round down to the nearest page. */
|
|
|
f57669 |
extra = ALIGN_DOWN(top_area - pad, pagesz);
|
|
|
f57669 |
- if ((unsigned long) extra < mp_.trim_threshold)
|
|
|
f57669 |
+ if (extra == 0)
|
|
|
f57669 |
return 0;
|
|
|
f57669 |
/* Try to shrink. */
|
|
|
f57669 |
if(shrink_heap(heap, extra) != 0)
|