* [Qemu-devel] [PATCH] memory: unref the memory region in simplify flatview
@ 2019-07-12 6:52 Wang King
2019-07-12 17:48 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Wang King @ 2019-07-12 6:52 UTC (permalink / raw)
To: pbonzini; +Cc: weidong.huang, qemu-devel, king.wang
From: King Wang<king.wang@huawei.com>
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<king.wang@huawei.com>
---
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;
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;
--
2.21.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] memory: unref the memory region in simplify flatview
2019-07-12 6:52 [Qemu-devel] [PATCH] memory: unref the memory region in simplify flatview Wang King
@ 2019-07-12 17:48 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2019-07-12 17:48 UTC (permalink / raw)
To: Wang King; +Cc: weidong.huang, qemu-devel
On 12/07/19 08:52, Wang King wrote:
> From: King Wang<king.wang@huawei.com>
>
> 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<king.wang@huawei.com>
> ---
> 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;
>
> 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;
>
Good catch. Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-12 17:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-12 6:52 [Qemu-devel] [PATCH] memory: unref the memory region in simplify flatview Wang King
2019-07-12 17:48 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).