The aio_copy example checks errors properly, so it will not leak
uninitialized memory to the destination image. Testing shows 5% speedup
when copying a real image.
$ qemu-nbd --read-only --persistent --shared 8 --cache none --aio native \
--socket /tmp/src.sock --format raw fedora-35-data.raw &
$ hyperfine -p "sleep 5" "./aio_copy-init $SRC >/dev/null"
"./aio_copy-no-init $SRC >/dev/null"
Benchmark 1: ./aio_copy-init nbd+unix:///?socket=/tmp/src.sock >/dev/null
Time (mean ± σ): 1.452 s ± 0.027 s [User: 0.330 s, System: 0.489 s]
Range (min … max): 1.426 s … 1.506 s 10 runs
Benchmark 2: ./aio_copy-no-init nbd+unix:///?socket=/tmp/src.sock >/dev/null
Time (mean ± σ): 1.378 s ± 0.009 s [User: 0.202 s, System: 0.484 s]
Range (min … max): 1.369 s … 1.399 s 10 runs
Summary
'./aio_copy-no-init nbd+unix:///?socket=/tmp/src.sock >/dev/null' ran
1.05 ± 0.02 times faster than './aio_copy-init nbd+unix:///?socket=/tmp/src.sock
>/dev/null'
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
golang/examples/aio_copy/aio_copy.go | 5 +++++
golang/examples/simple_copy/simple_copy.go | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/golang/examples/aio_copy/aio_copy.go b/golang/examples/aio_copy/aio_copy.go
index bb20b478..89eac4df 100644
--- a/golang/examples/aio_copy/aio_copy.go
+++ b/golang/examples/aio_copy/aio_copy.go
@@ -84,20 +84,25 @@ func main() {
err = h.ConnectUri(flag.Arg(0))
if err != nil {
panic(err)
}
size, err := h.GetSize()
if err != nil {
panic(err)
}
+ err = h.SetPreadInitialize(false)
+ if err != nil {
+ panic(err)
+ }
+
var offset uint64
for offset < size || queue.Len() > 0 {
for offset < size && inflightRequests() < *requests {
length := *requestSize
if size-offset < uint64(length) {
length = uint(size - offset)
}
startRead(offset, length)
diff --git a/golang/examples/simple_copy/simple_copy.go
b/golang/examples/simple_copy/simple_copy.go
index e8fa1f76..2a2ed0ff 100644
--- a/golang/examples/simple_copy/simple_copy.go
+++ b/golang/examples/simple_copy/simple_copy.go
@@ -63,20 +63,25 @@ func main() {
err = h.ConnectUri(flag.Arg(0))
if err != nil {
panic(err)
}
size, err := h.GetSize()
if err != nil {
panic(err)
}
+ err = h.SetPreadInitialize(false)
+ if err != nil {
+ panic(err)
+ }
+
buf := make([]byte, *requestSize)
var offset uint64
for offset < size {
if size-offset < uint64(len(buf)) {
buf = buf[:offset-size]
}
err = h.Pread(buf, offset, nil)
if err != nil {
--
2.35.1