From patchwork Wed Dec 10 14:52:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 419689 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 098B01400D5 for ; Thu, 11 Dec 2014 01:54:54 +1100 (AEDT) Received: from localhost ([::1]:46066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyifE-0002Bw-BO for incoming@patchwork.ozlabs.org; Wed, 10 Dec 2014 09:54:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyid9-0007N9-1X for qemu-devel@nongnu.org; Wed, 10 Dec 2014 09:52:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xyicw-00012g-DG for qemu-devel@nongnu.org; Wed, 10 Dec 2014 09:52:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyicn-0000xb-HM for qemu-devel@nongnu.org; Wed, 10 Dec 2014 09:52:30 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBAEqDtD030922 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 10 Dec 2014 09:52:14 -0500 Received: from donizetti.redhat.com (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBAEq3wN007388; Wed, 10 Dec 2014 09:52:10 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 10 Dec 2014 15:52:00 +0100 Message-Id: <1418223122-22481-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1418223122-22481-1-git-send-email-pbonzini@redhat.com> References: <1418223122-22481-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, ming.lei@canonical.com, pl@kamp.de, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 2/4] linux-aio: track whether the queue is blocked 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 Do not try submitting requests when io_submit reported that it couldn't accept more; dually, try more io_submit calls if it could handle the whole set of requests that were passed, so that the "blocked" flag is reset as soon as possible. This also fixes a hack in the previous patch, where s->io_q.idx was compared with "==" in order to avoid repeated submissions. It makes it more sense to compare with ">=", so do that now that we have the "blocked" flag. Signed-off-by: Paolo Bonzini --- block/linux-aio.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/block/linux-aio.c b/block/linux-aio.c index b6fbfd8..b870942 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -41,6 +41,7 @@ struct qemu_laiocb { typedef struct { int plugged; unsigned int idx; + bool blocked; QSIMPLEQ_HEAD(, qemu_laiocb) pending; } LaioQueue; @@ -180,34 +181,39 @@ static void ioq_init(LaioQueue *io_q) QSIMPLEQ_INIT(&io_q->pending); io_q->plugged = 0; io_q->idx = 0; + io_q->blocked = false; } static int ioq_submit(struct qemu_laio_state *s) { - int ret, i; - int len = 0; + int ret, i, len; struct qemu_laiocb *aiocb; struct iocb *iocbs[MAX_QUEUED_IO]; - QSIMPLEQ_FOREACH(aiocb, &s->io_q.pending, next) { - iocbs[len++] = &aiocb->iocb; - if (len == MAX_QUEUED_IO) { - break; + do { + len = 0; + QSIMPLEQ_FOREACH(aiocb, &s->io_q.pending, next) { + iocbs[len++] = &aiocb->iocb; + if (len == MAX_QUEUED_IO) { + break; + } } - } - ret = io_submit(s->ctx, len, iocbs); - if (ret == -EAGAIN) { - ret = 0; - } - if (ret < 0) { - abort(); - } + ret = io_submit(s->ctx, len, iocbs); + if (ret == -EAGAIN) { + ret = 0; + } + if (ret < 0) { + abort(); + } + + for (i = 0; i < ret; i++) { + s->io_q.idx--; + QSIMPLEQ_REMOVE_HEAD(&s->io_q.pending, next); + } + } while (ret == len && !QSIMPLEQ_EMPTY(&s->io_q.pending)); + s->io_q.blocked = (s->io_q.idx > 0); - for (i = 0; i < ret; i++) { - s->io_q.idx--; - QSIMPLEQ_REMOVE_HEAD(&s->io_q.pending, next); - } return ret; } @@ -229,7 +235,7 @@ int laio_io_unplug(BlockDriverState *bs, void *aio_ctx, bool unplug) return 0; } - if (!QSIMPLEQ_EMPTY(&s->io_q.pending)) { + if (!s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { ret = ioq_submit(s); } @@ -271,7 +277,8 @@ BlockAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd, QSIMPLEQ_INSERT_TAIL(&s->io_q.pending, laiocb, next); s->io_q.idx++; - if (s->io_q.idx == (s->io_q.plugged ? MAX_QUEUED_IO : 1)) { + if (!s->io_q.blocked && + (!s->io_q.plugged || s->io_q.idx >= MAX_QUEUED_IO)) { ioq_submit(s); } return &laiocb->common;