From patchwork Tue Jul 16 08:11:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 11045473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 543A013A4 for ; Tue, 16 Jul 2019 08:13:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 456B328496 for ; Tue, 16 Jul 2019 08:13:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39C85285A7; Tue, 16 Jul 2019 08:13:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3F239285A5 for ; Tue, 16 Jul 2019 08:13:29 +0000 (UTC) Received: from localhost ([::1]:46183 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnIaW-0008CB-72 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Jul 2019 04:13:28 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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=ubuntu,debug-threads=on -machine pc,accel=kvm,usb=off,dump-guest-core=off -cpu host -m 16384 -realtime mlock=off -smp 8,sockets=2,cores=4,threads=1 -object memory-backend-file,id=ram-node0,prealloc=yes,mem-path=/dev/hugepages,share=yes,size=8589934592 -numa node,nodeid=0,cpus=0-3,memdev=ram-node0 -object memory-backend-file,id=ram-node1,prealloc=yes,mem-path=/dev/hugepages,share=yes,size=8589934592 -numa node,nodeid=1,cpus=4-7,memdev=ram-node1 -no-user-config -nodefaults -rtc base=utc -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x2 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x3 -drive file=ubuntu.qcow2,format=qcow2,if=none,id=drive-virtio-disk0,cache=none,aio=native -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0,bus=usb.0,port=1 -vnc 0.0.0.0:0 -device VGA,id=video0,vgamem_mb=16,bus=pci.0,addr=0x5 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on And run the script in guest OS: while true do setpci -s 00:06.0 04.b=03 setpci -s 00:06.0 04.b=07 done I found the reference of node0 HostMemoryBackendFile is a big one. (gdb) p numa_info[0]->node_memdev->parent.ref $6 = 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; i = 0; while (i < view->nr) { @@ -332,6 +332,9 @@ static void flatview_simplify(FlatView *view) ++j; } ++i; + for (k = 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 -= j - i;