All of lore.kernel.org
 help / color / mirror / Atom feed
* Avoid copying unallocated clusters during full backup
@ 2020-04-17 18:33 Leo Luan
  2020-04-17 20:11 ` John Snow
  0 siblings, 1 reply; 11+ messages in thread
From: Leo Luan @ 2020-04-17 18:33 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2442 bytes --]

When doing a full backup from a single layer qcow2 disk file to a new qcow2
file, the backup_run function does not unset unallocated parts in the copy
bit map.  The subsequent backup_loop call goes through these unallocated
clusters unnecessarily.  In the case when the target and source reside in
different file systems, an EXDEV error would cause zeroes to be actually
copied into the target and that causes a target file size explosion to the
full virtual disk size.

This patch aims to unset the unallocated parts in the copy bitmap when it
is safe to do so, thereby avoid dealing with unallocated clusters in the
backup loop to prevent significant performance or storage efficiency
impacts when running full backup jobs.

Any insights or corrections?

diff --git a/block/backup.c b/block/backup.c
index cf62b1a38c..609d551b1e 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -139,6 +139,29 @@ static void backup_clean(Job *job)
     bdrv_backup_top_drop(s->backup_top);
 }

+static bool backup_ok_to_skip_unallocated(BackupBlockJob *s)
+{
+    /* Checks whether this backup job can avoid copying or dealing with
+       unallocated clusters in the backup loop and their associated
+       performance and storage effciency impacts. Check for the condition
+       when it's safe to skip copying unallocated clusters that allows the
+       corresponding bits in the copy bitmap to be unset.  The assumption
+       here is that it is ok to do so when we are doing a full backup,
+       the target file is a qcow2, and the source is single layer.
+       Do we need to add additional checks (so that it does not break
+       something) or add addtional conditions to optimize additional use
+       cases?
+     */
+
+    if (s->sync_mode == MIRROR_SYNC_MODE_FULL &&
+       s->bcs->target->bs->drv != NULL &&
+       strncmp(s->bcs->target->bs->drv->format_name, "qcow2", 5) == 0 &&
+       s->bcs->source->bs->backing_file[0] == '\0')
+       return true;
+    else
+        return false;
+}
+
 void backup_do_checkpoint(BlockJob *job, Error **errp)
 {
     BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
@@ -248,7 +271,7 @@ static int coroutine_fn backup_run(Job *job, Error
**errp)

     backup_init_copy_bitmap(s);

-    if (s->sync_mode == MIRROR_SYNC_MODE_TOP) {
+    if (s->sync_mode == MIRROR_SYNC_MODE_TOP ||
backup_ok_to_skip_unallocated(s)) {
         int64_t offset = 0;
         int64_t count;

[-- Attachment #2: Type: text/html, Size: 2853 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-04-21 14:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17 18:33 Avoid copying unallocated clusters during full backup Leo Luan
2020-04-17 20:11 ` John Snow
2020-04-17 20:24   ` Eric Blake
2020-04-17 22:57     ` Leo Luan
2020-04-18  0:34       ` John Snow
2020-04-18  1:43         ` Leo Luan
2020-04-20 10:56           ` Vladimir Sementsov-Ogievskiy
2020-04-20 14:31             ` Bryan S Rosenburg
2020-04-20 15:04               ` Vladimir Sementsov-Ogievskiy
2020-04-21 14:41                 ` Bryan S Rosenburg
2020-04-17 22:31   ` Leo Luan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.