From patchwork Fri Mar 7 08:03:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 327826 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 AA38A2C0081 for ; Fri, 7 Mar 2014 19:04:56 +1100 (EST) Received: from localhost ([::1]:35038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLpm2-0004bC-EN for incoming@patchwork.ozlabs.org; Fri, 07 Mar 2014 03:04:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLplg-0004ZL-ID for qemu-devel@nongnu.org; Fri, 07 Mar 2014 03:04:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLpla-0001UU-RN for qemu-devel@nongnu.org; Fri, 07 Mar 2014 03:04:32 -0500 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:58561 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLpla-0001UQ-Gf for qemu-devel@nongnu.org; Fri, 07 Mar 2014 03:04:26 -0500 Received: (qmail 12364 invoked by uid 89); 7 Mar 2014 08:04:25 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98.1/18542. hbedv: 8.2.14.18/7.11.135.64. spamassassin: 3.3.1. Clear:RC:1(82.141.1.145):SA:0(-1.5/4.0):. Processed in 1.292039 secs); 07 Mar 2014 08:04:25 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 7 Mar 2014 08:04:24 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 57D8120695; Fri, 7 Mar 2014 09:03:54 +0100 (CET) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id 4D91A611C5; Fri, 7 Mar 2014 09:03:54 +0100 (CET) From: Peter Lieven To: qemu-devel@nongnu.org Date: Fri, 7 Mar 2014 09:03:51 +0100 Message-Id: <1394179431-14474-1-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven , stefanha@redhat.com Subject: [Qemu-devel] [PATCH RESEND] block: introduce BDRV_O_SEQUENTIAL 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 this patch introduces a new flag to indicate that we are going to sequentially read from a file and do not plan to reread/reuse the data after it has been read. The current use of this flag is to open the source(s) of a qemu-img convert process. If a protocol from block/raw-posix.c is used posix_fadvise is utilized to advise to the kernel that we are going to read sequentially from the file and a POSIX_FADV_DONTNEED advise is issued after each write to indicate that there is no advantage keeping the blocks in the buffers. While the first seems to offer a slight performance benefit the latter option avoids that older data is swapped out to have the data unnecessarily buffered. Signed-off-by: Peter Lieven --- block/raw-posix.c | 14 ++++++++++++++ include/block/block.h | 1 + qemu-img.c | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 161ea14..fa6d9d2 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -433,6 +433,13 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, } #endif +#ifdef POSIX_FADV_SEQUENTIAL + if (bs->open_flags & BDRV_O_SEQUENTIAL && + !(bs->open_flags & BDRV_O_NOCACHE)) { + posix_fadvise(s->fd, 0, 0, POSIX_FADV_SEQUENTIAL); + } +#endif + ret = 0; fail: qemu_opts_del(opts); @@ -902,6 +909,13 @@ static int aio_worker(void *arg) ret = aiocb->aio_nbytes; } if (ret == aiocb->aio_nbytes) { +#ifdef POSIX_FADV_DONTNEED + if (aiocb->bs->open_flags & BDRV_O_SEQUENTIAL && + !(aiocb->bs->open_flags & BDRV_O_NOCACHE)) { + posix_fadvise(aiocb->aio_fildes, aiocb->aio_offset, + aiocb->aio_nbytes, POSIX_FADV_DONTNEED); + } +#endif ret = 0; } else if (ret >= 0 && ret < aiocb->aio_nbytes) { ret = -EINVAL; diff --git a/include/block/block.h b/include/block/block.h index 780f48b..502982f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -105,6 +105,7 @@ typedef enum { #define BDRV_O_PROTOCOL 0x8000 /* if no block driver is explicitly given: select an appropriate protocol driver, ignoring the format layer */ +#define BDRV_O_SEQUENTIAL 0x10000 /* open device for sequential read/write */ #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH) diff --git a/qemu-img.c b/qemu-img.c index 78fc868..e7a5721 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1298,7 +1298,8 @@ static int img_convert(int argc, char **argv) total_sectors = 0; for (bs_i = 0; bs_i < bs_n; bs_i++) { - bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS, true, + bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, + BDRV_O_FLAGS | BDRV_O_SEQUENTIAL, true, quiet); if (!bs[bs_i]) { error_report("Could not open '%s'", argv[optind + bs_i]);