From nobody Tue Apr 23 10:19:47 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1562914407; cv=none; d=zoho.com; s=zohoarc; b=YYl5Mxd+xGiFcxMK5bGBjINXoZlPsQMbDZYQYLenFVO/W4zyeWDxrOUw9/he34MVikjkVj/xJ9H1NpCM2rFYWUc8sbpzmUj7Riq/LBoD3gtQrzM2QggFMJqj+TpTydpF0o62IHkBfPiUQUNwmcGiTPVRZpyXTKj8CT0y3rMniMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562914407; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=A4ALEGovMvI9+lzpy6GcnlgVOHQeA/yoKRjn8SAPI/w=; b=NZbqwKcXGagKvwflKSRVnVs/EhqMH++tRdU9PGl4ThdZZJR+TDTXlKa5EB9JXnc8SLZ8JXmOwsb9Vop60ZgqnkJcqCvQ7WErg2xcoAVfh2QanC+mYOtmkbgTusQYCifSBDCI7Nbr+iIQ/yTCK+70TPEGCd0oZcm+T/XiOb8S98U= ARC-Authentication-Results: i=1; mx.zoho.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15629144075195.337375595370645; Thu, 11 Jul 2019 23:53:27 -0700 (PDT) Received: from localhost ([::1]:47052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlpQo-0007Nh-Py for importer@patchew.org; Fri, 12 Jul 2019 02:53:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56098) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlpQe-0006yd-VC for qemu-devel@nongnu.org; Fri, 12 Jul 2019 02:53:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlpQd-0001jd-Ip for qemu-devel@nongnu.org; Fri, 12 Jul 2019 02:53:12 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:53354 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlpQd-0001bN-4g for qemu-devel@nongnu.org; Fri, 12 Jul 2019 02:53:11 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5F8741FB7011A7BED614; Fri, 12 Jul 2019 14:52:58 +0800 (CST) Received: from localhost (10.177.17.7) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.439.0; Fri, 12 Jul 2019 14:52:48 +0800 From: Wang King To: Date: Fri, 12 Jul 2019 14:52:41 +0800 Message-ID: <20190712065241.11784-1-king.wang@huawei.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Originating-IP: [10.177.17.7] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.35 Subject: [Qemu-devel] [PATCH] 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: weidong.huang@huawei.com, qemu-devel@nongnu.org, king.wang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 --- memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 480f3d989b..d8d42bdff8 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 2.21.0