* [Qemu-devel] [PATCH V2] xen-mapcache: Fix rlimit set size.
@ 2011-08-04 17:06 Anthony PERARD
2011-08-12 20:23 ` Stefano Stabellini
0 siblings, 1 reply; 2+ messages in thread
From: Anthony PERARD @ 2011-08-04 17:06 UTC (permalink / raw)
To: QEMU-devel; +Cc: Anthony PERARD, Xen Devel, Alexander Graf, Stefano Stabellini
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 <anthony.perard@citrix.com>
---
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) +
--
Anthony PERARD
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH V2] xen-mapcache: Fix rlimit set size.
2011-08-04 17:06 [Qemu-devel] [PATCH V2] xen-mapcache: Fix rlimit set size Anthony PERARD
@ 2011-08-12 20:23 ` Stefano Stabellini
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Stabellini @ 2011-08-12 20:23 UTC (permalink / raw)
To: Anthony PERARD; +Cc: Xen Devel, Stefano Stabellini, QEMU-devel, Alexander Graf
On Thu, 4 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 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 <anthony.perard@citrix.com>
it looks good
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-12 20:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-04 17:06 [Qemu-devel] [PATCH V2] xen-mapcache: Fix rlimit set size Anthony PERARD
2011-08-12 20:23 ` Stefano Stabellini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).