From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGmo1-0004vH-B8 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 05:58:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGmnx-0007SO-AQ for qemu-devel@nongnu.org; Thu, 29 Jan 2015 05:58:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36063) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGmnx-0007SI-3X for qemu-devel@nongnu.org; Thu, 29 Jan 2015 05:58:33 -0500 Message-ID: <54CA1255.7010102@redhat.com> Date: Thu, 29 Jan 2015 11:58:29 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1422528659-3121-1-git-send-email-den@openvz.org> <1422528659-3121-2-git-send-email-den@openvz.org> In-Reply-To: <1422528659-3121-2-git-send-email-den@openvz.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/1] block: enforce minimal 4096 alignment in qemu_blockalign List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Denis V. Lunev" Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi On 29/01/2015 11:50, Denis V. Lunev wrote: > The following sequence > int fd = open(argv[1], O_RDWR | O_CREAT | O_DIRECT, 0644); > for (i = 0; i < 100000; i++) > write(fd, buf, 4096); > performs 5% better if buf is aligned to 4096 bytes rather then to > 512 bytes on HDD with 512/4096 logical/physical sector size. > > The difference is quite reliable. > > On the other hand we do not want at the moment to enforce bounce > buffering if guest request is aligned to 512 bytes. This patch > forces page alignment when we really forced to perform memory > allocation. > > Signed-off-by: Denis V. Lunev > CC: Paolo Bonzini > CC: Kevin Wolf > CC: Stefan Hajnoczi > --- > block.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/block.c b/block.c > index d45e4dd..38cf73f 100644 > --- a/block.c > +++ b/block.c > @@ -5293,7 +5293,11 @@ void bdrv_set_guest_block_size(BlockDriverState *bs, int align) > > void *qemu_blockalign(BlockDriverState *bs, size_t size) > { > - return qemu_memalign(bdrv_opt_mem_align(bs), size); > + size_t align = bdrv_opt_mem_align(bs); > + if (align < 4096) { > + align = 4096; > + } > + return qemu_memalign(align, size); > } > > void *qemu_blockalign0(BlockDriverState *bs, size_t size) > @@ -5307,6 +5311,9 @@ void *qemu_try_blockalign(BlockDriverState *bs, size_t size) > > /* Ensure that NULL is never returned on success */ > assert(align > 0); > + if (align < 4096) { > + align = 4096; > + } > if (size == 0) { > size = align; > } > Reviewed-by: Paolo Bonzini