From patchwork Tue May 12 14:30:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 471365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CED6E140D18 for ; Wed, 13 May 2015 00:31:12 +1000 (AEST) Received: from localhost ([::1]:43381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsBDD-00035y-10 for incoming@patchwork.ozlabs.org; Tue, 12 May 2015 10:31:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsBCf-0002HW-Bf for qemu-devel@nongnu.org; Tue, 12 May 2015 10:30:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YsBCa-0008LK-Jo for qemu-devel@nongnu.org; Tue, 12 May 2015 10:30:36 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:15036 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsBCM-0008Gt-76; Tue, 12 May 2015 10:30:18 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t4CEUDhD031741; Tue, 12 May 2015 17:30:16 +0300 (MSK) From: "Denis V. Lunev" To: Date: Tue, 12 May 2015 17:30:55 +0300 Message-Id: <1431441056-26198-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431441056-26198-1-git-send-email-den@openvz.org> References: <1431441056-26198-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: "Denis V. Lunev" , Stefan Hajnoczi , qemu-devel@nongnu.org, qemu-block@nongnu.org, Paolo Bonzini Subject: [Qemu-devel] [PATCH 1/2] block: minimal bounce buffer alignment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The patch introduces new concept: minimal memory alignment for bounce buffers. Original so called "optimal" value is actually minimal required value for aligment. It should be used for validation that the IOVec is properly aligned and bounce buffer is not required. Though, from the performance point of view, it would be better if bounce buffer or IOVec allocated by QEMU will be aligned stricter. The patch does not change any alignment value yet. Signed-off-by: Denis V. Lunev CC: Paolo Bonzini Reviewed-by: Kevin Wolf CC: Stefan Hajnoczi --- block.c | 11 +++++++++++ block/io.c | 7 ++++++- block/raw-posix.c | 1 + include/block/block.h | 2 ++ include/block/block_int.h | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 7904098..e293907 100644 --- a/block.c +++ b/block.c @@ -113,6 +113,16 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs) return bs->bl.opt_mem_alignment; } +size_t bdrv_min_mem_align(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + /* 4k should be on the safe side */ + return 4096; + } + + return bs->bl.min_mem_alignment; +} + /* check if the path starts with ":" */ int path_has_protocol(const char *path) { @@ -890,6 +900,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, } assert(bdrv_opt_mem_align(bs) != 0); + assert(bdrv_min_mem_align(bs) != 0); assert((bs->request_alignment != 0) || bs->sg); return 0; diff --git a/block/io.c b/block/io.c index 1ce62c4..908a3d1 100644 --- a/block/io.c +++ b/block/io.c @@ -201,8 +201,10 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) } bs->bl.opt_transfer_length = bs->file->bl.opt_transfer_length; bs->bl.max_transfer_length = bs->file->bl.max_transfer_length; + bs->bl.min_mem_alignment = bs->file->bl.min_mem_alignment; bs->bl.opt_mem_alignment = bs->file->bl.opt_mem_alignment; } else { + bs->bl.min_mem_alignment = 512; bs->bl.opt_mem_alignment = 512; } @@ -221,6 +223,9 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.opt_mem_alignment = MAX(bs->bl.opt_mem_alignment, bs->backing_hd->bl.opt_mem_alignment); + bs->bl.min_mem_alignment = + MAX(bs->bl.min_mem_alignment, + bs->backing_hd->bl.min_mem_alignment); } /* Then let the driver override it */ @@ -2489,7 +2494,7 @@ void *qemu_try_blockalign0(BlockDriverState *bs, size_t size) bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov) { int i; - size_t alignment = bdrv_opt_mem_align(bs); + size_t alignment = bdrv_min_mem_align(bs); for (i = 0; i < qiov->niov; i++) { if ((uintptr_t) qiov->iov[i].iov_base % alignment) { diff --git a/block/raw-posix.c b/block/raw-posix.c index 24d8582..7083924 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -725,6 +725,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) BDRVRawState *s = bs->opaque; raw_probe_alignment(bs, s->fd, errp); + bs->bl.min_mem_alignment = s->buf_align; bs->bl.opt_mem_alignment = s->buf_align; } diff --git a/include/block/block.h b/include/block/block.h index 7d1a717..c1c963e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -440,6 +440,8 @@ void bdrv_img_create(const char *filename, const char *fmt, /* Returns the alignment in bytes that is required so that no bounce buffer * is required throughout the stack */ +size_t bdrv_min_mem_align(BlockDriverState *bs); +/* Returns optimal alignment in bytes for bounce buffer */ size_t bdrv_opt_mem_align(BlockDriverState *bs); void bdrv_set_guest_block_size(BlockDriverState *bs, int align); void *qemu_blockalign(BlockDriverState *bs, size_t size); diff --git a/include/block/block_int.h b/include/block/block_int.h index db29b74..f004378 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -313,6 +313,9 @@ typedef struct BlockLimits { int max_transfer_length; /* memory alignment so that no bounce buffer is needed */ + size_t min_mem_alignment; + + /* memory alignment for bounce buffer */ size_t opt_mem_alignment; } BlockLimits;