From nobody Sun Feb 8 21:48:35 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=1615982346; cv=none; d=zohomail.com; s=zohoarc; b=asCNHubT29j5MZKgE+Ue4XYuHGNfefci1nEc/5b2GowEugMMGKCT/Eih0za2u5aAkMCQ6eqV/g6oaX90c317XTJiu8cj+vSwwptXkft0NAbX4JTh+K5eGIgMy1TOdlljJNbcl8a8trOnoH1IwJkA7a5SKO+CqAfOvHRHWcnDuaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615982346; 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=vqDj56l18yMzAoJe+bEcL59kBAOO0xGqp2+NDMPM+/k=; b=HjozNbERwVz5pPzegncDOpLrgMLcvQ0zrJCj/03j/wdyMKxHs6hnTbR2tvbcgFA4OOPbQsnE+hPANlpmiwt69xAe3ULO00ewq7d2gBYThsFP1Ypn7ztK7V0pb6/QCvOddCYKBkebB7RFc6uth3n4r/lriy64Ba7nQTHxQKn/tUo= 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 161598234672732.05324712350125; Wed, 17 Mar 2021 04:59:06 -0700 (PDT) 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-311-YZhClWCRO9SOy-NJxVxjug-1; Wed, 17 Mar 2021 07:58:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C94C108BD09; Wed, 17 Mar 2021 11:58:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB6AC5D74E; Wed, 17 Mar 2021 11:58:08 +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 79245180213C; Wed, 17 Mar 2021 11:58:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12HBvk4b028356 for ; Wed, 17 Mar 2021 07:57:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0DFA81037E82; Wed, 17 Mar 2021 11:57:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58F9E1017CF5; Wed, 17 Mar 2021 11:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615982345; 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=vqDj56l18yMzAoJe+bEcL59kBAOO0xGqp2+NDMPM+/k=; b=ccE/3QPoG00LilvucQ8Yo1b7HJhm5Hzug+GnJaMt+bkdo+pQJQU2xaaLppFjhZeQJcBP2b UwOOqxFW12+IAldn3maRm/sD3ux1Se6dOXCeAlALaVdsw0e1Rjt91vhRbg7j2CWceaqmBe XXQeRwvZWauklfxqCpVULfAezmsu9V8= X-MC-Unique: YZhClWCRO9SOy-NJxVxjug-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 11/15] qemu: Account for both memballoon and virtio-mem Date: Wed, 17 Mar 2021 12:57:21 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: david@redhat.com 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.79 on 10.5.11.15 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Reporting how much memory is exposed to the guest happens under which is taken from def->mem.cur_balloon. The reported amount should account for both balloon size and the sum of @actualsize of all virtio-mems. For instance, if domain has 4GiB via balloon and additional 2GiB via virtio-mem, then the domain XML should report 6GiB. The same applies for domain statistics. The way to achieve this is to account for either balloon or virtio-mem when the size of the other is changed, e.g. on balloon change we have to add all @actualsize (for non virtio-mem these will be zero, so the check for memory model is needless, but makes it more obvious what's happening), and vice versa. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 4 ++++ src/qemu/qemu_process.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6bcbc75fbc..d5891e32c3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4323,6 +4323,7 @@ processMemoryDeviceSizeChange(virQEMUDriverPtr driver, { virDomainMemoryDefPtr mem =3D NULL; virObjectEventPtr event =3D NULL; + unsigned long long balloon; =20 if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) return; @@ -4338,7 +4339,10 @@ processMemoryDeviceSizeChange(virQEMUDriverPtr drive= r, goto endjob; } =20 + balloon =3D vm->def->mem.cur_balloon - mem->actualsize; mem->actualsize =3D VIR_DIV_UP(info->size, 1024); + balloon +=3D mem->actualsize; + vm->def->mem.cur_balloon =3D balloon; =20 event =3D virDomainEventMemoryDeviceSizeChangeNewFromObj(vm, info->devAlias, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index dc301371ef..f6da5afb48 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1253,10 +1253,19 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon G= _GNUC_UNUSED, virQEMUDriverPtr driver =3D opaque; virObjectEventPtr event =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + size_t i; =20 virObjectLock(vm); event =3D virDomainEventBalloonChangeNewFromObj(vm, actual); =20 + /* We want the balloon size stored in domain definition to account for= the + * actual size of virtio-mem too. */ + VIR_DEBUG("balloon size before fix is %lld", actual); + for (i =3D 0; i < vm->def->nmems; i++) { + if (vm->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_= MEM) + actual +=3D vm->def->mems[i]->actualsize; + } + VIR_DEBUG("Updating balloon from %lld to %lld kb", vm->def->mem.cur_balloon, actual); vm->def->mem.cur_balloon =3D actual; @@ -2451,6 +2460,7 @@ qemuProcessRefreshBalloonState(virQEMUDriverPtr drive= r, int asyncJob) { unsigned long long balloon; + size_t i; int rc; =20 /* if no ballooning is available, the current size equals to the curre= nt @@ -2467,6 +2477,13 @@ qemuProcessRefreshBalloonState(virQEMUDriverPtr driv= er, if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) return -1; =20 + /* We want the balloon size stored in domain definition to account for= the + * actual size of virtio-mem too. */ + VIR_DEBUG("balloon size before fix is %lld", balloon); + for (i =3D 0; i < vm->def->nmems; i++) { + if (vm->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_= MEM) + balloon +=3D vm->def->mems[i]->actualsize; + } vm->def->mem.cur_balloon =3D balloon; =20 return 0; --=20 2.26.2