qemu-file: output data directly if possible
RFC PATCH 1/1 qemu-file: output data directly if possible
qemu file currently always buffers up data before writing it out. At least for memory this is probably not a good idea:
writing out to file would be cheaper. Let's do
that if we can, which should be the common case. If we can't, buffer.
---
Completely untested, this is just thinking aloud. Shouldn't the below save us a data copy in the common case, helping speed up migration?
Please comment.
qemu-file.c +10 -0
@@ -142,6 +142,16 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size)abort (); } +if (!f->has_error && size >0 && !f->buf_index) { +int len = f->put_buffer (f->opaque, buf,0 , size); +if (len >=0 ) { + size -= len; + buf += len; + }else { + f->has_error =1 ; + } + } +while (!f->has_error && size >0 ) { l =IO_BUF_SIZE - f->buf_index;if (l > size)
Quoted 5 lines · Michael S. Tsirkin
qemu file currently always buffers up data before writing it out. At least for memory this is probably not a good idea:
writing out to file would be cheaper. Let's do
that if we can, which should be the common case. If we can't, buffer.
Quoted 7 lines
Signed-off-by Michael S. Tsirkin<[email protected]>---
Completely untested, this is just thinking aloud. Shouldn't the below save us a data copy in the common case, helping speed up migration?
The problem here is qemu_put_byte and friends, where the indirection of a function call would probably slow things down. In the common case, qemu_put_byte is called a lot and f->buf_index would not be zero. The way to go would probably be to merge QEMUFile and QEMUBufferedFile's two buffering layers, which also removes a copy.
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Michael S. Tsirkin
qemu file currently always buffers up data before writing it out. At least for memory this is probably not a good idea:
writing out to file would be cheaper. Let's do
that if we can, which should be the common case. If we can't, buffer.Signed-off-by Michael S. Tsirkin<[email protected]>---
Quoted 8 lines
Quoted 3 lines
Completely untested, this is just thinking aloud. Shouldn't the below save us a data copy in the common case, helping speed up migration?
The problem here is
qemu_put_byteand friends, where the indirection of a function call would probably slow things down. In the common case,qemu_put_byteis called a lot andf->buf_indexwould not be zero.
True, maybe the right thing to do is use a size cutoff, avoid a copy if buffer is large enough.
I note the buffer in qemu file is 32K - is that based on some specific measurements or just
a random large number? Any objections to making it smaller, like 4K?
Quoted 4 lines
The way to go would probably be to merge QEMUFile and
QEMUBufferedFile's two buffering layers, which also removes a copy.Paolo
Yes, it does look sane. QEMUFile doesn't seem to ever be used without QEMUBufferedFile - is that true?
Signature · 1 line
MST
Quoted 2 lines · Michael S. Tsirkin
Yes, it does look sane. QEMUFile doesn't seem to ever be used without QEMUBufferedFile - is that true?
I think savevm does use it that way. With migration thread it will be much easier, because the migration thread can just block. I'd hold it off until Juan's patches are in and then I can rebase Umesh's patches for migration thread.
Paolo
Quoted 20 lines · Michael S. Tsirkin
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Michael S. Tsirkin
qemu file currently always buffers up data before writing it out. At least for memory this is probably not a good idea:
writing out to file would be cheaper. Let's do
that if we can, which should be the common case. If we can't, buffer.Signed-off-by Michael S. Tsirkin<[email protected]>---
Quoted 8 lines
Quoted 3 lines
Completely untested, this is just thinking aloud. Shouldn't the below save us a data copy in the common case, helping speed up migration?
The problem here is
qemu_put_byteand friends, where the indirection of a function call would probably slow things down. In the common case,qemu_put_byteis called a lot andf->buf_indexwould not be zero.
Quoted 6 lines
True, maybe the right thing to do is use a size cutoff, avoid a copy if buffer is large enough.
I note the buffer in qemu file is 32K - is that based on some specific measurements or just
a random large number? Any objections to making it smaller, like 4K?
We can't until we move to a thread or similar. Basically we have to be able to end a "section write", there is no way to stop in the midle of a section, we can only split on whole sections.
I think that for this, it should be easier to just make ram_save_live to bypass QEMUFile layering and just write directly to the fd (header is really small (between 4bytes and something less that 256 if we have bad luck).
Quoted 7 lines
Quoted 4 lines
The way to go would probably be to merge QEMUFile and
QEMUBufferedFile's two buffering layers, which also removes a copy.Paolo
Yes, it does look sane. QEMUFile doesn't seem to ever be used without QEMUBufferedFile - is that true?
As Paolo says, savevm uses QEMUFile directly. I think that the way to go is to make savevm to also use QEMUBufferedFile, and then do same trick to avoid the buffering. It is on my ToDo list, but there are 4-5 things before that.
Later, Juan.