From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:38184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RCzT6-0003f2-3a for qemu-devel@nongnu.org; Sun, 09 Oct 2011 15:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RCzT4-0005HO-Sr for qemu-devel@nongnu.org; Sun, 09 Oct 2011 15:55:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53013) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RCzT4-0005H9-I7 for qemu-devel@nongnu.org; Sun, 09 Oct 2011 15:55:26 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p99JtPkq002333 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 9 Oct 2011 15:55:25 -0400 Received: from redhat.com (vpn-200-152.tlv.redhat.com [10.35.200.152]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id p99JtMc6005499 for ; Sun, 9 Oct 2011 15:55:23 -0400 Date: Sun, 9 Oct 2011 21:56:29 -0200 From: "Michael S. Tsirkin" Message-ID: <20111009235629.GB9542@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH RFC] qemu-file: output data directly if possible List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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. diff --git a/qemu-file.c b/qemu-file.c index 761f2a9..6d30151 100644 --- a/qemu-file.c +++ b/qemu-file.c @@ -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)