fix the memory leak for share hugepage
PATCH 1/1 fix the memory leak for share hugepage
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
--- exec.c | 12 ++++++++++++ vl.c | 7 +++++++ 2 files changed, 19 insertions(+)
exec.c +12 -0
@@ -1535,6 +1535,18 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) } } } + +void qemu_close_all_ram_fd (void ) +{ +RAMBlock *block; + +qemu_mutex_lock_ramlist (); + QTAILQ_FOREACH(block, &ram_list.blocks, next) { +close (block->fd); + } +qemu_mutex_unlock_ramlist (); +} +#endif /* !_WIN32 */ int qemu_get_ram_fd (ram_addr_t addr)
vl.c +7 -0
@@ -1658,6 +1658,7 @@ static int qemu_shutdown_requested(void)return r; } +extern void qemu_close_all_ram_fd (void );static void qemu_kill_report (void ) {if (!qtest_driver () && shutdown_signal !=-1 ) {
@@ -1671,6 +1672,12 @@ static void qemu_kill_report(void)fprintf (stderr," from pid " FMT_pid"\n" , shutdown_pid); } shutdown_signal =-1 ; + +/* Close all ram fd when exit. If the ram is shared by othter process +* e.g vhost-user, it can free the hugepage by close fd after qemu exit, +* otherwise the process have to exit to free hugepage. +*/ +qemu_close_all_ram_fd (); } }
Signature · 1 line
1.9.0
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>
Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 11 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>
Quoted 9 lines
Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Actually, when vhost-user close the FD manually, the hugepage leak too unless the vhost-user process exit. So, maybe the FD is not a separate copy IMHO, but simply add the ref-count of FD. When QEMU exit, because the ref is not zero, the operate system will not free the FD automatically, and when vhost-user close the FD, because of the same reason, OS will not free FD resource.
BTW, I don't think this patch is good. When Qemu exit exceptionally, sush as 'by kill -9', this problem of memory leak still exist.
Best Regards,
-Gonglei
Quoted 30 lines · Gonglei
Quoted 11 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Quoted 9 lines
Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Actually, when vhost-user close the FD manually, the hugepage leak too unless the vhost-user process exit. So, maybe the FD is not a separate copy IMHO, but simply add the ref-count of FD. When QEMU exit, because the ref is not zero, the operate system will not free the FD automatically, and when vhost-user close the FD, because of the same reason, OS will not free FD resource.
Quoted 3 lines
BTW, I don't think this patch is good. When Qemu exit exceptionally, sush as 'by kill -9', this problem of memory leak still exist.
So,we should close qemu by 'kill -15' or close with virsh.
Quoted 8 lines
Best Regards,
-Gonglei.
Signature · 2 lines
Regards, Haifeng
Quoted 15 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
Quoted 8 lines
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Regards,
Daniel
Hi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the f_count is not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.
I have test it for many times.
Signature · 2 lines
Regards, Haifeng
Quoted 26 lines · Linhaifeng
Quoted 15 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
Quoted 8 lines
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Regards,
Daniel
Quoted 8 lines
Hi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.I have test it for many times.
The point is I want to free the hugepage when close port in vhost-user process and not exit.
Signature · 2 lines
Regards, Haifeng
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.
The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 33 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.
Quoted 7 lines
The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Regards,
Daniel
Hi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
This is <<linux man page>>about how to free resource of file.
http://linux.die.net/man/2/close
I'm trying to describe my problem.
For example, there are 2 VMs run with hugepage and the hugepage only for QEMU to use.
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Run the two VMs.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage.After this step the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB 5.shutdown VM with signal 15 without close(fd).After this step the meminfo is : HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Yes,it works well,like you said the kernel recycle all resources.
For another example,there are 2 VMs run with hugepage and share the hugepage with vapp(a vhost-user application).
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Run the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Run the second VM.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Then I want to close the first VM and run another VM.After close the first VM and close the fd in vapp the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
So failed to run the third VM because the first VM have not free the hugepage.After apply this patch the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
So i can run the third VM success.
Signature · 2 lines
Regards, Haifeng
Quoted 40 lines · Linhaifeng
Quoted 37 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Quoted 7 lines
Quoted 3 lines
Regards,
DanielHi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
If you don't close it, the kernel will help you when the program exits.
Quoted 33 lines
This is <<linux man page>>about how to free resource of file.
http://linux.die.net/man/2/closeI'm trying to describe my problem.
For example, there are 2 VMs run with hugepage and the hugepage only for QEMU to use.
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the two VMs.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage.After this step the meminfo is :HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB 5.shutdown VM with signal 15 without close(fd).After this step the meminfo is : HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Quoted 3 lines
Yes,it works well,like you said the kernel recycle all resources.
For another example,there are 2 VMs run with hugepage and share the hugepage with vapp(a vhost-user application).
The vapp is your internal application?
Quoted 26 lines
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the second VM.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Quoted 6 lines
Then I want to close the first VM and run another VM.After close the first VM and close the fd in vapp the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Does the qemu still run after you close the first VM? If the qemu exits, the fd will be closed by the kernel, so this bug is very strange.
Quoted 9 lines
So failed to run the third VM because the first VM have not free the hugepage.After apply this patch the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBSo i can run the third VM success.
Quoted 44 lines · Wen Congyang
Quoted 43 lines · Linhaifeng
Quoted 40 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Regards,
Daniel
Quoted 7 lines
Quoted 4 lines
Hi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
If you don't close it, the kernel will help you when the program exits.
Yes,when the hugepage is only used for qemu,the kernel will free the file object.If the hugepage shared for other process,when qemu exit the kernel will not free the file.
Quoted 33 lines
Quoted 33 lines
This is <<linux man page>>about how to free resource of file.
http://linux.die.net/man/2/closeI'm trying to describe my problem.
For example, there are 2 VMs run with hugepage and the hugepage only for QEMU to use.
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the two VMs.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage.After this step the meminfo is :HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB 5.shutdown VM with signal 15 without close(fd).After this step the meminfo is : HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Quoted 6 lines
Quoted 3 lines
Yes,it works well,like you said the kernel recycle all resources.
For another example,there are 2 VMs run with hugepage and share the hugepage with vapp(a vhost-user application).
The vapp is your internal application?
Yes vapp is a application to share the QEMU's hugepage.So threr are two process use the hugepage.
Quoted 33 lines
Quoted 26 lines
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the second VM.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBQuoted 6 lines
Then I want to close the first VM and run another VM.After close the first VM and close the fd in vapp the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Quoted 3 lines
Does the qemu still run after you close the first VM? If the qemu exits, the fd will be closed by the kernel, so this bug is very strange.
qemu is not run when close the first VM.If other process used the file will be closed by kernel too?
Quoted 13 lines
Quoted 9 lines
So failed to run the third VM because the first VM have not free the hugepage.After apply this patch the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBSo i can run the third VM success.
.
Signature · 2 lines
Regards, Haifeng
Quoted 47 lines · Linhaifeng
Quoted 44 lines · Wen Congyang
Quoted 43 lines · Linhaifeng
Quoted 40 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Regards,
Daniel
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Hi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
If you don't close it, the kernel will help you when the program exits.
Yes,when the hugepage is only used for qemu,the kernel will free the file object.If the hugepage shared for other process,when qemu exit the kernel will not free the file.
Even if the hugepage is shared with the other process, the kernel will auto close the fd when qemu exits. If the kernel doesn't do it, it is a kernel bug.
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
This is <<linux man page>>about how to free resource of file.
http://linux.die.net/man/2/closeI'm trying to describe my problem.
For example, there are 2 VMs run with hugepage and the hugepage only for QEMU to use.
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the two VMs.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage.After this step the meminfo is :HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB 5.shutdown VM with signal 15 without close(fd).After this step the meminfo is : HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Quoted 21 lines
Quoted 6 lines
Quoted 3 lines
Yes,it works well,like you said the kernel recycle all resources.
For another example,there are 2 VMs run with hugepage and share the hugepage with vapp(a vhost-user application).
The vapp is your internal application?
Yes vapp is a application to share the QEMU's hugepage.So threr are two process use the hugepage.
Quoted 13 lines
Quoted 13 lines
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:
Do you modify qemu?
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the second VM.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBThen I want to close the first VM and run another VM.After close the first VM and close the fd in vapp the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
Quoted 4 lines
Quoted 3 lines
Does the qemu still run after you close the first VM? If the qemu exits, the fd will be closed by the kernel, so this bug is very strange.
qemu is not run when close the first VM.If other process used the file will be closed by kernel too?
If qeum doesn't run after the first vm is closed, the fd should be closed even if another process uses the file.
Quoted 15 lines
Quoted 14 lines
Quoted 10 lines
So failed to run the third VM because the first VM have not free the hugepage.After apply this patch the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBSo i can run the third VM success.
.
Quoted 53 lines · Wen Congyang
Quoted 52 lines · Linhaifeng
Quoted 49 lines · Wen Congyang
Quoted 47 lines · Linhaifeng
Quoted 33 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.Quoted 7 lines
The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Regards,
DanielHi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
If you don't close it, the kernel will help you when the program exits.
Yes,when the hugepage is only used for qemu,the kernel will free the file object.If the hugepage shared for other process,when qemu exit the kernel will not free the file.
Even if the hugepage is shared with the other process, the kernel will auto close the fd when qemu exits. If the kernel doesn't do it, it is a kernel bug.
Kernel supply close to fix this bug.If you call open you must call close. If not, the result is unpredictability.
Quoted 103 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
This is <<linux man page>>about how to free resource of file.
http://linux.die.net/man/2/closeI'm trying to describe my problem.
For example, there are 2 VMs run with hugepage and the hugepage only for QEMU to use.
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the two VMs.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage.After this step the meminfo is :HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB 5.shutdown VM with signal 15 without close(fd).After this step the meminfo is : HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBQuoted 21 lines
Quoted 6 lines
Quoted 3 lines
Yes,it works well,like you said the kernel recycle all resources.
For another example,there are 2 VMs run with hugepage and share the hugepage with vapp(a vhost-user application).
The vapp is your internal application?
Yes vapp is a application to share the QEMU's hugepage.So threr are two process use the hugepage.
Quoted 13 lines
Quoted 13 lines
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:Do you modify qemu?
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the second VM.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBThen I want to close the first VM and run another VM.After close the first VM and close the fd in vapp the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBQuoted 4 lines
Quoted 3 lines
Does the qemu still run after you close the first VM? If the qemu exits, the fd will be closed by the kernel, so this bug is very strange.
qemu is not run when close the first VM.If other process used the file will be closed by kernel too?
If qeum doesn't run after the first vm is closed, the fd should be closed even if another process uses the file.
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
So failed to run the third VM because the first VM have not free the hugepage.After apply this patch the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBSo i can run the third VM success.
Quoted 3 lines
Quoted 2 lines
.
.
Signature · 2 lines
Regards, Haifeng
Quoted 58 lines · Linhaifeng
Quoted 55 lines · Wen Congyang
Quoted 54 lines · Linhaifeng
Quoted 51 lines · Wen Congyang
Quoted 40 lines · Linhaifeng
Quoted 37 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Quoted 7 lines
Quoted 3 lines
Regards,
DanielHi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
If you don't close it, the kernel will help you when the program exits.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Yes,when the hugepage is only used for qemu,the kernel will free the file object.If the hugepage shared for other process,when qemu exit the kernel will not free the file.
Even if the hugepage is shared with the other process, the kernel will auto close the fd when qemu exits. If the kernel doesn't do it, it is a kernel bug.
Kernel supply close to fix this bug.If you call open you must call close. If not, the result is unpredictability.
No, if the program exists, the kernel must close all fd used by the program. So, there is no need to close fd before program exists.
Thanks
Wen Congyang
Quoted 104 lines
Quoted 103 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
This is <<linux man page>>about how to free resource of file.
http://linux.die.net/man/2/closeI'm trying to describe my problem.
For example, there are 2 VMs run with hugepage and the hugepage only for QEMU to use.
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the two VMs.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage.After this step the meminfo is :HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB 5.shutdown VM with signal 15 without close(fd).After this step the meminfo is : HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBQuoted 21 lines
Quoted 6 lines
Quoted 3 lines
Yes,it works well,like you said the kernel recycle all resources.
For another example,there are 2 VMs run with hugepage and share the hugepage with vapp(a vhost-user application).
The vapp is your internal application?
Yes vapp is a application to share the QEMU's hugepage.So threr are two process use the hugepage.
Quoted 13 lines
Quoted 13 lines
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:Do you modify qemu?
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the second VM.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBThen I want to close the first VM and run another VM.After close the first VM and close the fd in vapp the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBQuoted 4 lines
Quoted 3 lines
Does the qemu still run after you close the first VM? If the qemu exits, the fd will be closed by the kernel, so this bug is very strange.
qemu is not run when close the first VM.If other process used the file will be closed by kernel too?
If qeum doesn't run after the first vm is closed, the fd should be closed even if another process uses the file.
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
So failed to run the third VM because the first VM have not free the hugepage.After apply this patch the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBSo i can run the third VM success.
Quoted 3 lines
Quoted 2 lines
.
.
Hi,all
Maybe this is unix domain socket's bug.I found that qemu send the fd to vapp the fd's f_count inc twice in kernel.
1.kernel calls when we call send.unix_stream_sendmsg -> unix_scm_to_skb -> unix_attach_fds -> scm_fp_dup -> get_file -> atomic_long_inc(&f->f_count)
Maybe should't inc the f_count when call send.
2.kernel calls when we call recvunix_stream_recvmsg -> scm_fp_dup -> get_file -> atomic_long_inc(&f->f_count)
Quoted 181 lines · Wen Congyang
Quoted 58 lines · Linhaifeng
Quoted 55 lines · Wen Congyang
Quoted 54 lines · Linhaifeng
Quoted 51 lines · Wen Congyang
Quoted 40 lines · Linhaifeng
Quoted 37 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Quoted 7 lines
Quoted 3 lines
Regards,
DanielHi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
If you don't close it, the kernel will help you when the program exits.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Yes,when the hugepage is only used for qemu,the kernel will free the file object.If the hugepage shared for other process,when qemu exit the kernel will not free the file.
Even if the hugepage is shared with the other process, the kernel will auto close the fd when qemu exits. If the kernel doesn't do it, it is a kernel bug.
Kernel supply close to fix this bug.If you call open you must call close. If not, the result is unpredictability.
No, if the program exists, the kernel must close all fd used by the program. So, there is no need to close fd before program exists.
Thanks
Wen CongyangQuoted 96 lines
Quoted 96 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
This is <<linux man page>>about how to free resource of file.
http://linux.die.net/man/2/closeI'm trying to describe my problem.
For example, there are 2 VMs run with hugepage and the hugepage only for QEMU to use.
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the two VMs.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage.After this step the meminfo is :HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB 5.shutdown VM with signal 15 without close(fd).After this step the meminfo is : HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBQuoted 21 lines
Quoted 6 lines
Quoted 3 lines
Yes,it works well,like you said the kernel recycle all resources.
For another example,there are 2 VMs run with hugepage and share the hugepage with vapp(a vhost-user application).
The vapp is your internal application?
Yes vapp is a application to share the QEMU's hugepage.So threr are two process use the hugepage.
Quoted 13 lines
Quoted 13 lines
Before run VM the meminfo is :
HugePages_Total: 4096 HugePages_Free: 4096 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:Do you modify qemu?
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBRun the second VM.After this step the meminfo is:
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBThen I want to close the first VM and run another VM.After close the first VM and close the fd in vapp the meminfo is :
HugePages_Total: 4096 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBQuoted 4 lines
Quoted 3 lines
Does the qemu still run after you close the first VM? If the qemu exits, the fd will be closed by the kernel, so this bug is very strange.
qemu is not run when close the first VM.If other process used the file will be closed by kernel too?
If qeum doesn't run after the first vm is closed, the fd should be closed even if another process uses the file.
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
So failed to run the third VM because the first VM have not free the hugepage.After apply this patch the meminfo is:
HugePages_Total: 4096 HugePages_Free: 2048 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kBSo i can run the third VM success.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
.
.
.
Signature · 2 lines
Regards, Haifeng
Quoted 40 lines · Linhaifeng
Quoted 37 lines · Daniel P. Berrange
Quoted 23 lines · Linhaifeng
Quoted 20 lines · Daniel P. Berrange
Quoted 9 lines · On Fri, Oct 17, 2014 at 04:27:17PM +0800, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>Err, all file descriptors are closed automatically when a process exits. So manually calling close(fd) before exit can't have any functional effect on a resource leak.
If QEMU has sent the FD to another process, that process has a completely separate copy of the FD. Closing the FD in QEMU will not close the FD in the other process. You need the other process to exit for the copy to be closed.
Quoted 8 lines
Quoted 3 lines
Regards,
DanielHi,daniel
QEMU send the fd by unix domain socket.unix domain socket just install the fd to other process and inc the f_count,if qemu not close the fd the
f_countis not dec. Then the other process even close the fd the hugepage would not freed whise the other process exit.The kernel always closes all FDs when a process exits. So if this FD is not being correctly closed then it is a kernel bug. There should never be any reason for an application to do close(fd) before exiting.
Quoted 7 lines
Quoted 3 lines
Regards,
DanielHi,daniel
I don't think this is kernel's bug.May be this a problem about usage. If you open a file you should close it too.
No, the standard UNIX semantics are that the kernel will close all file descriptors when a process exits. There is *no* requirement to manually close any file descriptors before exiting.
The only time you need to close files is if you are using a higher level API (eg C library "FILE *" ) and you need to explicitly flush any buffered I/O operations before exiting. This doesn't apply in the case of huge pages.
Quoted 5 lines
Run the first VM.QEMU deal with hugepage as follow steps:
1.open
2.unlink
3.mmap
4.use memory of hugepage and send the fd to vapp with unix domain socket.After this step the meminfo is:
If the QEMU process has exited then the kernel has closed the FD that QEMU had open. The logical implication is that the 'vapp' process still has its copy of the file descriptor open even after QEMU has exited.
Another possibility is that whatever launched QEMU has not done a waitpid and thus leaving QEMU in a zombie state where file descriptors are not yet cleaned up.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 50 lines · On 2014/10/17 16:27, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>--- exec.c | 12 ++++++++++++ vl.c | 7 +++++++ 2 files changed, 19 insertions(+)exec.c +12
-0@@ -1535,6 +1535,18 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) } } } + +void qemu_close_all_ram_fd (void ) +{ +RAMBlock *block; + +qemu_mutex_lock_ramlist (); + QTAILQ_FOREACH(block, &ram_list.blocks, next) { +close (block->fd); + } +qemu_mutex_unlock_ramlist (); +} +#endif /* !_WIN32 */ int qemu_get_ram_fd (ram_addr_t addr)vl.c +1
-0@@ -1658,6 +1658,7 @@ static int qemu_shutdown_requested(void)return r; } +extern void qemu_close_all_ram_fd (void );static void qemu_kill_report (void ) {if (!qtest_driver () && shutdown_signal !=-1 ) {
vl.c static void qemu_kill_report(void) · line 1676
Quoted 5 lines
vl.c +2
-0@@ -1671,6 +1672,12 @@ static void qemu_kill_report(void)fprintf (stderr," from pid " FMT_pid"\n" , shutdown_pid); } shutdown_signal =-1 ; + +/* Close all ram fd when exit. If the ram is shared by othter process
s/othter/other/
Quoted 8 lines
vl.c +4
-0+* e.g vhost-user, it can free the hugepage by close fd after qemu exit, +* otherwise the process have to exit to free hugepage. +*/ +qemu_close_all_ram_fd (); } }
Quoted 46 lines · zhanghailiang
Quoted 45 lines · On 2014/10/17 16:27, [email protected] wrote:
From: linhaifeng <[email protected]>
The VM start with share hugepage should close the hugefile fd when exit.Because the hugepage fd may be send to other process e.g vhost-user If qemu not close the fd the other process can not free the hugepage otherwise exit process,this is ugly,so qemu should close all shared fd when exit.
Signed-off-by linhaifeng <[email protected]>--- exec.c | 12 ++++++++++++ vl.c | 7 +++++++ 2 files changed, 19 insertions(+)exec.c +12
-0@@ -1535,6 +1535,18 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) } } } + +void qemu_close_all_ram_fd (void ) +{ +RAMBlock *block; + +qemu_mutex_lock_ramlist (); + QTAILQ_FOREACH(block, &ram_list.blocks, next) { +close (block->fd); + } +qemu_mutex_unlock_ramlist (); +} +#endif /* !_WIN32 */ int qemu_get_ram_fd (ram_addr_t addr)vl.c +0
-0@@ -1658,6 +1658,7 @@ static int qemu_shutdown_requested(void)return r; }
Quoted 13 lines
vl.c static void qemu_kill_report(void) · line 1676
Quoted 10 lines
vl.c +3
-0+extern void qemu_close_all_ram_fd (void );static void qemu_kill_report (void ) {if (!qtest_driver () && shutdown_signal !=-1 ) {@@ -1671,6 +1672,12 @@ static void qemu_kill_report(void)fprintf (stderr," from pid " FMT_pid"\n" , shutdown_pid); } shutdown_signal =-1 ; + +/* Close all ram fd when exit. If the ram is shared by othter process s/othter/other/
OK.thank you.
Quoted 13 lines
vl.c static void qemu_kill_report(void) · line 1683
Quoted 8 lines
vl.c +4
-0+* e.g vhost-user, it can free the hugepage by close fd after qemu exit, +* otherwise the process have to exit to free hugepage. +*/ +qemu_close_all_ram_fd (); } }.
Signature · 2 lines
Regards, Haifeng