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

[Xen-devel] Re: [PATCH] xen-mapcache: Fix rlimit set size.

To: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH] xen-mapcache: Fix rlimit set size.
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Tue, 2 Aug 2011 23:01:40 +0100
Cc: Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <Stefano.Stabellini@xxxxxxxxxxxxx>, QEMU-devel <qemu-devel@xxxxxxxxxx>, Alexander Graf <agraf@xxxxxxx>
Delivery-date: Tue, 02 Aug 2011 14:56:27 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1312226782-26882-2-git-send-email-anthony.perard@xxxxxxxxxx>
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>
References: <1312226782-26882-2-git-send-email-anthony.perard@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
On Mon, 1 Aug 2011, Anthony PERARD wrote:
> Previously, the address space soft limit was set mcache_max_size. So,
> before the mcache_max_size was reached by the mapcache, QEMU was killed
> for overuse of the virtual address space.
> 
> This patch fix that by setting the soft limit to mcache_max_size + 80MB.
> I observed that QEMU use 75MB more than max_mcache_size after several
> empirical tests.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
> ---
>  xen-mapcache.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/xen-mapcache.c b/xen-mapcache.c
> index 007136a..40212f7 100644
> --- a/xen-mapcache.c
> +++ b/xen-mapcache.c
> @@ -40,6 +40,13 @@
>  #endif
>  #define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
>  
> +/* This is the size of the virtual address space reserve to QEMU that will 
> not
> + * be use by MapCache.
> + * From empirical tests I observed that qemu use 75MB more than the
> + * max_mcache_size.
> + */
> +#define NON_MCACHE_MEMORY_SIZE (80 * 1024 * 1024)
> +
>  #define mapcache_lock()   ((void)0)
>  #define mapcache_unlock() ((void)0)
>  
> @@ -93,14 +100,14 @@ void xen_map_cache_init(void)
>      mapcache->last_address_index = -1;
>  
>      getrlimit(RLIMIT_AS, &rlimit_as);
> -    if (rlimit_as.rlim_max < MCACHE_MAX_SIZE) {
> +    if (rlimit_as.rlim_max < MCACHE_MAX_SIZE + NON_MCACHE_MEMORY_SIZE) {
>          rlimit_as.rlim_cur = rlimit_as.rlim_max;
>      } else {
> -        rlimit_as.rlim_cur = MCACHE_MAX_SIZE;
> +        rlimit_as.rlim_cur = MCACHE_MAX_SIZE + NON_MCACHE_MEMORY_SIZE;
>      }

In the 'else' case we should just set rlimit_as.rlim_cur to
rlimit_as.rlim_max.
Also we should detect if we are running as a privileged process and if
that is the case just modify rlimit_as.rlim_max to RLIM_INFINITY.
If we are not running as a privileged process and if rlim_max is not
high enough we should print a warning because trying to guess how much
virtual memory qemu is going to use is obviously error prone.

So this is how I think it should work:

if (rlimit_as.rlim_max < MCACHE_MAX_SIZE) {
    if (qemu is priviledged) {
        rlimit_as.rlim_max = RLIM_INFINITY;
        rlimit_as.rlim_cur = RLIM_INFINITY;
    } else {
        print a warning
        mapcache->max_mcache_size = rlimit_as.rlim_cur - NON_MCACHE_MEMORY_SIZE;
        rlimit_as.rlim_cur = rlimit_as.rlim_max;
    }
} else {
    rlimit_as.rlim_cur = rlimit_as.rlim_max;
}
setrlimit


>      setrlimit(RLIMIT_AS, &rlimit_as);
> -    mapcache->max_mcache_size = rlimit_as.rlim_cur;
> +    mapcache->max_mcache_size = rlimit_as.rlim_cur - NON_MCACHE_MEMORY_SIZE;
>  
>      mapcache->nr_buckets =
>          (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +
> -- 
> Anthony PERARD
> 

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