From nobody Sun Feb 8 14:52:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606327492; cv=none; d=zohomail.com; s=zohoarc; b=K+EcJc4ypNU4RCHH/iae0pIsC22w0IwjCXHZ9tVPgpN6n5eP7WO7M7m7bg1n/viSp6ru2gHZkGBqSg4jl+wFPy1d2kiIb40LZcO8KIgvi9767kOdpI3F26K+kGa1OAu7QlFilPzfHXVONgS4t8n/kB3W77KZqBuFymCblVXnbBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606327492; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=x0MBA8bOzXVWCmryJ64yGrpF4oAKLW1TqbxQIrzFJmw=; b=A2itUx5eTqZV6uh8ipvzftYEPw1hKPBp+karJWtjg9o8xT4LWc0zXr7CA+bub8RCVbhDSIJwNOR344bFtkg6P1XoubVZsuEnl+elbpUaMRM7M7RpFXKryVk5w+xL1LJK0pyoqa881DmkiEcJRILY3i6/d/0ibj1OAzoXBYC4xxM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606327492772980.43378111289; Wed, 25 Nov 2020 10:04:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-13-z5xQmfKJP5OLEGNUSsT-yw-1; Wed, 25 Nov 2020 13:04:46 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 788A884A5E6; Wed, 25 Nov 2020 18:04:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52BAC19C48; Wed, 25 Nov 2020 18:04:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1F35A4EE0B; Wed, 25 Nov 2020 18:04:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0API4b2i017726 for ; Wed, 25 Nov 2020 13:04:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1353060864; Wed, 25 Nov 2020 18:04:37 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (gx270-2.gsslab.fab.redhat.com [10.33.8.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53F0560854; Wed, 25 Nov 2020 18:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606327490; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=x0MBA8bOzXVWCmryJ64yGrpF4oAKLW1TqbxQIrzFJmw=; b=Ix2ddu1VKWLITF/MRaoMQDeEZRqJwCfSpi4ayTfHJYrFY8NRU1UO2lWHOreQLenuRR0IKR +5YvRVTG44JYlJ0J5XpupWi8L8ErJGtv7CWEA+4++/9v26MJgZ7JWD62b3nSuWNb/tbVwu ShWdVoSFxyc2iH3QQJCSt/tvxXomRiA= X-MC-Unique: z5xQmfKJP5OLEGNUSsT-yw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] util: avoid glib event loop workaround where possible Date: Wed, 25 Nov 2020 18:04:27 +0000 Message-Id: <20201125180427.132863-3-berrange@redhat.com> In-Reply-To: <20201125180427.132863-1-berrange@redhat.com> References: <20201125180427.132863-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Christian Ehrhardt X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) I previously did a workaround for a glib event loop race that causes crashes: commit 0db4743645b7a0611a3c0687f834205c9956f7fc Author: Daniel P. Berrang=C3=A9 Date: Tue Jul 28 16:52:47 2020 +0100 util: avoid crash due to race in glib event loop code it turns out that the workaround has a significant performance penalty on I/O intensive workloads. We thus need to avoid the workaround if we know we have a new enough glib to avoid the race condition. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/vireventglib.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/util/vireventglib.c b/src/util/vireventglib.c index 6842c6e806..8c5495bfab 100644 --- a/src/util/vireventglib.c +++ b/src/util/vireventglib.c @@ -189,9 +189,21 @@ virEventGLibHandleFind(int watch) * If the last reference to a GSource is released in a non-main * thread we're exposed to a race condition that causes a * crash: - * https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1358 - * Thus we're using an idle func to release our ref + * + * https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1358 + * + * Thus we're using an idle func to release our ref... + * + * ...but this imposes a significant performance penalty on + * I/O intensive workloads which are sensitive to the iterations + * of the event loop, so avoid the workaround if we know we have + * new enough glib. */ +#if GLIB_CHECK_VERSION(2, 64, 0) +# define g_vir_source_unref_safe(source) g_source_unref(source) +#else +# define g_vir_source_unref_safe(source) g_idle_add(virEventGLibSourceUnre= fIdle, source); + static gboolean virEventGLibSourceUnrefIdle(gpointer data) { @@ -201,6 +213,7 @@ virEventGLibSourceUnrefIdle(gpointer data) =20 return FALSE; } +#endif =20 =20 static void @@ -231,7 +244,7 @@ virEventGLibHandleUpdate(int watch, if (data->source !=3D NULL) { VIR_DEBUG("Removed old handle source=3D%p", data->source); g_source_destroy(data->source); - g_idle_add(virEventGLibSourceUnrefIdle, data->source); + g_vir_source_unref_safe(data->source); } =20 data->source =3D virEventGLibAddSocketWatch( @@ -245,7 +258,7 @@ virEventGLibHandleUpdate(int watch, =20 VIR_DEBUG("Removed old handle source=3D%p", data->source); g_source_destroy(data->source); - g_idle_add(virEventGLibSourceUnrefIdle, data->source); + g_vir_source_unref_safe(data->source); data->source =3D NULL; data->events =3D 0; } @@ -294,7 +307,7 @@ virEventGLibHandleRemove(int watch) =20 if (data->source !=3D NULL) { g_source_destroy(data->source); - g_idle_add(virEventGLibSourceUnrefIdle, data->source); + g_vir_source_unref_safe(data->source); data->source =3D NULL; data->events =3D 0; } @@ -427,7 +440,7 @@ virEventGLibTimeoutUpdate(int timer, if (interval >=3D 0) { if (data->source !=3D NULL) { g_source_destroy(data->source); - g_idle_add(virEventGLibSourceUnrefIdle, data->source); + g_vir_source_unref_safe(data->source); } =20 data->interval =3D interval; @@ -437,7 +450,7 @@ virEventGLibTimeoutUpdate(int timer, goto cleanup; =20 g_source_destroy(data->source); - g_idle_add(virEventGLibSourceUnrefIdle, data->source); + g_vir_source_unref_safe(data->source); data->source =3D NULL; } =20 @@ -486,7 +499,7 @@ virEventGLibTimeoutRemove(int timer) =20 if (data->source !=3D NULL) { g_source_destroy(data->source); - g_idle_add(virEventGLibSourceUnrefIdle, data->source); + g_vir_source_unref_safe(data->source); data->source =3D NULL; } =20 --=20 2.25.4