From nobody Mon Feb 9 01:47:26 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=1619184315; cv=none; d=zohomail.com; s=zohoarc; b=MQND5/aW9RKHHdCwsswaMQdFIL5ljWEmf3Utp542Jy6ol1sVZHfGtmidZXmmYzfgNhs97AwoeqZYbOAmu6oVtUqI3B6Rfv0iWeHU2XQm4K/8/d8BU/bhGeFDDsrGF+1aSC3jbkfIweGNHHPPGopWRCmUNbRa3OX0FKZyRxf5wHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619184315; 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=aApWMuq2cDlvSBxqoAvV6bhHRyuthpVy0JaRr08oxp8=; b=AkdjnlbuZTZWJAYEDFnVShX9ga7wOv51Std6YqUos66RYxc4otzJJNTJ0rRoLJMQ+QqxFdP+ZdQ9u5xM+eR5Iwm5QcAqTCsDxUt7l46fueftQTLIvJkKolZA0HwE4rDpD+ql/+bQdLWlafljcUAitCamD4aLdk6KMGhORMjRBjQ= 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 1619184315653616.8798678459221; Fri, 23 Apr 2021 06:25:15 -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-441-8vIKhzWBOLS4KotiHmPkOw-1; Fri, 23 Apr 2021 09:25:12 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D88E281744F; Fri, 23 Apr 2021 13:25:06 +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 B37DE1B513; Fri, 23 Apr 2021 13:25:06 +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 6FBF544A67; Fri, 23 Apr 2021 13:25:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13NDP41H021733 for ; Fri, 23 Apr 2021 09:25:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8D6636A8E5; Fri, 23 Apr 2021 13:25:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AD7363634 for ; Fri, 23 Apr 2021 13:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619184314; 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=aApWMuq2cDlvSBxqoAvV6bhHRyuthpVy0JaRr08oxp8=; b=PkGR+k496NDIwpYZu/oPRKwzmkhLtGXgmSBcCKIDbjNpxOeU7gIqwPxu1Fijss0ZZOQii1 Elc9ruWxlGlhfDRyZWTePf/kd0KaNIbjdcuRn8sHHMhF85oc6rcyTRXdH8mIl/K9X2A2K0 fCQgxfry38yVoqXGxPVXjSl6DplVR1o= X-MC-Unique: 8vIKhzWBOLS4KotiHmPkOw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 10/14] qemu: Account for both memballoon and virtio-mem Date: Fri, 23 Apr 2021 15:24:32 +0200 Message-Id: <91f3bad85387356e0934cb7f3f56c9808dc6a908.1619184154.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@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.12 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 b495a261d1..e376a64bee 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4324,6 +4324,7 @@ processMemoryDeviceSizeChange(virQEMUDriver *driver, { virDomainMemoryDef *mem =3D NULL; virObjectEvent *event =3D NULL; + unsigned long long balloon; =20 if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) return; @@ -4339,7 +4340,10 @@ processMemoryDeviceSizeChange(virQEMUDriver *driver, 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 55f081cc9d..b529983f73 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1232,10 +1232,19 @@ qemuProcessHandleBalloonChange(qemuMonitor *mon G_G= NUC_UNUSED, virQEMUDriver *driver =3D opaque; virObjectEvent *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; @@ -2430,6 +2439,7 @@ qemuProcessRefreshBalloonState(virQEMUDriver *driver, 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 @@ -2446,6 +2456,13 @@ qemuProcessRefreshBalloonState(virQEMUDriver *driver, 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.3