* Compile-Time Options
*/
-#define OS_DISABLE_UNLOAD (0)
-#define OS_DEBUG (1)
+#define OS_DISABLE_UNLOAD 0
+#define OS_DEBUG 1
/*
* Includes
#include "os.h"
#include "vmballoon.h"
-/*
- * Constants
- */
-
/*
* Types
*/
}
-static void os_pmap_alloc(os_pmap *p)
+static void
+os_pmap_alloc(os_pmap *p) // IN
{
/* number of pages (div. 8) */
p->size = (cnt.v_page_count + 7) / 8;
- /*
+ /*
* expand to nearest word boundary
* XXX: bitmap can be greater than total number of pages in system
*/
p->bitmap = (unsigned long *)kmem_alloc(kernel_map, p->size);
}
-static void os_pmap_free(os_pmap *p)
+
+static void
+os_pmap_free(os_pmap *p) // IN
{
kmem_free(kernel_map, (vm_offset_t)p->bitmap, p->size);
p->size = 0;
p->bitmap = NULL;
}
-static void os_pmap_init(os_pmap *p)
+
+static void
+os_pmap_init(os_pmap *p) // IN
{
/* alloc bitmap for pages in system */
- os_pmap_alloc(p);
+ os_pmap_alloc(p);
if (!p->bitmap) {
p->size = 0;
p->bitmap = NULL;
p->hint = 0;
}
-static vm_pindex_t os_pmap_getindex(os_pmap *p)
+
+static vm_pindex_t
+os_pmap_getindex(os_pmap *p) // IN
{
int i;
unsigned long bitidx, wordidx;
return (vm_pindex_t)-1;
}
-static void os_pmap_putindex(os_pmap *p, vm_pindex_t pindex)
+
+static void
+os_pmap_putindex(os_pmap *p, // IN
+ vm_pindex_t pindex) // IN
{
/* unset bit */
- p->bitmap[pindex / (8*sizeof(unsigned long))] &=
+ p->bitmap[pindex / (8*sizeof(unsigned long))] &=
~(1<<(pindex % (8*sizeof(unsigned long))));
}
-static void os_kmem_free(vm_page_t page)
+
+static void
+os_kmem_free(vm_page_t page) // IN
{
os_state *state = &global_state;
os_pmap *pmap = &state->pmap;
vm_page_free(page);
}
-static vm_page_t os_kmem_alloc(int alloc_normal_failed)
+
+static vm_page_t
+os_kmem_alloc(int alloc_normal_failed) // IN
{
vm_page_t page;
vm_pindex_t pindex;
return page;
}
-static void os_balloonobject_delete(void)
+
+static void
+os_balloonobject_delete(void)
{
vm_object_deallocate(global_state.vmobject);
}
-static void os_balloonobject_create(void)
+
+static void
+os_balloonobject_create(void)
{
global_state.vmobject = vm_object_allocate(OBJT_DEFAULT,
OFF_TO_IDX(VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS));
}
-static void os_timer_internal(void *data)
+static void
+os_timer_internal(void *data) // IN
{
os_timer *t = (os_timer *) data;
/* Do nothing. */
}
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * OS_Init --
+ *
+ * Called at driver startup, initializes the balloon state and structures.
+ *
+ * XXX : this function should return a value to indicate success or failure
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
void
-OS_Init(const char *name,
- const char *name_verbose,
- OSStatusHandler *handler)
+OS_Init(const char *name, // IN
+ const char *nameVerbose, // IN
+ OSStatusHandler *handler) // IN
{
os_state *state = &global_state;
os_pmap *pmap = &state->pmap;
/* initialize status state */
state->status.handler = handler;
state->status.name = name;
- state->status.name_verbose = name_verbose;
+ state->status.name_verbose = nameVerbose;
os_pmap_init(pmap);
os_balloonobject_create();
printf("%s initialized\n", state->status.name_verbose);
}
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * OS_Cleanup --
+ *
+ * Called when the driver is terminating, cleanup initialized structures.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
void
OS_Cleanup(void)
{
printf("%s unloaded\n", status->name_verbose);
}
+
/*
* Module Load/Unload Operations
*/
-static int vmmemctl_load(module_t mod, int cmd, void *arg)
+
+static int
+vmmemctl_load(module_t mod, // IN: Unused
+ int cmd, // IN
+ void *arg) // IN: Unused
{
int err = 0;
case MOD_UNLOAD:
if (OS_DISABLE_UNLOAD) {
- /* prevent moudle unload */
+ /* prevent module unload */
err = EBUSY;
} else {
Balloon_ModuleCleanup();
* Compile-Time Options
*/
-#define BALLOON_RATE_ADAPT (1)
+#define BALLOON_RATE_ADAPT 1
-#define BALLOON_DEBUG (1)
-#define BALLOON_DEBUG_VERBOSE (0)
+#define BALLOON_DEBUG 1
+#define BALLOON_DEBUG_VERBOSE 0
#define BALLOON_STATS
#define BALLOON_STATS_PROCFS
#include "os.h"
#include "backdoor.h"
#include "backdoor_balloon.h"
-
#include "vmballoon.h"
/*
#define BALLOON_NAME "vmmemctl"
#define BALLOON_NAME_VERBOSE "VMware memory control driver"
-#define BALLOON_PROTOCOL_VERSION (2)
+#define BALLOON_PROTOCOL_VERSION 2
-#define BALLOON_CHUNK_PAGES (1000)
+#define BALLOON_CHUNK_PAGES 1000
-#define BALLOON_NOSLEEP_ALLOC_MAX (16384)
+#define BALLOON_NOSLEEP_ALLOC_MAX 16384
-#define BALLOON_RATE_ALLOC_MIN (512)
-#define BALLOON_RATE_ALLOC_MAX (2048)
-#define BALLOON_RATE_ALLOC_INC (16)
+#define BALLOON_RATE_ALLOC_MIN 512
+#define BALLOON_RATE_ALLOC_MAX 2048
+#define BALLOON_RATE_ALLOC_INC 16
-#define BALLOON_RATE_FREE_MIN (512)
-#define BALLOON_RATE_FREE_MAX (16384)
-#define BALLOON_RATE_FREE_INC (16)
+#define BALLOON_RATE_FREE_MIN 512
+#define BALLOON_RATE_FREE_MAX 16384
+#define BALLOON_RATE_FREE_INC 16
-#define BALLOON_ERROR_PAGES (16)
+#define BALLOON_ERROR_PAGES 16
/*
* When guest is under memory pressure, use a reduced page allocation
* rate for next several cycles.
*/
-#define SLOW_PAGE_ALLOCATION_CYCLES (4)
+#define SLOW_PAGE_ALLOCATION_CYCLES 4
/*
* Move it to bora/public/balloon_def.h later, if needed. Note that
* distinguishing page allocation failures from monitor-backdoor errors.
* We use value 1000 because all monitor-backdoor error codes are < 1000.
*/
-#define BALLOON_PAGE_ALLOC_FAILURE (1000)
+#define BALLOON_PAGE_ALLOC_FAILURE 1000
// Maximum number of page allocations without yielding processor
-#define BALLOON_ALLOC_YIELD_THRESHOLD (1024)
+#define BALLOON_ALLOC_YIELD_THRESHOLD 1024
/*
static Bool timerStarted;
/*
- * Forward Declarations
+ * Balloon operations
*/
-
-static int Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType);
-static int Balloon_FreePage(Balloon *b, int monitorUnlock);
-static int Balloon_AdjustSize(Balloon *b, uint32 target);
-static void Balloon_Reset(Balloon *b);
-
+static int BalloonPageAlloc(Balloon *b, BalloonPageAllocType allocType);
+static int BalloonPageFree(Balloon *b, int monitorUnlock);
+static int BalloonAdjustSize(Balloon *b, uint32 target);
+static void BalloonReset(Balloon *b);
static void BalloonTimerHandler(void *clientData);
-static int Balloon_MonitorStart(Balloon *b);
-static int Balloon_MonitorGuestType(Balloon *b);
-static int Balloon_MonitorGetTarget(Balloon *b, uint32 *nPages);
-static int Balloon_MonitorLockPage(Balloon *b, PageHandle handle);
-static int Balloon_MonitorUnlockPage(Balloon *b, PageHandle handle);
+/*
+ * Backdoor Operations
+ */
+static int BalloonMonitorStart(Balloon *b);
+static int BalloonMonitorGuestType(Balloon *b);
+static int BalloonMonitorGetTarget(Balloon *b, uint32 *nPages);
+static int BalloonMonitorLockPage(Balloon *b, PageHandle handle);
+static int BalloonMonitorUnlockPage(Balloon *b, PageHandle handle);
/*
* Macros
GENERATE_LIST_INSERT(BalloonChunk);
GENERATE_LIST_REMOVE(BalloonChunk);
-/*
- * Procfs Operations
- */
-
/*
*----------------------------------------------------------------------
*/
static int
-BalloonProcRead(char *buf, // OUT
+BalloonProcRead(char *buf, // OUT
size_t size) // IN
{
int len = 0;
return len;
}
-/*
- * Utility Operations
- */
-
/*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonChunk_Destroy(BalloonChunk *chunk)
+BalloonChunk_Destroy(BalloonChunk *chunk) // IN
{
/* reclaim storage */
OS_Free(chunk, sizeof *chunk);
}
-/*
- * Balloon operations
- */
-
/*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_Init(Balloon *b)
+Balloon_Init(Balloon *b) // IN
{
/* clear state */
OS_MemZero(b, sizeof *b);
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_Deallocate(Balloon *b)
+Balloon_Deallocate(Balloon *b) // IN
{
unsigned int cnt = 0;
/* free all pages, skipping monitor unlock */
while (b->nChunks > 0) {
- (void) Balloon_FreePage(b, FALSE);
+ (void) BalloonPageFree(b, FALSE);
if (++cnt >= b->rateFree) {
cnt = 0;
OS_Yield();
}
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_Reset --
+ * BalloonReset --
*
* Resets balloon "b" to empty state. Frees all allocated pages
* and attempts to reset contact with the monitor.
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_Reset(Balloon *b)
+BalloonReset(Balloon *b) // IN
{
uint32 status;
Balloon_Deallocate(b);
/* send start command */
- status = Balloon_MonitorStart(b);
+ status = BalloonMonitorStart(b);
if (status == BALLOON_SUCCESS) {
/* clear flag */
b->resetFlag = 0;
/* report guest type */
- (void) Balloon_MonitorGuestType(b);
+ (void) BalloonMonitorGuestType(b);
}
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonTimerHandler(void *clientData)
+BalloonTimerHandler(void *clientData) // IN
{
Balloon *b = (Balloon *) clientData;
uint32 target = 0; // Silence compiler warning.
/* reset, if specified */
if (b->resetFlag) {
- Balloon_Reset(b);
+ BalloonReset(b);
}
/* contact monitor via backdoor */
- status = Balloon_MonitorGetTarget(b, &target);
+ status = BalloonMonitorGetTarget(b, &target);
/* decrement slowPageAllocationCycles counter */
if (b->slowPageAllocationCycles > 0) {
if (status == BALLOON_SUCCESS) {
/* update target, adjust size */
b->nPagesTarget = target;
- (void) Balloon_AdjustSize(b, target);
+ (void) BalloonAdjustSize(b, target);
}
}
/*
*----------------------------------------------------------------------
*
- * Balloon_ErrorPagesAlloc --
+ * BalloonErrorPagesAlloc --
*
* Attempt to add "page" to list of non-balloonable pages
* associated with "b".
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page)
+BalloonErrorPagesAlloc(Balloon *b, // IN
+ PageHandle page) // IN
{
/* fail if list already full */
if (b->errors.nextPage >= BALLOON_ERROR_PAGES) {
/*
*----------------------------------------------------------------------
*
- * Balloon_ErrorPagesFree --
+ * BalloonErrorPagesFree --
*
* Deallocates all pages on the list of non-balloonable pages
* associated with "b".
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_ErrorPagesFree(Balloon *b)
+BalloonErrorPagesFree(Balloon *b) // IN
{
- int i;
+ unsigned int i;
/* free all non-balloonable "error" pages */
for (i = 0; i < b->errors.nextPage; i++) {
b->errors.nextPage = 0;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_AllocPage --
+ * BalloonPageAlloc --
*
* Attempts to allocate a physical page, inflating balloon "b".
* Informs monitor of PPN for allocated page via backdoor.
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType)
+BalloonPageAlloc(Balloon *b, // IN
+ BalloonPageAllocType allocType) // IN
{
BalloonChunk *chunk;
PageHandle page;
}
/* inform monitor via backdoor */
- status = Balloon_MonitorLockPage(b, page);
+ status = BalloonMonitorLockPage(b, page);
if (status != BALLOON_SUCCESS) {
/* place on list of non-balloonable pages, retry allocation */
if ((status != BALLOON_ERROR_RESET) &&
- (Balloon_ErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) {
+ (BalloonErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) {
goto retry;
}
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_FreePage --
+ * BalloonPageFree --
*
* Attempts to deallocate a physical page, deflating balloon "b".
* Informs monitor of PPN for deallocated page via backdoor if
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_FreePage(Balloon *b, int monitorUnlock)
+BalloonPageFree(Balloon *b, // IN
+ int monitorUnlock) // IN
{
BalloonChunk *chunk;
PageHandle page;
/* inform monitor via backdoor */
if (monitorUnlock) {
- status = Balloon_MonitorUnlockPage(b, page);
+ status = BalloonMonitorUnlockPage(b, page);
if (status != BALLOON_SUCCESS) {
/* reset next pointer, fail */
chunk->nextPage++;
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonDecreaseRateAlloc(Balloon *b)
+BalloonDecreaseRateAlloc(Balloon *b) // IN
{
if (BALLOON_RATE_ADAPT) {
b->rateAlloc = MAX(b->rateAlloc / 2, BALLOON_RATE_ALLOC_MIN);
}
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc)
+BalloonIncreaseRateAlloc(Balloon *b, // IN
+ uint32 nAlloc) // IN
{
if (BALLOON_RATE_ADAPT) {
if (nAlloc >= b->rateAlloc) {
*/
static int
-BalloonInflate(Balloon *b, uint32 target)
+BalloonInflate(Balloon *b, // IN
+ uint32 target) // IN
{
int status, allocations = 0;
uint32 i, nAllocNoSleep, nAllocCanSleep;
for (i = 0; i < nAllocNoSleep; i++) {
/* Try NOSLEEP allocation */
- status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_NOSLEEP);
+ status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_NOSLEEP);
if (status != BALLOON_SUCCESS) {
if (status != BALLOON_PAGE_ALLOC_FAILURE) {
/*
* Not a page allocation failure, so release non-balloonable
* pages, and fail.
*/
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(status);
}
/*
if (i == nAllocNoSleep) {
BalloonIncreaseRateAlloc(b, nAllocNoSleep);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
} else {
/*
if (i > b->rateAlloc) {
BalloonIncreaseRateAlloc(b, i);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
} else {
/* update successful NOSLEEP allocations, and proceed */
for (i = 0; i < nAllocCanSleep; i++) {
/* Try CANSLEEP allocation */
- status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_CANSLEEP);
+ status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_CANSLEEP);
if(status != BALLOON_SUCCESS) {
if (status == BALLOON_PAGE_ALLOC_FAILURE) {
/*
BalloonDecreaseRateAlloc(b);
}
/* release non-balloonable pages, fail */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(status);
}
BalloonIncreaseRateAlloc(b, nAllocNoSleep + nAllocCanSleep);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
}
*/
static int
-BalloonDeflate(Balloon *b, uint32 target)
+BalloonDeflate(Balloon *b, // IN
+ uint32 target) // IN
{
int status, i;
uint32 nFree = b->nPages - target;
/* free pages to reach target */
for (i = 0; i < nFree; i++) {
- if ((status = Balloon_FreePage(b, TRUE)) != BALLOON_SUCCESS) {
+ status = BalloonPageFree(b, TRUE);
+ if (status != BALLOON_SUCCESS) {
if (BALLOON_RATE_ADAPT) {
/* quickly decrease rate if error */
b->rateFree = MAX(b->rateFree / 2, BALLOON_RATE_FREE_MIN);
/*
*----------------------------------------------------------------------
*
- * Balloon_AdjustSize --
+ * BalloonAdjustSize --
*
* Attempts to allocate or deallocate physical pages in order
* to reach desired "target" size for balloon "b".
*/
static int
-Balloon_AdjustSize(Balloon *b, uint32 target)
+BalloonAdjustSize(Balloon *b, // IN
+ uint32 target) // IN
{
/* done if already at target */
if (b->nPages == target) {
return(BALLOON_FAILURE);
}
-/*
- * Backdoor Operations
- */
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorStart --
+ * BalloonMonitorStart --
*
* Attempts to contact monitor via backdoor to begin operation.
*
*/
static int
-Balloon_MonitorStart(Balloon *b)
+BalloonMonitorStart(Balloon *b) // IN
{
uint32 status, target;
Backdoor_proto bp;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorGuestType --
+ * BalloonMonitorGuestType --
*
* Attempts to contact monitor and report guest OS identity.
*
*/
static int
-Balloon_MonitorGuestType(Balloon *b)
+BalloonMonitorGuestType(Balloon *b) // IN
{
uint32 status, target;
BalloonGuest identity;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorGetTarget --
+ * BalloonMonitorGetTarget --
*
* Attempts to contact monitor via backdoor to obtain desired
* balloon size.
*/
static int
-Balloon_MonitorGetTarget(Balloon *b, // IN
+BalloonMonitorGetTarget(Balloon *b, // IN
uint32 *target) // OUT
{
Backdoor_proto bp;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorLockPage --
+ * BalloonMonitorLockPage --
*
* Attempts to contact monitor and add PPN corresponding to
* the page handle to set of "balloon locked" pages.
*/
static int
-Balloon_MonitorLockPage(Balloon *b, // IN
+BalloonMonitorLockPage(Balloon *b, // IN
PageHandle handle) // IN
{
unsigned long ppn;
return status;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorUnlockPage --
+ * BalloonMonitorUnlockPage --
*
* Attempts to contact monitor and remove PPN corresponding to
* the page handle from set of "balloon locked" pages.
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_MonitorUnlockPage(Balloon *b, // IN
+BalloonMonitorUnlockPage(Balloon *b, // IN
PageHandle handle) // IN
{
unsigned long ppn;
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
* Reset connection before deallocating memory to avoid potential for
* additional spurious resets from guest touching deallocated pages.
*/
- Balloon_MonitorStart(b);
+ BalloonMonitorStart(b);
Balloon_Deallocate(b);
/* os-specific cleanup */
* Compile-Time Options
*/
-#define OS_DISABLE_UNLOAD (0)
-#define OS_DEBUG (1)
+#define OS_DISABLE_UNLOAD 0
+#define OS_DEBUG 1
/*
* Includes
#include <linux/timer.h>
#include <linux/kthread.h>
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_PROC_FS
#include <linux/stat.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
-#endif /* CONFIG_PROC_FS */
+#endif /* CONFIG_PROC_FS */
#include "compat_sched.h"
}
-#ifdef CONFIG_PROC_FS
-static int os_proc_show(struct seq_file *f,
- void *data)
+#ifdef CONFIG_PROC_FS
+static int
+os_proc_show(struct seq_file *f, // IN
+ void *data) // IN: Unused
{
os_status *s = &global_state.status;
char *buf = NULL;
}
-static int os_proc_open(struct inode *inode,
- struct file *file)
+static int
+os_proc_open(struct inode *inode, // IN: Unused
+ struct file *file) // IN
{
return single_open(file, os_proc_show, NULL);
}
+#endif /* CONFIG_PROC_FS */
-#endif
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * OS_Init --
+ *
+ * Called at driver startup, initializes the balloon state and structures.
+ *
+ * XXX : this function should return a value to indicate success or failure
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
void
-OS_Init(const char *name,
- const char *name_verbose,
- OSStatusHandler *handler)
+OS_Init(const char *name, // IN
+ const char *nameVerbose, // IN
+ OSStatusHandler *handler) // IN
{
os_state *state = &global_state;
static int initialized = 0;
/* initialize status state */
state->status.handler = handler;
state->status.name = name;
- state->status.name_verbose = name_verbose;
+ state->status.name_verbose = nameVerbose;
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_PROC_FS
/* register procfs device */
global_proc_entry = create_proc_entry("vmmemctl", S_IFREG | S_IRUGO, NULL);
if (global_proc_entry != NULL) {
global_proc_entry->proc_fops = &global_proc_fops;
}
-#endif /* CONFIG_PROC_FS */
+#endif /* CONFIG_PROC_FS */
/* log device load */
printk(KERN_INFO "%s initialized\n", state->status.name_verbose);
}
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * OS_Cleanup --
+ *
+ * Called when the driver is terminating, cleanup initialized structures.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
void
OS_Cleanup(void)
{
* Compile-Time Options
*/
-#define BALLOON_RATE_ADAPT (1)
+#define BALLOON_RATE_ADAPT 1
-#define BALLOON_DEBUG (1)
-#define BALLOON_DEBUG_VERBOSE (0)
+#define BALLOON_DEBUG 1
+#define BALLOON_DEBUG_VERBOSE 0
#define BALLOON_STATS
#define BALLOON_STATS_PROCFS
#include "os.h"
#include "backdoor.h"
#include "backdoor_balloon.h"
-
#include "vmballoon.h"
/*
#define BALLOON_NAME "vmmemctl"
#define BALLOON_NAME_VERBOSE "VMware memory control driver"
-#define BALLOON_PROTOCOL_VERSION (2)
+#define BALLOON_PROTOCOL_VERSION 2
-#define BALLOON_CHUNK_PAGES (1000)
+#define BALLOON_CHUNK_PAGES 1000
-#define BALLOON_NOSLEEP_ALLOC_MAX (16384)
+#define BALLOON_NOSLEEP_ALLOC_MAX 16384
-#define BALLOON_RATE_ALLOC_MIN (512)
-#define BALLOON_RATE_ALLOC_MAX (2048)
-#define BALLOON_RATE_ALLOC_INC (16)
+#define BALLOON_RATE_ALLOC_MIN 512
+#define BALLOON_RATE_ALLOC_MAX 2048
+#define BALLOON_RATE_ALLOC_INC 16
-#define BALLOON_RATE_FREE_MIN (512)
-#define BALLOON_RATE_FREE_MAX (16384)
-#define BALLOON_RATE_FREE_INC (16)
+#define BALLOON_RATE_FREE_MIN 512
+#define BALLOON_RATE_FREE_MAX 16384
+#define BALLOON_RATE_FREE_INC 16
-#define BALLOON_ERROR_PAGES (16)
+#define BALLOON_ERROR_PAGES 16
/*
* When guest is under memory pressure, use a reduced page allocation
* rate for next several cycles.
*/
-#define SLOW_PAGE_ALLOCATION_CYCLES (4)
+#define SLOW_PAGE_ALLOCATION_CYCLES 4
/*
* Move it to bora/public/balloon_def.h later, if needed. Note that
* distinguishing page allocation failures from monitor-backdoor errors.
* We use value 1000 because all monitor-backdoor error codes are < 1000.
*/
-#define BALLOON_PAGE_ALLOC_FAILURE (1000)
+#define BALLOON_PAGE_ALLOC_FAILURE 1000
// Maximum number of page allocations without yielding processor
-#define BALLOON_ALLOC_YIELD_THRESHOLD (1024)
+#define BALLOON_ALLOC_YIELD_THRESHOLD 1024
/*
static Bool timerStarted;
/*
- * Forward Declarations
+ * Balloon operations
*/
-
-static int Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType);
-static int Balloon_FreePage(Balloon *b, int monitorUnlock);
-static int Balloon_AdjustSize(Balloon *b, uint32 target);
-static void Balloon_Reset(Balloon *b);
-
+static int BalloonPageAlloc(Balloon *b, BalloonPageAllocType allocType);
+static int BalloonPageFree(Balloon *b, int monitorUnlock);
+static int BalloonAdjustSize(Balloon *b, uint32 target);
+static void BalloonReset(Balloon *b);
static void BalloonTimerHandler(void *clientData);
-static int Balloon_MonitorStart(Balloon *b);
-static int Balloon_MonitorGuestType(Balloon *b);
-static int Balloon_MonitorGetTarget(Balloon *b, uint32 *nPages);
-static int Balloon_MonitorLockPage(Balloon *b, PageHandle handle);
-static int Balloon_MonitorUnlockPage(Balloon *b, PageHandle handle);
+/*
+ * Backdoor Operations
+ */
+static int BalloonMonitorStart(Balloon *b);
+static int BalloonMonitorGuestType(Balloon *b);
+static int BalloonMonitorGetTarget(Balloon *b, uint32 *nPages);
+static int BalloonMonitorLockPage(Balloon *b, PageHandle handle);
+static int BalloonMonitorUnlockPage(Balloon *b, PageHandle handle);
/*
* Macros
GENERATE_LIST_INSERT(BalloonChunk);
GENERATE_LIST_REMOVE(BalloonChunk);
-/*
- * Procfs Operations
- */
-
/*
*----------------------------------------------------------------------
*/
static int
-BalloonProcRead(char *buf, // OUT
+BalloonProcRead(char *buf, // OUT
size_t size) // IN
{
int len = 0;
return len;
}
-/*
- * Utility Operations
- */
-
/*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonChunk_Destroy(BalloonChunk *chunk)
+BalloonChunk_Destroy(BalloonChunk *chunk) // IN
{
/* reclaim storage */
OS_Free(chunk, sizeof *chunk);
}
-/*
- * Balloon operations
- */
-
/*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_Init(Balloon *b)
+Balloon_Init(Balloon *b) // IN
{
/* clear state */
OS_MemZero(b, sizeof *b);
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_Deallocate(Balloon *b)
+Balloon_Deallocate(Balloon *b) // IN
{
unsigned int cnt = 0;
/* free all pages, skipping monitor unlock */
while (b->nChunks > 0) {
- (void) Balloon_FreePage(b, FALSE);
+ (void) BalloonPageFree(b, FALSE);
if (++cnt >= b->rateFree) {
cnt = 0;
OS_Yield();
}
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_Reset --
+ * BalloonReset --
*
* Resets balloon "b" to empty state. Frees all allocated pages
* and attempts to reset contact with the monitor.
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_Reset(Balloon *b)
+BalloonReset(Balloon *b) // IN
{
uint32 status;
Balloon_Deallocate(b);
/* send start command */
- status = Balloon_MonitorStart(b);
+ status = BalloonMonitorStart(b);
if (status == BALLOON_SUCCESS) {
/* clear flag */
b->resetFlag = 0;
/* report guest type */
- (void) Balloon_MonitorGuestType(b);
+ (void) BalloonMonitorGuestType(b);
}
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonTimerHandler(void *clientData)
+BalloonTimerHandler(void *clientData) // IN
{
Balloon *b = (Balloon *) clientData;
uint32 target = 0; // Silence compiler warning.
/* reset, if specified */
if (b->resetFlag) {
- Balloon_Reset(b);
+ BalloonReset(b);
}
/* contact monitor via backdoor */
- status = Balloon_MonitorGetTarget(b, &target);
+ status = BalloonMonitorGetTarget(b, &target);
/* decrement slowPageAllocationCycles counter */
if (b->slowPageAllocationCycles > 0) {
if (status == BALLOON_SUCCESS) {
/* update target, adjust size */
b->nPagesTarget = target;
- (void) Balloon_AdjustSize(b, target);
+ (void) BalloonAdjustSize(b, target);
}
}
/*
*----------------------------------------------------------------------
*
- * Balloon_ErrorPagesAlloc --
+ * BalloonErrorPagesAlloc --
*
* Attempt to add "page" to list of non-balloonable pages
* associated with "b".
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page)
+BalloonErrorPagesAlloc(Balloon *b, // IN
+ PageHandle page) // IN
{
/* fail if list already full */
if (b->errors.nextPage >= BALLOON_ERROR_PAGES) {
/*
*----------------------------------------------------------------------
*
- * Balloon_ErrorPagesFree --
+ * BalloonErrorPagesFree --
*
* Deallocates all pages on the list of non-balloonable pages
* associated with "b".
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_ErrorPagesFree(Balloon *b)
+BalloonErrorPagesFree(Balloon *b) // IN
{
- int i;
+ unsigned int i;
/* free all non-balloonable "error" pages */
for (i = 0; i < b->errors.nextPage; i++) {
b->errors.nextPage = 0;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_AllocPage --
+ * BalloonPageAlloc --
*
* Attempts to allocate a physical page, inflating balloon "b".
* Informs monitor of PPN for allocated page via backdoor.
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType)
+BalloonPageAlloc(Balloon *b, // IN
+ BalloonPageAllocType allocType) // IN
{
BalloonChunk *chunk;
PageHandle page;
}
/* inform monitor via backdoor */
- status = Balloon_MonitorLockPage(b, page);
+ status = BalloonMonitorLockPage(b, page);
if (status != BALLOON_SUCCESS) {
/* place on list of non-balloonable pages, retry allocation */
if ((status != BALLOON_ERROR_RESET) &&
- (Balloon_ErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) {
+ (BalloonErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) {
goto retry;
}
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_FreePage --
+ * BalloonPageFree --
*
* Attempts to deallocate a physical page, deflating balloon "b".
* Informs monitor of PPN for deallocated page via backdoor if
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_FreePage(Balloon *b, int monitorUnlock)
+BalloonPageFree(Balloon *b, // IN
+ int monitorUnlock) // IN
{
BalloonChunk *chunk;
PageHandle page;
/* inform monitor via backdoor */
if (monitorUnlock) {
- status = Balloon_MonitorUnlockPage(b, page);
+ status = BalloonMonitorUnlockPage(b, page);
if (status != BALLOON_SUCCESS) {
/* reset next pointer, fail */
chunk->nextPage++;
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonDecreaseRateAlloc(Balloon *b)
+BalloonDecreaseRateAlloc(Balloon *b) // IN
{
if (BALLOON_RATE_ADAPT) {
b->rateAlloc = MAX(b->rateAlloc / 2, BALLOON_RATE_ALLOC_MIN);
}
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc)
+BalloonIncreaseRateAlloc(Balloon *b, // IN
+ uint32 nAlloc) // IN
{
if (BALLOON_RATE_ADAPT) {
if (nAlloc >= b->rateAlloc) {
*/
static int
-BalloonInflate(Balloon *b, uint32 target)
+BalloonInflate(Balloon *b, // IN
+ uint32 target) // IN
{
int status, allocations = 0;
uint32 i, nAllocNoSleep, nAllocCanSleep;
for (i = 0; i < nAllocNoSleep; i++) {
/* Try NOSLEEP allocation */
- status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_NOSLEEP);
+ status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_NOSLEEP);
if (status != BALLOON_SUCCESS) {
if (status != BALLOON_PAGE_ALLOC_FAILURE) {
/*
* Not a page allocation failure, so release non-balloonable
* pages, and fail.
*/
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(status);
}
/*
if (i == nAllocNoSleep) {
BalloonIncreaseRateAlloc(b, nAllocNoSleep);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
} else {
/*
if (i > b->rateAlloc) {
BalloonIncreaseRateAlloc(b, i);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
} else {
/* update successful NOSLEEP allocations, and proceed */
for (i = 0; i < nAllocCanSleep; i++) {
/* Try CANSLEEP allocation */
- status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_CANSLEEP);
+ status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_CANSLEEP);
if(status != BALLOON_SUCCESS) {
if (status == BALLOON_PAGE_ALLOC_FAILURE) {
/*
BalloonDecreaseRateAlloc(b);
}
/* release non-balloonable pages, fail */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(status);
}
BalloonIncreaseRateAlloc(b, nAllocNoSleep + nAllocCanSleep);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
}
*/
static int
-BalloonDeflate(Balloon *b, uint32 target)
+BalloonDeflate(Balloon *b, // IN
+ uint32 target) // IN
{
int status, i;
uint32 nFree = b->nPages - target;
/* free pages to reach target */
for (i = 0; i < nFree; i++) {
- if ((status = Balloon_FreePage(b, TRUE)) != BALLOON_SUCCESS) {
+ status = BalloonPageFree(b, TRUE);
+ if (status != BALLOON_SUCCESS) {
if (BALLOON_RATE_ADAPT) {
/* quickly decrease rate if error */
b->rateFree = MAX(b->rateFree / 2, BALLOON_RATE_FREE_MIN);
/*
*----------------------------------------------------------------------
*
- * Balloon_AdjustSize --
+ * BalloonAdjustSize --
*
* Attempts to allocate or deallocate physical pages in order
* to reach desired "target" size for balloon "b".
*/
static int
-Balloon_AdjustSize(Balloon *b, uint32 target)
+BalloonAdjustSize(Balloon *b, // IN
+ uint32 target) // IN
{
/* done if already at target */
if (b->nPages == target) {
return(BALLOON_FAILURE);
}
-/*
- * Backdoor Operations
- */
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorStart --
+ * BalloonMonitorStart --
*
* Attempts to contact monitor via backdoor to begin operation.
*
*/
static int
-Balloon_MonitorStart(Balloon *b)
+BalloonMonitorStart(Balloon *b) // IN
{
uint32 status, target;
Backdoor_proto bp;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorGuestType --
+ * BalloonMonitorGuestType --
*
* Attempts to contact monitor and report guest OS identity.
*
*/
static int
-Balloon_MonitorGuestType(Balloon *b)
+BalloonMonitorGuestType(Balloon *b) // IN
{
uint32 status, target;
BalloonGuest identity;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorGetTarget --
+ * BalloonMonitorGetTarget --
*
* Attempts to contact monitor via backdoor to obtain desired
* balloon size.
*/
static int
-Balloon_MonitorGetTarget(Balloon *b, // IN
+BalloonMonitorGetTarget(Balloon *b, // IN
uint32 *target) // OUT
{
Backdoor_proto bp;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorLockPage --
+ * BalloonMonitorLockPage --
*
* Attempts to contact monitor and add PPN corresponding to
* the page handle to set of "balloon locked" pages.
*/
static int
-Balloon_MonitorLockPage(Balloon *b, // IN
+BalloonMonitorLockPage(Balloon *b, // IN
PageHandle handle) // IN
{
unsigned long ppn;
return status;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorUnlockPage --
+ * BalloonMonitorUnlockPage --
*
* Attempts to contact monitor and remove PPN corresponding to
* the page handle from set of "balloon locked" pages.
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_MonitorUnlockPage(Balloon *b, // IN
+BalloonMonitorUnlockPage(Balloon *b, // IN
PageHandle handle) // IN
{
unsigned long ppn;
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
* Reset connection before deallocating memory to avoid potential for
* additional spurious resets from guest touching deallocated pages.
*/
- Balloon_MonitorStart(b);
+ BalloonMonitorStart(b);
Balloon_Deallocate(b);
/* os-specific cleanup */
* Wrappers for Solaris system functions required by "vmmemctl".
*/
-/*
- * Includes
- */
#include <sys/types.h>
#include <sys/cred.h>
#include <sys/file.h>
* Constants
*/
-#define ONE_SECOND_IN_MICROSECONDS 1000000
+#define ONE_SECOND_IN_MICROSECONDS 1000000
/*
* Types
/*
- * Worker thread that periodically calls the timer handler. This is
- * executed by a user context thread so that it can block waiting for
- * memory without fear of deadlock.
+ *-----------------------------------------------------------------------------
+ *
+ * os_worker --
+ *
+ * Worker thread that periodically calls the timer handler. This is
+ * executed by a user context thread so that it can block waiting for
+ * memory without fear of deadlock.
+ *
+ * Results:
+ * On success: 0
+ * On failure: error code
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
*/
-static int os_worker(void)
+
+static int
+os_worker(void)
{
os_timer *t = &global_state.timer;
clock_t timeout;
mutex_exit(&t->lock);
}
-static void os_timer_cleanup(void)
+
+static void
+os_timer_cleanup(void)
{
os_timer *timer = &global_state.timer;
/* Do nothing. */
}
-void OS_Init(const char *name,
- const char *name_verbose,
- OSStatusHandler *handler)
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * OS_Init --
+ *
+ * Called at driver startup, initializes the balloon state and structures.
+ *
+ * XXX : this function should return a value to indicate success or failure
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+OS_Init(const char *name, // IN
+ const char *nameVerbose, // IN
+ OSStatusHandler *handler) // IN
{
os_state *state = &global_state;
static int initialized = 0;
state->kstats = BalloonKstatCreate();
state->id_space = id_space_create("vmmemctl", 0, INT_MAX);
state->name = name;
- state->name_verbose = name_verbose;
+ state->name_verbose = nameVerbose;
/* disable memscrubber */
#if defined(SOL9)
#endif
/* log device load */
- cmn_err(CE_CONT, "!%s initialized\n", name_verbose);
+ cmn_err(CE_CONT, "!%s initialized\n", nameVerbose);
}
-void OS_Cleanup(void)
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * OS_Cleanup --
+ *
+ * Called when the driver is terminating, cleanup initialized structures.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+OS_Cleanup(void)
{
os_state *state = &global_state;
/*
* Device configuration entry points
*/
-static int vmmemctl_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
+
+
+static int
+vmmemctl_attach(dev_info_t *dip, // IN
+ ddi_attach_cmd_t cmd) // IN
{
switch (cmd) {
case DDI_ATTACH:
}
}
-static int vmmemctl_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
+
+static int
+vmmemctl_detach(dev_info_t *dip, // IN
+ ddi_detach_cmd_t cmd) // IN
{
switch (cmd) {
case DDI_DETACH:
}
}
+
/*
- * Commands used by the user level daemon to control the driver.
- * Since the daemon is single threaded, we use a simple monitor to
- * make sure that only one thread is executing here at a time.
+ *-----------------------------------------------------------------------------
+ *
+ * vmmemctl_ioctl --
+ *
+ * Commands used by the user level daemon to control the driver.
+ * Since the daemon is single threaded, we use a simple monitor to
+ * make sure that only one thread is executing here at a time.
+ *
+ * Results:
+ * On success: 0
+ * On failure: error code
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
*/
-static int vmmemctl_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
- cred_t *cred, int *rvalp)
+
+static int
+vmmemctl_ioctl(dev_t dev, // IN: Unused
+ int cmd, // IN
+ intptr_t arg, // IN: Unused
+ int mode, // IN: Unused
+ cred_t *cred, // IN
+ int *rvalp) // IN: Unused
{
int error = 0;
static int busy = 0; /* set when a thread is in this function */
{&vmmodldrv, NULL}
};
-int _init(void)
+
+int
+_init(void)
{
int error;
return error;
}
-int _info(struct modinfo *modinfop)
+
+int
+_info(struct modinfo *modinfop) // IN
{
return mod_info(&vmmodlinkage, modinfop);
}
-int _fini(void)
+
+int
+_fini(void)
{
int error;
* Compile-Time Options
*/
-#define BALLOON_RATE_ADAPT (1)
+#define BALLOON_RATE_ADAPT 1
-#define BALLOON_DEBUG (1)
-#define BALLOON_DEBUG_VERBOSE (0)
+#define BALLOON_DEBUG 1
+#define BALLOON_DEBUG_VERBOSE 0
#define BALLOON_STATS
#define BALLOON_STATS_PROCFS
#include "os.h"
#include "backdoor.h"
#include "backdoor_balloon.h"
-
#include "vmballoon.h"
/*
#define BALLOON_NAME "vmmemctl"
#define BALLOON_NAME_VERBOSE "VMware memory control driver"
-#define BALLOON_PROTOCOL_VERSION (2)
+#define BALLOON_PROTOCOL_VERSION 2
-#define BALLOON_CHUNK_PAGES (1000)
+#define BALLOON_CHUNK_PAGES 1000
-#define BALLOON_NOSLEEP_ALLOC_MAX (16384)
+#define BALLOON_NOSLEEP_ALLOC_MAX 16384
-#define BALLOON_RATE_ALLOC_MIN (512)
-#define BALLOON_RATE_ALLOC_MAX (2048)
-#define BALLOON_RATE_ALLOC_INC (16)
+#define BALLOON_RATE_ALLOC_MIN 512
+#define BALLOON_RATE_ALLOC_MAX 2048
+#define BALLOON_RATE_ALLOC_INC 16
-#define BALLOON_RATE_FREE_MIN (512)
-#define BALLOON_RATE_FREE_MAX (16384)
-#define BALLOON_RATE_FREE_INC (16)
+#define BALLOON_RATE_FREE_MIN 512
+#define BALLOON_RATE_FREE_MAX 16384
+#define BALLOON_RATE_FREE_INC 16
-#define BALLOON_ERROR_PAGES (16)
+#define BALLOON_ERROR_PAGES 16
/*
* When guest is under memory pressure, use a reduced page allocation
* rate for next several cycles.
*/
-#define SLOW_PAGE_ALLOCATION_CYCLES (4)
+#define SLOW_PAGE_ALLOCATION_CYCLES 4
/*
* Move it to bora/public/balloon_def.h later, if needed. Note that
* distinguishing page allocation failures from monitor-backdoor errors.
* We use value 1000 because all monitor-backdoor error codes are < 1000.
*/
-#define BALLOON_PAGE_ALLOC_FAILURE (1000)
+#define BALLOON_PAGE_ALLOC_FAILURE 1000
// Maximum number of page allocations without yielding processor
-#define BALLOON_ALLOC_YIELD_THRESHOLD (1024)
+#define BALLOON_ALLOC_YIELD_THRESHOLD 1024
/*
static Bool timerStarted;
/*
- * Forward Declarations
+ * Balloon operations
*/
-
-static int Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType);
-static int Balloon_FreePage(Balloon *b, int monitorUnlock);
-static int Balloon_AdjustSize(Balloon *b, uint32 target);
-static void Balloon_Reset(Balloon *b);
-
+static int BalloonPageAlloc(Balloon *b, BalloonPageAllocType allocType);
+static int BalloonPageFree(Balloon *b, int monitorUnlock);
+static int BalloonAdjustSize(Balloon *b, uint32 target);
+static void BalloonReset(Balloon *b);
static void BalloonTimerHandler(void *clientData);
-static int Balloon_MonitorStart(Balloon *b);
-static int Balloon_MonitorGuestType(Balloon *b);
-static int Balloon_MonitorGetTarget(Balloon *b, uint32 *nPages);
-static int Balloon_MonitorLockPage(Balloon *b, PageHandle handle);
-static int Balloon_MonitorUnlockPage(Balloon *b, PageHandle handle);
+/*
+ * Backdoor Operations
+ */
+static int BalloonMonitorStart(Balloon *b);
+static int BalloonMonitorGuestType(Balloon *b);
+static int BalloonMonitorGetTarget(Balloon *b, uint32 *nPages);
+static int BalloonMonitorLockPage(Balloon *b, PageHandle handle);
+static int BalloonMonitorUnlockPage(Balloon *b, PageHandle handle);
/*
* Macros
GENERATE_LIST_INSERT(BalloonChunk);
GENERATE_LIST_REMOVE(BalloonChunk);
-/*
- * Procfs Operations
- */
-
/*
*----------------------------------------------------------------------
*/
static int
-BalloonProcRead(char *buf, // OUT
+BalloonProcRead(char *buf, // OUT
size_t size) // IN
{
int len = 0;
return len;
}
-/*
- * Utility Operations
- */
-
/*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonChunk_Destroy(BalloonChunk *chunk)
+BalloonChunk_Destroy(BalloonChunk *chunk) // IN
{
/* reclaim storage */
OS_Free(chunk, sizeof *chunk);
}
-/*
- * Balloon operations
- */
-
/*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_Init(Balloon *b)
+Balloon_Init(Balloon *b) // IN
{
/* clear state */
OS_MemZero(b, sizeof *b);
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_Deallocate(Balloon *b)
+Balloon_Deallocate(Balloon *b) // IN
{
unsigned int cnt = 0;
/* free all pages, skipping monitor unlock */
while (b->nChunks > 0) {
- (void) Balloon_FreePage(b, FALSE);
+ (void) BalloonPageFree(b, FALSE);
if (++cnt >= b->rateFree) {
cnt = 0;
OS_Yield();
}
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_Reset --
+ * BalloonReset --
*
* Resets balloon "b" to empty state. Frees all allocated pages
* and attempts to reset contact with the monitor.
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_Reset(Balloon *b)
+BalloonReset(Balloon *b) // IN
{
uint32 status;
Balloon_Deallocate(b);
/* send start command */
- status = Balloon_MonitorStart(b);
+ status = BalloonMonitorStart(b);
if (status == BALLOON_SUCCESS) {
/* clear flag */
b->resetFlag = 0;
/* report guest type */
- (void) Balloon_MonitorGuestType(b);
+ (void) BalloonMonitorGuestType(b);
}
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonTimerHandler(void *clientData)
+BalloonTimerHandler(void *clientData) // IN
{
Balloon *b = (Balloon *) clientData;
uint32 target = 0; // Silence compiler warning.
/* reset, if specified */
if (b->resetFlag) {
- Balloon_Reset(b);
+ BalloonReset(b);
}
/* contact monitor via backdoor */
- status = Balloon_MonitorGetTarget(b, &target);
+ status = BalloonMonitorGetTarget(b, &target);
/* decrement slowPageAllocationCycles counter */
if (b->slowPageAllocationCycles > 0) {
if (status == BALLOON_SUCCESS) {
/* update target, adjust size */
b->nPagesTarget = target;
- (void) Balloon_AdjustSize(b, target);
+ (void) BalloonAdjustSize(b, target);
}
}
/*
*----------------------------------------------------------------------
*
- * Balloon_ErrorPagesAlloc --
+ * BalloonErrorPagesAlloc --
*
* Attempt to add "page" to list of non-balloonable pages
* associated with "b".
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_ErrorPagesAlloc(Balloon *b, unsigned long page)
+BalloonErrorPagesAlloc(Balloon *b, // IN
+ PageHandle page) // IN
{
/* fail if list already full */
if (b->errors.nextPage >= BALLOON_ERROR_PAGES) {
/*
*----------------------------------------------------------------------
*
- * Balloon_ErrorPagesFree --
+ * BalloonErrorPagesFree --
*
* Deallocates all pages on the list of non-balloonable pages
* associated with "b".
*
*----------------------------------------------------------------------
*/
+
static void
-Balloon_ErrorPagesFree(Balloon *b)
+BalloonErrorPagesFree(Balloon *b) // IN
{
- int i;
+ unsigned int i;
/* free all non-balloonable "error" pages */
for (i = 0; i < b->errors.nextPage; i++) {
b->errors.nextPage = 0;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_AllocPage --
+ * BalloonPageAlloc --
*
* Attempts to allocate a physical page, inflating balloon "b".
* Informs monitor of PPN for allocated page via backdoor.
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_AllocPage(Balloon *b, BalloonPageAllocType allocType)
+BalloonPageAlloc(Balloon *b, // IN
+ BalloonPageAllocType allocType) // IN
{
BalloonChunk *chunk;
PageHandle page;
}
/* inform monitor via backdoor */
- status = Balloon_MonitorLockPage(b, page);
+ status = BalloonMonitorLockPage(b, page);
if (status != BALLOON_SUCCESS) {
/* place on list of non-balloonable pages, retry allocation */
if ((status != BALLOON_ERROR_RESET) &&
- (Balloon_ErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) {
+ (BalloonErrorPagesAlloc(b, page) == BALLOON_SUCCESS)) {
goto retry;
}
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_FreePage --
+ * BalloonPageFree --
*
* Attempts to deallocate a physical page, deflating balloon "b".
* Informs monitor of PPN for deallocated page via backdoor if
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_FreePage(Balloon *b, int monitorUnlock)
+BalloonPageFree(Balloon *b, // IN
+ int monitorUnlock) // IN
{
BalloonChunk *chunk;
PageHandle page;
/* inform monitor via backdoor */
if (monitorUnlock) {
- status = Balloon_MonitorUnlockPage(b, page);
+ status = BalloonMonitorUnlockPage(b, page);
if (status != BALLOON_SUCCESS) {
/* reset next pointer, fail */
chunk->nextPage++;
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonDecreaseRateAlloc(Balloon *b)
+BalloonDecreaseRateAlloc(Balloon *b) // IN
{
if (BALLOON_RATE_ADAPT) {
b->rateAlloc = MAX(b->rateAlloc / 2, BALLOON_RATE_ALLOC_MIN);
}
}
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
+
static void
-BalloonIncreaseRateAlloc(Balloon *b, uint32 nAlloc)
+BalloonIncreaseRateAlloc(Balloon *b, // IN
+ uint32 nAlloc) // IN
{
if (BALLOON_RATE_ADAPT) {
if (nAlloc >= b->rateAlloc) {
*/
static int
-BalloonInflate(Balloon *b, uint32 target)
+BalloonInflate(Balloon *b, // IN
+ uint32 target) // IN
{
int status, allocations = 0;
uint32 i, nAllocNoSleep, nAllocCanSleep;
for (i = 0; i < nAllocNoSleep; i++) {
/* Try NOSLEEP allocation */
- status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_NOSLEEP);
+ status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_NOSLEEP);
if (status != BALLOON_SUCCESS) {
if (status != BALLOON_PAGE_ALLOC_FAILURE) {
/*
* Not a page allocation failure, so release non-balloonable
* pages, and fail.
*/
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(status);
}
/*
if (i == nAllocNoSleep) {
BalloonIncreaseRateAlloc(b, nAllocNoSleep);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
} else {
/*
if (i > b->rateAlloc) {
BalloonIncreaseRateAlloc(b, i);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
} else {
/* update successful NOSLEEP allocations, and proceed */
for (i = 0; i < nAllocCanSleep; i++) {
/* Try CANSLEEP allocation */
- status = Balloon_AllocPage(b, BALLOON_PAGE_ALLOC_CANSLEEP);
+ status = BalloonPageAlloc(b, BALLOON_PAGE_ALLOC_CANSLEEP);
if(status != BALLOON_SUCCESS) {
if (status == BALLOON_PAGE_ALLOC_FAILURE) {
/*
BalloonDecreaseRateAlloc(b);
}
/* release non-balloonable pages, fail */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(status);
}
BalloonIncreaseRateAlloc(b, nAllocNoSleep + nAllocCanSleep);
/* release non-balloonable pages, succeed */
- Balloon_ErrorPagesFree(b);
+ BalloonErrorPagesFree(b);
return(BALLOON_SUCCESS);
}
*/
static int
-BalloonDeflate(Balloon *b, uint32 target)
+BalloonDeflate(Balloon *b, // IN
+ uint32 target) // IN
{
int status, i;
uint32 nFree = b->nPages - target;
/* free pages to reach target */
for (i = 0; i < nFree; i++) {
- if ((status = Balloon_FreePage(b, TRUE)) != BALLOON_SUCCESS) {
+ status = BalloonPageFree(b, TRUE);
+ if (status != BALLOON_SUCCESS) {
if (BALLOON_RATE_ADAPT) {
/* quickly decrease rate if error */
b->rateFree = MAX(b->rateFree / 2, BALLOON_RATE_FREE_MIN);
/*
*----------------------------------------------------------------------
*
- * Balloon_AdjustSize --
+ * BalloonAdjustSize --
*
* Attempts to allocate or deallocate physical pages in order
* to reach desired "target" size for balloon "b".
*/
static int
-Balloon_AdjustSize(Balloon *b, uint32 target)
+BalloonAdjustSize(Balloon *b, // IN
+ uint32 target) // IN
{
/* done if already at target */
if (b->nPages == target) {
return(BALLOON_FAILURE);
}
-/*
- * Backdoor Operations
- */
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorStart --
+ * BalloonMonitorStart --
*
* Attempts to contact monitor via backdoor to begin operation.
*
*/
static int
-Balloon_MonitorStart(Balloon *b)
+BalloonMonitorStart(Balloon *b) // IN
{
uint32 status, target;
Backdoor_proto bp;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorGuestType --
+ * BalloonMonitorGuestType --
*
* Attempts to contact monitor and report guest OS identity.
*
*/
static int
-Balloon_MonitorGuestType(Balloon *b)
+BalloonMonitorGuestType(Balloon *b) // IN
{
uint32 status, target;
BalloonGuest identity;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorGetTarget --
+ * BalloonMonitorGetTarget --
*
* Attempts to contact monitor via backdoor to obtain desired
* balloon size.
*/
static int
-Balloon_MonitorGetTarget(Balloon *b, // IN
+BalloonMonitorGetTarget(Balloon *b, // IN
uint32 *target) // OUT
{
Backdoor_proto bp;
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorLockPage --
+ * BalloonMonitorLockPage --
*
* Attempts to contact monitor and add PPN corresponding to
* the page handle to set of "balloon locked" pages.
*/
static int
-Balloon_MonitorLockPage(Balloon *b, // IN
+BalloonMonitorLockPage(Balloon *b, // IN
PageHandle handle) // IN
{
unsigned long ppn;
return status;
}
+
/*
*----------------------------------------------------------------------
*
- * Balloon_MonitorUnlockPage --
+ * BalloonMonitorUnlockPage --
*
* Attempts to contact monitor and remove PPN corresponding to
* the page handle from set of "balloon locked" pages.
*
*----------------------------------------------------------------------
*/
+
static int
-Balloon_MonitorUnlockPage(Balloon *b, // IN
+BalloonMonitorUnlockPage(Balloon *b, // IN
PageHandle handle) // IN
{
unsigned long ppn;
return BALLOON_SUCCESS;
}
+
/*
*----------------------------------------------------------------------
*
* Reset connection before deallocating memory to avoid potential for
* additional spurious resets from guest touching deallocated pages.
*/
- Balloon_MonitorStart(b);
+ BalloonMonitorStart(b);
Balloon_Deallocate(b);
/* os-specific cleanup */