qemu: reduce file padding requirements

Followup to https://bugzilla.redhat.com/show_bug.cgi?id=599091,
commit 20206a4b, to reduce disk waste in padding.

* src/qemu/qemu_monitor.h (QEMU_MONITOR_MIGRATE_TO_FILE_BS): Drop
back to 4k.
(QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE): New macro.
* src/qemu/qemu_driver.c (qemudDomainSaveFlag): Update comment.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextMigrateToFile): Use
two invocations of dd to output non-aligned large blocks.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMigrateToFile):
Likewise.
This commit is contained in:
Eric Blake 2010-06-09 20:23:51 -06:00
parent 51d3fb0276
commit 322b1fd44b
4 changed files with 30 additions and 19 deletions

View File

@ -5001,13 +5001,6 @@ static int qemudDomainSaveFlag(virDomainPtr dom, const char *path,
* we need to ensure there's a 512 byte boundary. Unfortunately * we need to ensure there's a 512 byte boundary. Unfortunately
* we don't have an explicit offset in the header, so we fake * we don't have an explicit offset in the header, so we fake
* it by padding the XML string with NULLs. * it by padding the XML string with NULLs.
*
* XXX: This means there will be (QEMU_MONITOR_MIGRATE_TO_FILE_BS
* - strlen(xml)) bytes of wastage in each file.
* Unfortunately, a large BS is needed for reasonable
* performance. It would be nice to find a replacement for dd
* that could specify the start offset in bytes rather than
* blocks, to eliminate this waste.
*/ */
if (offset % QEMU_MONITOR_MIGRATE_TO_FILE_BS) { if (offset % QEMU_MONITOR_MIGRATE_TO_FILE_BS) {
unsigned long long pad = unsigned long long pad =

View File

@ -1,7 +1,7 @@
/* /*
* qemu_monitor.h: interaction with QEMU monitor console * qemu_monitor.h: interaction with QEMU monitor console
* *
* Copyright (C) 2006-2009 Red Hat, Inc. * Copyright (C) 2006-2010 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange * Copyright (C) 2006 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -261,10 +261,16 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
unsigned int background, unsigned int background,
const char * const *argv); const char * const *argv);
/* In general, a larger BS means better domain save performance, /* In general, BS is the smallest fundamental block size we can use to
* at the expense of a larger resulting file - see qemu_driver.c * access a block device; everything must be aligned to a multiple of
* this. Linux generally supports a BS as small as 512, but with
* newer disks with 4k sectors, performance is better if we guarantee
* alignment to the sector size. However, operating on BS-sized
* blocks is painfully slow, so we also have a transfer size that is
* larger but only aligned to the smaller block size.
*/ */
# define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 1024) # define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4)
# define QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE (1024llu * 1024)
int qemuMonitorMigrateToFile(qemuMonitorPtr mon, int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
unsigned int background, unsigned int background,

View File

@ -1695,10 +1695,16 @@ int qemuMonitorJSONMigrateToFile(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (virAsprintf(&dest, "exec:%s | dd of=%s bs=%llu seek=%llu", /* Two dd processes, sharing the same stdout, are necessary to
argstr, safe_target, * allow starting at an alignment of 512, but without wasting
QEMU_MONITOR_MIGRATE_TO_FILE_BS, * padding to get to the larger alignment useful for speed. Use
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS) < 0) { * <> redirection to avoid truncating a regular file. */
if (virAsprintf(&dest, "exec:%s | { dd bs=%llu seek=%llu if=/dev/null && "
"dd bs=%llu; } 1<>%s",
argstr, QEMU_MONITOR_MIGRATE_TO_FILE_BS,
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS,
QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE,
safe_target) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }

View File

@ -1273,10 +1273,16 @@ int qemuMonitorTextMigrateToFile(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
if (virAsprintf(&dest, "exec:%s | dd of=%s bs=%llu seek=%llu", /* Two dd processes, sharing the same stdout, are necessary to
argstr, safe_target, * allow starting at an alignment of 512, but without wasting
QEMU_MONITOR_MIGRATE_TO_FILE_BS, * padding to get to the larger alignment useful for speed. Use
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS) < 0) { * <> redirection to avoid truncating a regular file. */
if (virAsprintf(&dest, "exec:%s | { dd bs=%llu seek=%llu if=/dev/null && "
"dd bs=%llu; } 1<>%s",
argstr, QEMU_MONITOR_MIGRATE_TO_FILE_BS,
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS,
QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE,
safe_target) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }