From: luzhipeng <luzhipeng@cestc.cn>
To: qemu-block@nongnu.org
Cc: Alberto Garcia <berto@igalia.com>, Kevin Wolf <kwolf@redhat.com>,
Hanna Reitz <hreitz@redhat.com>,
qemu-devel@nongnu.org, luzhipeng <luzhipeng@cestc.cn>
Subject: [PATCH] mirror: Optimize mirroring for zero blocks in mirror_read_complete
Date: Fri, 14 Nov 2025 10:11:10 +0800 [thread overview]
Message-ID: <20251114021110.1464-2-luzhipeng@cestc.cn> (raw)
In-Reply-To: <20251114021110.1464-1-luzhipeng@cestc.cn>
When mirroring data blocks, detect if the read data consists entirely of
zeros. If so, use blk_co_pwrite_zeroes() instead of regular write to
improve performance.
Signed-off-by: luzhipeng <luzhipeng@cestc.cn>
---
block/mirror.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/block/mirror.c b/block/mirror.c
index b344182c74..535112f65d 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -269,6 +269,33 @@ static void coroutine_fn mirror_read_complete(MirrorOp *op, int ret)
return;
}
+ /* Check if the read data is all zeros */
+ bool is_zero = true;
+ for (int i = 0; i < op->qiov.niov; i++) {
+ if (!buffer_is_zero(op->qiov.iov[i].iov_base,
+ op->qiov.iov[i].iov_len)) {
+ is_zero = false;
+ break;
+ }
+ }
+
+ /* Write to target - optimized path for zero blocks */
+ if (is_zero) {
+ /*
+ * Use zero-writing interface which may:
+ * 1. Avoid actual data transfer
+ * 2. Enable storage-level optimizations
+ * 3. Potentially unmap blocks (if supported)
+ */
+ ret = blk_co_pwrite_zeroes(s->target, op->offset,
+ op->qiov.size,
+ BDRV_REQ_MAY_UNMAP);
+ } else {
+ /* Normal data write path */
+ ret = blk_co_pwritev(s->target, op->offset,
+ op->qiov.size, &op->qiov, 0);
+ }
+
ret = blk_co_pwritev(s->target, op->offset, op->qiov.size, &op->qiov, 0);
mirror_write_complete(op, ret);
}
--
2.45.1.windows.1
next prev parent reply other threads:[~2025-11-14 2:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 2:11 [PATCH] block: add single-check guard in throttle_group_restart_queue to address race with schedule_next_request luzhipeng
2025-11-14 2:11 ` luzhipeng [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-09-22 11:36 [PATCH] mirror: Optimize mirroring for zero blocks in mirror_read_complete luzhipeng
2025-09-22 11:36 ` luzhipeng
2025-09-22 12:53 ` Eric Blake
2025-11-17 17:35 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114021110.1464-2-luzhipeng@cestc.cn \
--to=luzhipeng@cestc.cn \
--cc=berto@igalia.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).