From nobody Sat Feb 7 04:40:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1642599156; cv=none; d=zohomail.com; s=zohoarc; b=hUQ1O15M934KhkGJ//OGEG8/EWuQvKa+kjIx0s3DeKoo5nykyvf+qDE825QIEeirTM+wdXDqzAKPVEHoFVa420eMRK4NDnZGfnIRA0oxJ5WTTScZDnV7Tqeb8R3oMUL59H73IaXMKxY7O50TAsjag5/Tqm9/oUcaLnlHrhHiHrE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642599156; 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=WHMzIGuGlB6biUiU7/iThnkmMg9XyqqHclvKPCPRULc=; b=S5FEbwofjbbbcAt35yW27WGPD+uUfqQM3sBg5fHfjVQ4YHqHwaicrKdjDvtvL2qjPRa9VFvpefGs7ib5cfmmgI/eK9k3PrnvjX4QH1NLIUFJedTKKK2JpgU49gC8QzQpqQJvIzkYDrRaiSZNR9OUFCGYHOG2wLA7RZEyAq7fsLQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1642599156214320.4397338422858; Wed, 19 Jan 2022 05:32:36 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-421-I0KLKhqPMtybsNWiUlldMA-1; Wed, 19 Jan 2022 08:32:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 523E18519E1; Wed, 19 Jan 2022 13:32:28 +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 225B784A0F; Wed, 19 Jan 2022 13:32:28 +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 E0C841806D1C; Wed, 19 Jan 2022 13:32:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20JDWRc3009010 for ; Wed, 19 Jan 2022 08:32:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3B5B67DE4D; Wed, 19 Jan 2022 13:32:27 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 909377DE50; Wed, 19 Jan 2022 13:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642599155; 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=WHMzIGuGlB6biUiU7/iThnkmMg9XyqqHclvKPCPRULc=; b=EypInqXhgFQhFCVzewOVa07UT9wRrMVbTFEBLrdXC3pqBVXuqZNovh1qS9j4DhUXrcmjYe FJOA2x4ubY/BjVX3I+4xYRZS8s5zGDUQtIazLCRiZsC618huy8ZdBBwvDs6Heua/z3RhHP lfIHpWv9IIJOuZaGG3U4ncCt8t9gtRg= X-MC-Unique: I0KLKhqPMtybsNWiUlldMA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 3/5] qemu: Move @prealloc into qemuBuildMemoryGetPagesize() Date: Wed, 19 Jan 2022 14:32:16 +0100 Message-Id: <817058c2b8bb4fbed4fdaf679039fc6e2c416d1a.1642598968.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.13 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) X-ZM-MESSAGEID: 1642599157972100003 Content-Type: text/plain; charset="utf-8" The qemuBuildMemoryGetPagesize() function has everything is needs to decide whether preallocation is needed or not. Move the logic from qemuBuildMemoryBackendProps() into qemuBuildMemoryGetPagesize(). Signed-off-by: Michal Privoznik --- src/qemu/qemu_command.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 858aa0211a..9ab2b25fe2 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3609,12 +3609,14 @@ qemuBuildMemoryGetPagesize(virQEMUDriverConfig *cfg, const virDomainMemoryDef *mem, unsigned long long *pagesizeRet, bool *needHugepageRet, - bool *useHugepageRet) + bool *useHugepageRet, + bool *preallocRet) { const long system_page_size =3D virGetSystemPageSizeKB(); unsigned long long pagesize =3D mem->pagesize; bool needHugepage =3D !!pagesize; bool useHugepage =3D !!pagesize; + bool prealloc =3D false; =20 if (pagesize =3D=3D 0) { virDomainHugePage *master_hugepage =3D NULL; @@ -3675,9 +3677,23 @@ qemuBuildMemoryGetPagesize(virQEMUDriverConfig *cfg, return -1; } =20 + if (def->mem.allocation =3D=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) + prealloc =3D true; + + /* If the NVDIMM is a real device then there's nothing to prealloc. + * If anything, we would be only wearing off the device. + * Similarly, virtio-pmem-pci doesn't need prealloc either. */ + if (mem->nvdimmPath && !mem->nvdimmPmem && + mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM) + prealloc =3D true; + + if (useHugepage) + prealloc =3D true; + *pagesizeRet =3D pagesize; *needHugepageRet =3D needHugepage; *useHugepageRet =3D useHugepage; + *preallocRet =3D prealloc; =20 return 0; } @@ -3767,15 +3783,12 @@ qemuBuildMemoryBackendProps(virJSONValue **backendP= rops, if (discard =3D=3D VIR_TRISTATE_BOOL_ABSENT) discard =3D def->mem.discard; =20 - if (def->mem.allocation =3D=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) - prealloc =3D true; - if (virDomainNumatuneGetMode(def->numa, mem->targetNode, &mode) < 0 && virDomainNumatuneGetMode(def->numa, -1, &mode) < 0) mode =3D VIR_DOMAIN_NUMATUNE_MEM_STRICT; =20 if (qemuBuildMemoryGetPagesize(cfg, def, mem, &pagesize, - &needHugepage, &useHugepage) < 0) + &needHugepage, &useHugepage, &prealloc)= < 0) return -1; =20 props =3D virJSONValueNewObject(); @@ -3784,13 +3797,10 @@ qemuBuildMemoryBackendProps(virJSONValue **backendP= rops, def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_MEMFD) { backendType =3D "memory-backend-memfd"; =20 - if (useHugepage) { - if (virJSONValueObjectAdd(&props, "b:hugetlb", useHugepage, NU= LL) < 0 || - virJSONValueObjectAdd(&props, "U:hugetlbsize", pagesize <<= 10, NULL) < 0) { - return -1; - } - - prealloc =3D true; + if (useHugepage && + (virJSONValueObjectAdd(&props, "b:hugetlb", useHugepage, NULL)= < 0 || + virJSONValueObjectAdd(&props, "U:hugetlbsize", pagesize << 10= , NULL) < 0)) { + return -1; } =20 if (qemuBuildMemoryBackendPropsShare(props, memAccess) < 0) @@ -3804,15 +3814,9 @@ qemuBuildMemoryBackendProps(virJSONValue **backendPr= ops, =20 if (mem->nvdimmPath) { memPath =3D g_strdup(mem->nvdimmPath); - /* If the NVDIMM is a real device then there's nothing to prea= lloc. - * If anything, we would be only wearing off the device. - * Similarly, virtio-pmem-pci doesn't need prealloc either. */ - if (!mem->nvdimmPmem && mem->model !=3D VIR_DOMAIN_MEMORY_MODE= L_VIRTIO_PMEM) - prealloc =3D true; } else if (useHugepage) { if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &m= emPath) < 0) return -1; - prealloc =3D true; } else { /* We can have both pagesize and mem source. If that's the cas= e, * prefer hugepages as those are more specific. */ --=20 2.34.1