From patchwork Thu Aug 4 17:06:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 108542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6408CB6F70 for ; Fri, 5 Aug 2011 03:06:48 +1000 (EST) Received: from localhost ([::1]:35479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qp1Nc-0003CH-VM for incoming@patchwork.ozlabs.org; Thu, 04 Aug 2011 13:06:44 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qp1NV-0003AN-LB for qemu-devel@nongnu.org; Thu, 04 Aug 2011 13:06:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qp1NU-0008Mo-Jj for qemu-devel@nongnu.org; Thu, 04 Aug 2011 13:06:37 -0400 Received: from smtp.citrix.com ([66.165.176.89]:11778) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qp1NU-0008MC-Gf for qemu-devel@nongnu.org; Thu, 04 Aug 2011 13:06:36 -0400 X-IronPort-AV: E=Sophos;i="4.67,318,1309752000"; d="scan'208";a="15454585" Received: from ftlpmailmx01.citrite.net ([10.13.107.65]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/RC4-MD5; 04 Aug 2011 13:06:34 -0400 Received: from smtp01.ad.xensource.com (10.219.128.104) by smtprelay.citrix.com (10.13.107.65) with Microsoft SMTP Server id 8.3.137.0; Thu, 4 Aug 2011 13:06:33 -0400 Received: from perard.uk.xensource.com (dhcp-3-28.uk.xensource.com [10.80.3.28] (may be forged)) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id p74H6UHl006317; Thu, 4 Aug 2011 10:06:31 -0700 From: Anthony PERARD To: QEMU-devel Date: Thu, 4 Aug 2011 18:06:02 +0100 Message-ID: <1312477562-15827-1-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 1.7.2.5 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: Anthony PERARD , Xen Devel , Alexander Graf , Stefano Stabellini Subject: [Qemu-devel] [PATCH V2] xen-mapcache: Fix rlimit set size. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 the maximum than can have QEMU. So the soft and hard limit are always set to RLIM_INFINITY if QEMU is privileged. In case QEMU is not run as root and the limit is too low, the maximum mapcache size will be set the rlim_max - 80MB because observed that QEMU use 75MB more than the maximum mapcache size after several empirical tests. Signed-off-by: Anthony PERARD --- Change: - This time, always set the rlimit to max or INFINITY if qemu is run as root. - Also, print a warning message if the rlimit can not be set to INFINITY. xen-mapcache.c | 27 ++++++++++++++++++++++----- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/xen-mapcache.c b/xen-mapcache.c index 007136a..f698876 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) @@ -92,15 +99,25 @@ void xen_map_cache_init(void) QTAILQ_INIT(&mapcache->locked_entries); mapcache->last_address_index = -1; - getrlimit(RLIMIT_AS, &rlimit_as); - if (rlimit_as.rlim_max < MCACHE_MAX_SIZE) { - rlimit_as.rlim_cur = rlimit_as.rlim_max; + if (geteuid() == 0) { + rlimit_as.rlim_cur = RLIM_INFINITY; + rlimit_as.rlim_max = RLIM_INFINITY; + mapcache->max_mcache_size = MCACHE_MAX_SIZE; } else { - rlimit_as.rlim_cur = MCACHE_MAX_SIZE; + getrlimit(RLIMIT_AS, &rlimit_as); + rlimit_as.rlim_cur = rlimit_as.rlim_max; + + if (rlimit_as.rlim_max != RLIM_INFINITY) { + fprintf(stderr, "Warning: QEMU's maximum size of virtual memory is not infinity.\n"); + } + if (rlimit_as.rlim_max < MCACHE_MAX_SIZE + NON_MCACHE_MEMORY_SIZE) { + mapcache->max_mcache_size = rlimit_as.rlim_max - NON_MCACHE_MEMORY_SIZE; + } else { + mapcache->max_mcache_size = MCACHE_MAX_SIZE; + } } setrlimit(RLIMIT_AS, &rlimit_as); - mapcache->max_mcache_size = rlimit_as.rlim_cur; mapcache->nr_buckets = (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +