From nobody Tue Feb 10 02:48:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563264818; cv=none; d=zoho.com; s=zohoarc; b=DqDvdG7ki8VNbaFfdqHMY0m7WlFHEaKCCPjLP7Hv8IUtMPrloRT8cf/GUskcwSiY+0feOEXGGXzXpxy7pY5yHyFHj5jmGdE9tUx8xVQBQcV8JnrEtO7yAYMCFkFMwinpKrpRJiHcejitW5dWliMj1g5WOuccBatk+BllMX87dsE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563264818; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=UxGATMBNQig2wIfjWLxzWQxLyakGvI3IHTSyhIIbcuE=; b=fpsjHL8FCRIgKSc8K6S5G3j65wxN+2cpHY4vZ6mdc3zS8+Z5pT6g38S0D8tQ/7K/c3wMpeDBVrWVjo3pHDKBhNWfaxk+kd1+DIq++ilp50FcjkElYyw2vLyv9XnIOsc4JDUKzrPonCpCrRH7/vnGGdhPRZFUJiTY2SdlfNE5fW8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563264818546285.45345856569554; Tue, 16 Jul 2019 01:13:38 -0700 (PDT) Received: from localhost ([::1]:46183 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnIae-0008CB-EH for importer@patchew.org; Tue, 16 Jul 2019 04:13:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59915) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnIYd-0008GS-Lq for qemu-devel@nongnu.org; Tue, 16 Jul 2019 04:11:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnIYc-0003GM-CX for qemu-devel@nongnu.org; Tue, 16 Jul 2019 04:11:31 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:36696) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnIYc-0003Fb-68 for qemu-devel@nongnu.org; Tue, 16 Jul 2019 04:11:30 -0400 Received: by mail-wr1-x429.google.com with SMTP id n4so19888599wrs.3 for ; Tue, 16 Jul 2019 01:11:30 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id c1sm37723879wrh.1.2019.07.16.01.11.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 01:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=UxGATMBNQig2wIfjWLxzWQxLyakGvI3IHTSyhIIbcuE=; b=ZtI3N8WmcsSjB326JXV4NX2p6ACeFbGi0divP59eJUfFp1+xOSyhpD5cakMdPq4SqM al/7nxnUbcLrD5jbEn1P55QHkIOmVPiPcN5AaSmevXhCjWiZCvlvaT52Ydfcregl1uee OYfD8dCq+UjjkKP8mEJJx5IMW6eAZEMGzQlqzqwIoOK391+6Fb0k14kRg9mcewsmAVJu qQBzDQttLPWnfBqhYLiJn5sKf3QR8nxHSakYFT9GNC1oxTlotAS5DXJEPsrpYsDVvNiJ rFFrxOURjwfAmrYhkiIgYORGAPpWvAetzDuGO2M0MH7oQ8PEWPuFgKoxvBKgD+dpMOZ8 GD/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=UxGATMBNQig2wIfjWLxzWQxLyakGvI3IHTSyhIIbcuE=; b=PUqP5JzuDSQCbvKynnqmMhJP6fGGXoq959HYQOmsosBZWJ89K4+TEpT0+BIftIe7oH Hdhk3GGrMyqPaxV8Xu86ijods+dxb3wLg+thY+nuIxpev2w+mASMMdj4EMDr8vEOjBsS G2A7yeOoI9QIdK80gNdbYUKmZw/uWk0hZaEnDrmdKhuWGBjAyVc82xVZgijS6igeF0wl DPccY3ukLh5lV4TQ2zEoW0nQsJqV/R9oS3i4bX4mTpX9O1uzDzjpIHzplGskSgryMLe9 Q7Fsu0muJ2jpFsB6JhcxWkyokTZzvs05/jPz51BEcZZeHjqh8hlGzE6/3GjKcsbKuYb8 5mRQ== X-Gm-Message-State: APjAAAXqbxBzkYyaUSD49DSrjiRzrkgeSkvQxdKUQGQMj8CdmuEokveT 6J31p+Vf0SSF+x3BhrP0QICKicWSEc8= X-Google-Smtp-Source: APXvYqyTYIdM/xOg9NHClSKz7NNh9HpbCGsybjuvAR7Zi5HR94sIeJUx7WuxfUK4sgvQEQtF4DbXQg== X-Received: by 2002:a5d:46cf:: with SMTP id g15mr35592887wrs.93.1563264688886; Tue, 16 Jul 2019 01:11:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 16 Jul 2019 10:11:07 +0200 Message-Id: <1563264677-39718-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1563264677-39718-1-git-send-email-pbonzini@redhat.com> References: <1563264677-39718-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::429 Subject: [Qemu-devel] [PULL 09/19] memory: unref the memory region in simplify flatview X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: King Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: King Wang The memory region reference is increased when insert a range into flatview range array, then decreased by destroy flatview. If some flat range merged by flatview_simplify, the memory region reference can not be decreased by destroy flatview any more. In this case, start virtual machine by the command line: qemu-system-x86_64 -name guest=3Dubuntu,debug-threads=3Don -machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff -cpu host -m 16384 -realtime mlock=3Doff -smp 8,sockets=3D2,cores=3D4,threads=3D1 -object memory-backend-file,id=3Dram-node0,prealloc=3Dyes,mem-path=3D/dev/h= ugepages,share=3Dyes,size=3D8589934592 -numa node,nodeid=3D0,cpus=3D0-3,memdev=3Dram-node0 -object memory-backend-file,id=3Dram-node1,prealloc=3Dyes,mem-path=3D/dev/h= ugepages,share=3Dyes,size=3D8589934592 -numa node,nodeid=3D1,cpus=3D4-7,memdev=3Dram-node1 -no-user-config -nodefaults -rtc base=3Dutc -no-shutdown -boot strict=3Don -device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 -device virtio-scsi-pci,id=3Dscsi0,bus=3Dpci.0,addr=3D0x2 -device virtio-serial-pci,id=3Dvirtio-serial0,bus=3Dpci.0,addr=3D0x3 -drive file=3Dubuntu.qcow2,format=3Dqcow2,if=3Dnone,id=3Ddrive-virtio-disk0= ,cache=3Dnone,aio=3Dnative -device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x4,drive=3Ddrive-virt= io-disk0,id=3Dvirtio-disk0,bootindex=3D1 -chardev pty,id=3Dcharserial0 -device isa-serial,chardev=3Dcharserial0,id=3Dserial0 -device usb-tablet,id=3Dinput0,bus=3Dusb.0,port=3D1 -vnc 0.0.0.0:0 -device VGA,id=3Dvideo0,vgamem_mb=3D16,bus=3Dpci.0,addr=3D0x5 -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x6 -msg timestamp=3Don And run the script in guest OS: while true do setpci -s 00:06.0 04.b=3D03 setpci -s 00:06.0 04.b=3D07 done I found the reference of node0 HostMemoryBackendFile is a big one. (gdb) p numa_info[0]->node_memdev->parent.ref $6 =3D 1636278 (gdb) Signed-off-by: King Wang Message-Id: <20190712065241.11784-1-king.wang@huawei.com> Signed-off-by: Paolo Bonzini --- memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 480f3d9..d8d42bd 100644 --- a/memory.c +++ b/memory.c @@ -321,7 +321,7 @@ static bool can_merge(FlatRange *r1, FlatRange *r2) /* Attempt to simplify a view by merging adjacent ranges */ static void flatview_simplify(FlatView *view) { - unsigned i, j; + unsigned i, j, k; =20 i =3D 0; while (i < view->nr) { @@ -332,6 +332,9 @@ static void flatview_simplify(FlatView *view) ++j; } ++i; + for (k =3D i; k < j; k++) { + memory_region_unref(view->ranges[k].mr); + } memmove(&view->ranges[i], &view->ranges[j], (view->nr - j) * sizeof(view->ranges[j])); view->nr -=3D j - i; --=20 1.8.3.1