From nobody Sun Feb 8 22:51:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1668440164; cv=none; d=zohomail.com; s=zohoarc; b=hQa9g8XdYDultDAAjEQAt8Pz6LTjEzhZ0uu1fg3LNjYAYqILPEkMNRCXxUI22WjQ64Wwp7iQ3y48FKkqKXN8NmuBt6EDgTJ6tUhE0eFPMx+gOXVr5MC5W6Wti/ZbGXOztk/Bfk2PMah8JIrBCclFgmO0vKpHSGSg3A0nKNoOYjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668440164; h=Content-Type:Content-Transfer-Encoding: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=sOg1J1v75Fx0WyRZDB5IF4qTbppQd2VfRpF2rX+xC2A=; b=QbaMksgyv2JhVAUpbz/DMYyclDCClmZT3sD0m9gYJ3uEotSzLZEp6q9hpN76oTYXrz4HwOkg6yJJPjq4Arxm8QjPO7olIlsbQKDbb1fnFkN8HTHN0c43Gip8U9VDnAvRTgVwVvOKzoNRtpm1hxkUQiVdOOuIk9vlrp3i6/bDmIE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 166844016423481.49298992088109; Mon, 14 Nov 2022 07:36:04 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-2-1Y8OjbYlPE-OqDvKGIw1yQ-1; Mon, 14 Nov 2022 10:35:43 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8B88D38012CC; Mon, 14 Nov 2022 15:35:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 762C54043CCC; Mon, 14 Nov 2022 15:35:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4FF8E19466DF; Mon, 14 Nov 2022 15:35:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BCC21194658F for ; Mon, 14 Nov 2022 15:35:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A3041475060; Mon, 14 Nov 2022 15:35:38 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47DF9475061 for ; Mon, 14 Nov 2022 15:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668440163; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=sOg1J1v75Fx0WyRZDB5IF4qTbppQd2VfRpF2rX+xC2A=; b=BprGxL5HwtE5e+zFkmjFZbAU8M60HRK0XyquCs4RMIJOSur1PBjZI5U/gJ81C62LxDGSQJ WJoL+FHEcYIx4NRa3Ig8YgojqZ3uZrMq0tfshK8I51InDcyjh+IhSLEwKgI566Ww9HHero JSmNk2o8ZrYTb1HDMk7w3ZN0f4gIEKI= X-MC-Unique: 1Y8OjbYlPE-OqDvKGIw1yQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/7] qemu: Delete thread-context objects at domain startup Date: Mon, 14 Nov 2022 16:35:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668440164628100001 Content-Type: text/plain; charset="utf-8"; x-default="true" While technically thread-context objects can be reused, we only use them (well, will use them) to pin memory allocation threads. Therefore, once we connect to QEMU monitor, all memory (with prealloc=3Dyes) was allocated and thus these objects are no longer needed and can be removed. For on demand allocation the TC object is left behind. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/qemu/qemu_command.c | 7 ++++++ src/qemu/qemu_domain.c | 2 ++ src/qemu/qemu_domain.h | 2 ++ src/qemu/qemu_process.c | 47 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_process.h | 2 ++ 5 files changed, 60 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 392b248628..90bc537b33 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3613,6 +3613,7 @@ qemuBuildThreadContextProps(virJSONValue **tcProps, g_autoptr(virJSONValue) nodemaskCopy =3D NULL; g_autofree char *tcAlias =3D NULL; const char *memalias =3D NULL; + bool prealloc =3D false; =20 if (tcProps) *tcProps =3D NULL; @@ -3646,6 +3647,12 @@ qemuBuildThreadContextProps(virJSONValue **tcProps, NULL) < 0) return -1; =20 + if (virJSONValueObjectGetBoolean(*memProps, "prealloc", &prealloc) >= =3D 0 && + prealloc) { + priv->threadContextAliases =3D g_slist_prepend(priv->threadContext= Aliases, + g_steal_pointer(&tcAl= ias)); + } + *tcProps =3D g_steal_pointer(&props); return 0; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0d579bfc9b..ef1a9c8c74 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1811,6 +1811,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *p= riv) priv->preMigrationMemlock =3D 0; =20 virHashRemoveAll(priv->statsSchema); + + g_slist_free_full(g_steal_pointer(&priv->threadContextAliases), g_free= ); } =20 =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index d5f4fbad12..a9af8502d2 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -251,6 +251,8 @@ struct _qemuDomainObjPrivate { * briefly when starting a guest. Don't save/parse into XML. */ pid_t schedCoreChildPID; pid_t schedCoreChildFD; + + GSList *threadContextAliases; /* List of IDs of thread-context objects= */ }; =20 #define QEMU_DOMAIN_PRIVATE(vm) \ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4b26c384cf..0769f30d74 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7500,6 +7500,50 @@ qemuProcessSetupLifecycleActions(virDomainObj *vm, } =20 =20 +int +qemuProcessDeleteThreadContext(virDomainObj *vm) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + GSList *next =3D priv->threadContextAliases; + int ret =3D -1; + + if (!next) + return 0; + + for (; next; next =3D next->next) { + if (qemuMonitorDelObject(priv->mon, next->data, true) < 0) + goto cleanup; + } + + ret =3D 0; + cleanup: + g_slist_free_full(g_steal_pointer(&priv->threadContextAliases), g_free= ); + return ret; +} + + +static int +qemuProcessDeleteThreadContextHelper(virDomainObj *vm, + virDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + int ret =3D -1; + + if (!priv->threadContextAliases) + return 0; + + VIR_DEBUG("Deleting thread context objects"); + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + return -1; + + ret =3D qemuProcessDeleteThreadContext(vm); + + qemuDomainObjExitMonitor(vm); + + return ret; +} + + /** * qemuProcessLaunch: * @@ -7860,6 +7904,9 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuProcessSetupLifecycleActions(vm, asyncJob) < 0) goto cleanup; =20 + if (qemuProcessDeleteThreadContextHelper(vm, asyncJob) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index d1f58ee258..9a24745f15 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -123,6 +123,8 @@ int qemuProcessPrepareHost(virQEMUDriver *driver, virDomainObj *vm, unsigned int flags); =20 +int qemuProcessDeleteThreadContext(virDomainObj *vm); + int qemuProcessLaunch(virConnectPtr conn, virQEMUDriver *driver, virDomainObj *vm, --=20 2.37.4