/** * do_balloon(): Request VM to change its memory allocation */ int do_balloon(Monitor *mon, const QDict *params, MonitorCompletion cb, void *opaque) { int64_t target; int ret; if (kvm_enabled() && !kvm_has_sync_mmu()) { qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); return -1; } target = qdict_get_int(params, "value"); if (target <= 0) { qerror_report(QERR_INVALID_PARAMETER_VALUE, "target", "a size"); return -1; } ret = qemu_balloon(target); if (ret == 0) { qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); return -1; } cb(opaque, NULL); return 0; }
static void balloon_page(void *addr, int deflate) { #if defined(__linux__) if (!kvm_enabled() || kvm_has_sync_mmu()) qemu_madvise(addr, TARGET_PAGE_SIZE, deflate ? QEMU_MADV_WILLNEED : QEMU_MADV_DONTNEED); #endif }
static void balloon_page(void *addr, int deflate) { if (!qemu_balloon_is_inhibited() && (!kvm_enabled() || kvm_has_sync_mmu())) { qemu_madvise(addr, BALLOON_PAGE_SIZE, deflate ? QEMU_MADV_WILLNEED : QEMU_MADV_DONTNEED); } }
static bool have_balloon(Error **errp) { if (kvm_enabled() && !kvm_has_sync_mmu()) { error_set(errp, ERROR_CLASS_KVM_MISSING_CAP, "Using KVM without synchronous MMU, balloon unavailable"); return false; } if (!balloon_event_fn) { error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE, "No balloon device has been activated"); return false; } return true; }
void qmp_balloon(int64_t value, Error **errp) { if (kvm_enabled() && !kvm_has_sync_mmu()) { error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); return; } if (value <= 0) { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size"); return; } if (qemu_balloon(value) == 0) { error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon"); } }
/** * do_info_balloon(): Balloon information * * Make an asynchronous request for balloon info. When the request completes * a QDict will be returned according to the following specification: * * - "actual": current balloon value in bytes * The following fields may or may not be present: * - "mem_swapped_in": Amount of memory swapped in (bytes) * - "mem_swapped_out": Amount of memory swapped out (bytes) * - "major_page_faults": Number of major faults * - "minor_page_faults": Number of minor faults * - "free_mem": Total amount of free and unused memory (bytes) * - "total_mem": Total amount of available memory (bytes) * * Example: * * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, * "major_page_faults": 142, "minor_page_faults": 239245, * "free_mem": 1014185984, "total_mem": 1044668416 } */ int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) { int ret; if (kvm_enabled() && !kvm_has_sync_mmu()) { qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); return -1; } ret = qemu_balloon_status(cb, opaque); if (!ret) { qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); return -1; } return 0; }
BalloonInfo *qmp_query_balloon(Error **errp) { BalloonInfo *info; if (kvm_enabled() && !kvm_has_sync_mmu()) { error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); return NULL; } info = g_malloc0(sizeof(*info)); if (qemu_balloon_status(info) == 0) { error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon"); qapi_free_BalloonInfo(info); return NULL; } return info; }
int ram_load(QEMUFile *f, void *opaque, int version_id) { ram_addr_t addr; int flags; if (version_id != 3) { return -EINVAL; } do { addr = qemu_get_be64(f); flags = addr & ~TARGET_PAGE_MASK; addr &= TARGET_PAGE_MASK; if (flags & RAM_SAVE_FLAG_MEM_SIZE) { if (addr != last_ram_offset) { return -EINVAL; } } if (flags & RAM_SAVE_FLAG_COMPRESS) { uint8_t ch = qemu_get_byte(f); memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE); #ifndef _WIN32 if (ch == 0 && (!kvm_enabled() || kvm_has_sync_mmu())) { madvise(qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE, MADV_DONTNEED); } #endif } else if (flags & RAM_SAVE_FLAG_PAGE) { qemu_get_buffer(f, qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE); } if (qemu_file_has_error(f)) { return -EIO; } } while (!(flags & RAM_SAVE_FLAG_EOS)); return 0; }