Received: from eggs.gnu.org ([2001:4830:134:3::10]:49584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHZcQ-0001K6-AK for qemu-devel@nongnu.org; Mon, 27 Jun 2016 12:42:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHZcM-0007qI-B6 for qemu-devel@nongnu.org; Mon, 27 Jun 2016 12:42:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHZcM-0007q6-5A for qemu-devel@nongnu.org; Mon, 27 Jun 2016 12:42:38 -0400 References: <1467045468-25709-1-git-send-email-stefanha@redhat.com> From: Paolo Bonzini Message-ID: <613d34ba-87fc-7b52-5bb6-567cc845430e@redhat.com> Date: Mon, 27 Jun 2016 18:42:33 +0200 MIME-Version: 1.0 In-Reply-To: <1467045468-25709-1-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] linux-aio: keep processing events if MAX_EVENTS reached List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , roman.penyaev@profitbricks.com On 27/06/2016 18:37, Stefan Hajnoczi wrote: > Commit ccb9dc10129954d0bcd7814298ed445e684d5a2a ("linux-aio: Cancel BH > if not needed") exposed a side-effect of scheduling the BH for nested > event loops. When io_getevents(2) fetches MAX_EVENTS events then it's > necessary to call it again. Failure to do so can lead to hung I/O > because the eventfd has already been cleared and the completion BH will > not run again. > > This patch fixes the hang by calling io_getevents(2) again if the events > array was totally full. > > Reported-by: Roman Penyaev > Signed-off-by: Stefan Hajnoczi > --- > block/linux-aio.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/block/linux-aio.c b/block/linux-aio.c > index e468960..af15f85 100644 > --- a/block/linux-aio.c > +++ b/block/linux-aio.c > @@ -117,6 +117,7 @@ static void qemu_laio_completion_bh(void *opaque) > LinuxAioState *s = opaque; > > /* Fetch more completion events when empty */ > +more_events: > if (s->event_idx == s->event_max) { > do { > struct timespec ts = { 0 }; > @@ -146,6 +147,10 @@ static void qemu_laio_completion_bh(void *opaque) > qemu_laio_process_completion(laiocb); > } > > + if (s->event_idx == MAX_EVENTS) { > + goto more_events; /* there might still be events waiting for us */ > + } > + > if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { > ioq_submit(s); > } > Do we want to do it after submitting, in order to reduce latency and perhaps even get some results immediately? Paolo