WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] xmalloc: return unused full pages on multi-page

To: Jan Beulich <JBeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] xmalloc: return unused full pages on multi-page allocations
From: Keir Fraser <keir@xxxxxxx>
Date: Thu, 13 Oct 2011 08:46:00 +0100
Cc:
Delivery-date: Thu, 13 Oct 2011 00:47:50 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:user-agent:date:subject:from:to:message-id:thread-topic :thread-index:in-reply-to:mime-version:content-type :content-transfer-encoding; bh=s6v4thR02UetvuAJEWPSpHH0m/1FtL5/5sbMkHFl/40=; b=VvTKwLAlTZSzedLZ5RWg6bZaJdEts7W9rP/Twne8bFGF5DqjmSyB9Q5oqR4tfq/Z04 LVPHBJsrvQOD2P923z2iU8qmX0w99g/Y+qYEdOAjbCvFvj12QjCzw9vdnsMdbSkUS1ly j2zaGANxXpgfYUhd/N9r8QioLpx6+3rw9jI60=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4E96AF16020000780005B0A0@xxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcyJfCZkbEMBNWLm5kyTsCMcXQbWbw==
Thread-topic: [Xen-devel] [PATCH] xmalloc: return unused full pages on multi-page allocations
User-agent: Microsoft-Entourage/12.30.0.110427
On 13/10/2011 08:27, "Jan Beulich" <JBeulich@xxxxxxxx> wrote:

> Certain (boot time) allocations are relatively large (particularly when
> building with high NR_CPUS), but can also happen to be pretty far away
> from a power-of-two size. Utilize the page allocator's (other than
> Linux'es) capability of allowing to return space from higher-order
> allocations in smaller pieces to return the unused parts immediately.
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

Acked-by: Keir Fraser <keir@xxxxxxx>

> --- a/xen/common/xmalloc_tlsf.c
> +++ b/xen/common/xmalloc_tlsf.c
> @@ -527,13 +527,21 @@ static void xmalloc_pool_put(void *p)
>  static void *xmalloc_whole_pages(unsigned long size)
>  {
>      struct bhdr *b;
> -    unsigned int pageorder = get_order_from_bytes(size + BHDR_OVERHEAD);
> +    unsigned int i, pageorder = get_order_from_bytes(size + BHDR_OVERHEAD);
> +    char *p;
>  
>      b = alloc_xenheap_pages(pageorder, 0);
>      if ( b == NULL )
>          return NULL;
>  
> -    b->size = (1 << (pageorder + PAGE_SHIFT));
> +    b->size = PAGE_ALIGN(size + BHDR_OVERHEAD);
> +    for ( p = (char *)b + b->size, i = 0; i < pageorder; ++i )
> +        if ( (unsigned long)p & (PAGE_SIZE << i) )
> +        {
> +            free_xenheap_pages(p, i);
> +            p += PAGE_SIZE << i;
> +        }
> +
>      return (void *)b->ptr.buffer;
>  }
>  
> @@ -611,7 +619,20 @@ void xfree(void *p)
>      }
>  
>      if ( b->size >= PAGE_SIZE )
> -        free_xenheap_pages((void *)b, get_order_from_bytes(b->size));
> +    {
> +        unsigned int i, order = get_order_from_bytes(b->size);
> +
> +        BUG_ON((unsigned long)b & ((PAGE_SIZE << order) - 1));
> +        for ( i = 0; ; ++i )
> +        {
> +            if ( !(b->size & (PAGE_SIZE << i)) )
> +                continue;
> +            b->size -= PAGE_SIZE << i;
> +            free_xenheap_pages((void *)b + b->size, i);
> +            if ( i + 1 >= order )
> +                break;
> +        }
> +    }
>      else
>          xmem_pool_free(p, xenpool);
>  }
> 
> 
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/xen-devel



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>