VBoxServiceBalloon.cpp revision 7c028717ac3be15e08ddb01366ad75c251307f3f
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * VBoxService - Memory Ballooning.
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * Copyright (C) 2006-2010 Oracle Corporation
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * This file is part of VirtualBox Open Source Edition (OSE), as
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * available from http://www.virtualbox.org. This file is free software;
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * you can redistribute it and/or modify it under the terms of the GNU
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * General Public License (GPL) as published by the Free Software
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * Foundation, in version 2 as it comes in the "COPYING" file of the
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
582e60f5478cf04cad2b208c3e8013fef3617942Jaco Jooste/*******************************************************************************
582e60f5478cf04cad2b208c3e8013fef3617942Jaco Jooste* Header Files *
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford*******************************************************************************/
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford/*******************************************************************************
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford* Global Variables *
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford*******************************************************************************/
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford/** The balloon size. */
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford/** The semaphore we're blocking on. */
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamfordstatic RTSEMEVENTMULTI g_MemBalloonEvent = NIL_RTSEMEVENTMULTI;
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford/** The array holding the R3 pointers of the balloon. */
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford/** True = madvise(MADV_DONTFORK) works, false otherwise. */
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford * Check whether madvise() works.
1cbd8752ba5fabec320a628e3c2624a775b7d246Eugenia Sergueeva void *pv = (void*)mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
e2c90f7e6a7cd643ed88d1870224e3b91daa8724Tony Bamford g_fSysMadviseWorks = madvise(pv, PAGE_SIZE, MADV_DONTFORK) == 0;
static void* VBoxServiceBalloonAllocChunk(void)
char *pu8;
#ifdef RT_OS_LINUX
if (!g_fSysMadviseWorks)
return NULL;
if (g_fSysMadviseWorks)
if (!pu8)
return pu8;
return pu8;
#ifdef RT_OS_LINUX
if (!g_fSysMadviseWorks)
* Adapt the R0 memory balloon by granting/reclaiming 1MB chunks to/from R0.
return VINF_SUCCESS;
VBoxServiceVerbose(3, "VBoxServiceBalloonSetUser: cNewChunks=%u g_cMemBalloonChunks=%u\n", cNewChunks, g_cMemBalloonChunks);
uint32_t i;
if (!pv)
#ifndef RT_OS_SOLARIS
uint32_t i;
#ifndef RT_OS_SOLARIS
return VINF_SUCCESS;
return VINF_SUCCESS;
static DECLCALLBACK(int) VBoxServiceBalloonOption(const char **ppszShort, int argc, char **argv, int *pi)
return VINF_SUCCESS;
g_cMemBalloonChunks = 0;
bool fHandleInR3;
if (fHandleInR3)
rc = VERR_SERVICE_DISABLED; /** @todo Playing safe for now, figure out the exact status codes here. */
return rc;
return rc;
bool fHandleInR3;
if (fHandleInR3)
VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: successfully set requested balloon size %d.\n", cNewChunks);
if (*pfShutdown)
if (*pfShutdown)
NULL,
NULL,