[PATCH] [v5] malloc: Consistently apply trim_threshold to all heaps [BZ #17195]

Siddhesh Poyarekar siddhesh@redhat.com
Fri Feb 20 13:04:00 GMT 2015


On Thu, Feb 19, 2015 at 10:42:05AM +0000, Mel Gorman wrote:
> 2015-02-19  Mel Gorman  <mgorman@suse.de>
> 
>   [BZ #17195]
>   * malloc/arena.c (free): Apply trim threshold to per-thread heaps
>     as well as the main arena.
> ---
>  malloc/arena.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/malloc/arena.c b/malloc/arena.c
> index 886defb074a2..cdb4e900a66a 100644
> --- a/malloc/arena.c
> +++ b/malloc/arena.c
> @@ -696,20 +696,21 @@ heap_trim (heap_info *heap, size_t pad)
>      }
>    top_size = chunksize (top_chunk);
>    extra = (top_size - pad - MINSIZE - 1) & ~(pagesz - 1);
> -  if (extra < (long) pagesz)
> -    return 0;
> -
> -  /* Try to shrink. */
> -  if (shrink_heap (heap, extra) != 0)
> -    return 0;
> +  if (extra >= (long) mp_.trim_threshold)

Cast EXTRA to unsigned long instead.  The above will break if trimming
is disabled since it will always trim instead.

Why did you change the condition BTW?  The earlier one-line change was
nicer and only needed to have the cast fixed.

Siddhesh

> +    {
> +      /* Try to shrink. */
> +      if (shrink_heap (heap, extra) != 0)
> +        return 0;
>  
> -  ar_ptr->system_mem -= extra;
> -  arena_mem -= extra;
> +      ar_ptr->system_mem -= extra;
> +      arena_mem -= extra;
>  
> -  /* Success. Adjust top accordingly. */
> -  set_head (top_chunk, (top_size - extra) | PREV_INUSE);
> -  /*check_chunk(ar_ptr, top_chunk);*/
> -  return 1;
> +      /* Success. Adjust top accordingly. */
> +      set_head (top_chunk, (top_size - extra) | PREV_INUSE);
> +      /*check_chunk(ar_ptr, top_chunk);*/
> +      return 1;
> +    }
> +  return 0;
>  }
>  
>  /* Create a new arena with initial size "size".  */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150220/3280356a/attachment.sig>


More information about the Libc-alpha mailing list