about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--NEWS12
-rw-r--r--malloc/arena.c13
3 files changed, 22 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e8df42d31..c687d1356f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-02  Mel Gorman  <mgorman@suse.de>
+
+	[BZ #17195]
+	* malloc/arena.c (free): Apply trim threshold to per-thread heaps
+	as well as the main arena.
+
 2015-03-31  H.J. Lu  <hongjiu.lu@intel.com>
 
 	[BZ #18185]
diff --git a/NEWS b/NEWS
index d2651b3a8d..dec42d8a15 100644
--- a/NEWS
+++ b/NEWS
@@ -10,12 +10,12 @@ Version 2.22
 * The following bugs are resolved with this release:
 
   4719, 13064, 14094, 14841, 14906, 15319, 15467, 15790, 15969, 16351,
-  16512, 16560, 16783, 17090, 17269, 17523, 17542, 17569, 17588, 17620,
-  17621, 17628, 17631, 17711, 17776, 17779, 17792, 17836, 17912, 17916,
-  17932, 17944, 17949, 17964, 17965, 17967, 17969, 17978, 17987, 17991,
-  17996, 17998, 17999, 18019, 18020, 18029, 18030, 18032, 18036, 18038,
-  18039, 18042, 18043, 18046, 18047, 18068, 18080, 18093, 18100, 18104,
-  18110, 18111, 18128, 18138, 18185.
+  16512, 16560, 16783, 17090, 17195, 17269, 17523, 17542, 17569, 17588,
+  17620, 17621, 17628, 17631, 17711, 17776, 17779, 17792, 17836, 17912,
+  17916, 17932, 17944, 17949, 17964, 17965, 17967, 17969, 17978, 17987,
+  17991, 17996, 17998, 17999, 18019, 18020, 18029, 18030, 18032, 18036,
+  18038, 18039, 18042, 18043, 18046, 18047, 18068, 18080, 18093, 18100,
+  18104, 18110, 18111, 18128, 18138, 18185.
 
 * A powerpc and powerpc64 optimization for TLS, similar to TLS descriptors
   for LD and GD on x86 and x86-64, has been implemented.  You will need
diff --git a/malloc/arena.c b/malloc/arena.c
index 8af51f05eb..d85f3712f7 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -658,7 +658,7 @@ heap_trim (heap_info *heap, size_t pad)
   unsigned long pagesz = GLRO (dl_pagesize);
   mchunkptr top_chunk = top (ar_ptr), p, bck, fwd;
   heap_info *prev_heap;
-  long new_size, top_size, extra, prev_size, misalign;
+  long new_size, top_size, top_area, extra, prev_size, misalign;
 
   /* Can this heap go away completely? */
   while (top_chunk == chunk_at_offset (heap, sizeof (*heap)))
@@ -694,9 +694,16 @@ heap_trim (heap_info *heap, size_t pad)
       set_head (top_chunk, new_size | PREV_INUSE);
       /*check_chunk(ar_ptr, top_chunk);*/
     }
+
+  /* Uses similar logic for per-thread arenas as the main arena with systrim
+     by preserving the top pad and at least a page.  */
   top_size = chunksize (top_chunk);
-  extra = (top_size - pad - MINSIZE - 1) & ~(pagesz - 1);
-  if (extra < (long) pagesz)
+  top_area = top_size - MINSIZE - 1;
+  if (top_area <= pad)
+    return 0;
+
+  extra = ALIGN_DOWN(top_area - pad, pagesz);
+  if ((unsigned long) extra < mp_.trim_threshold)
     return 0;
 
   /* Try to shrink. */