From nobody Thu May 2 18:44:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532010618453141.6645647360873; Thu, 19 Jul 2018 07:30:18 -0700 (PDT) Received: from localhost ([::1]:43585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg9wb-0001Hz-F8 for importer@patchew.org; Thu, 19 Jul 2018 10:30:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fg9vJ-0000Ua-UB for qemu-devel@nongnu.org; Thu, 19 Jul 2018 10:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fg9vI-0000Pz-Dv for qemu-devel@nongnu.org; Thu, 19 Jul 2018 10:28:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47442 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fg9vE-0000O6-Pd; Thu, 19 Jul 2018 10:28:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61A6F8182D28; Thu, 19 Jul 2018 14:28:48 +0000 (UTC) Received: from localhost (ovpn-117-80.ams2.redhat.com [10.36.117.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17A862026D6B; Thu, 19 Jul 2018 14:28:47 +0000 (UTC) From: Stefan Hajnoczi To: Date: Thu, 19 Jul 2018 15:28:43 +0100 Message-Id: <20180719142843.30230-2-stefanha@redhat.com> In-Reply-To: <20180719142843.30230-1-stefanha@redhat.com> References: <20180719142843.30230-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 14:28:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 14:28:48 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL for-v3.0 1/1] throttle-groups: fix hang when group member leaves X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Throttle groups consist of members sharing one throttling state (including bps/iops limits). Round-robin scheduling is used to ensure fairness. If a group member already has a timer pending then other groups members do not schedule their own timers. The next group member will have its turn when the existing timer expires. A hang may occur when a group member leaves while it had a timer scheduled. Although the code carefully removes the group member from the round-robin list, it does not schedule the next member. Therefore remaining members continue to wait for the removed member's timer to expire. This patch schedules the next request if a timer is pending. Unfortunately the actual bug is a race condition that I've been unable to capture in a test case. Sometimes drive2 hangs when drive1 is removed from the throttling group: $ qemu ... -drive if=3Dnone,id=3Ddrive1,cache=3Dnone,format=3Dqcow2,file= =3Ddata1.qcow2,iops=3D100,group=3Dfoo \ -device virtio-blk-pci,id=3Dvirtio-blk-pci0,drive=3Ddrive1 \ -drive if=3Dnone,id=3Ddrive2,cache=3Dnone,format=3Dqcow2,file= =3Ddata2.qcow2,iops=3D10,group=3Dfoo \ -device virtio-blk-pci,id=3Dvirtio-blk-pci1,drive=3Ddrive2 (guest-console1)# fio -filename /dev/vda 4k-seq-read.job (guest-console2)# fio -filename /dev/vdb 4k-seq-read.job (qmp) {"execute": "block_set_io_throttle", "arguments": {"device": "drive= 1","bps": 0,"bps_rd": 0,"bps_wr": 0,"iops": 0,"iops_rd": 0,"iops_wr": 0}} Reported-by: Nini Gu Signed-off-by: Stefan Hajnoczi Message-id: 20180704145410.794-1-stefanha@redhat.com RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D1535914 Cc: Alberto Garcia Signed-off-by: Stefan Hajnoczi --- block/throttle-groups.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 36cc0430c3..e297b04e17 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -564,6 +564,10 @@ void throttle_group_unregister_tgm(ThrottleGroupMember= *tgm) =20 qemu_mutex_lock(&tg->lock); for (i =3D 0; i < 2; i++) { + if (timer_pending(tgm->throttle_timers.timers[i])) { + tg->any_timer_armed[i] =3D false; + schedule_next_request(tgm, i); + } if (tg->tokens[i] =3D=3D tgm) { token =3D throttle_group_next_tgm(tgm); /* Take care of the case where this is the last tgm in the gro= up */ --=20 2.17.1