: xenpaging: add command to to flush qemu buffer cache via VMCALL
RFC PATCH 1/1 : xenpaging: add command to to flush qemu buffer cache via VMCALL
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1330272880 -3600
# Node ID e17afed13a35989bdf422b75d44843bfd2fda0f4
# Parent 3ace34b89ebe3bdd6afb0bca85b0c1270f99c1bb
[RFC]: xenpaging: add command to to flush qemu buffer cache via VMCALL
Is the approach taken in this patch ok?
With the debug output in my patch I get output like pasted below. It means that xenpaging set qemu_mapcache_invalidate very often before a VMCALL occoured.
What triggers a VMCALL anyway? It looks like its not something one can depend on. From xenpagings PoV its not required that the command reaches qemu right away, but it should be processed "soon".
Could send_invalidate_req() be called from another exit reason (or from another place perhaps)?
Olaf
....
(XEN) irq.c:350: Dom1 callback via changed to PCI INTx Dev 0x03 IntA (XEN) hvm_do_hypercall: 0 1 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 0 1 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 3049 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 4562 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 6 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 6 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 14 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 598 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 1 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 3 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 161 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 1 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 4860 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 1 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 799 0 0
(XEN) io.c:155:d1 send_invalidate_req
(XEN) hvm_do_hypercall: 5 0 0
(XEN) io.c:155:d1 send_invalidate_req
....
....
qemu will just keep mapping pages and not release them, which causes problems for the memory pager (since the page is mapped, it won't get paged out). When the pager has trouble finding a page to page out, it asks qemu to flush its buffer, which releases all the page mappings. This makes it possible to find pages to swap out agian.
This change removes the code which writes "flush-cache" to xenstore because the corresponding change for qemu-xen-traditional was never applied, and it also will not work with qemu-xen-upstream.
Instead of sending commands via xenstore, use the existing IOREQ_TYPE_INVALIDATE command for HVM guests. A simple memory_op just sets qemu_mapcache_invalidate flag which in turn causes the hypervisor to send the actual IOREQ_TYPE_INVALIDATE during next VMEXIT_VMCALL.
tools/libxc/xc_mem_paging.c +8 -0
@@ -93,6 +93,14 @@ int xc_mem_paging_load(xc_interface *xchreturn rc; } +int xc_mem_paging_flush (xc_interface *xch,domid_t domain_id) +{ +return xc_mem_event_memop (xch, domain_id, + XENMEM_paging_op_ioemu_flush, + XENMEM_paging_op, +0 ,NULL ); +} +/* * Local variables:
tools/libxc/xenctrl.h +1 -0
@@ -1902,6 +1902,7 @@ int xc_mem_paging_evict(xc_interface *xcint xc_mem_paging_prep (xc_interface *xch,domid_t domain_id,unsigned long gfn);int xc_mem_paging_load (xc_interface *xch,domid_t domain_id,unsigned long gfn,void *buffer); +int xc_mem_paging_flush (xc_interface *xch,domid_t domain_id);int xc_mem_access_enable (xc_interface *xch,domid_t domain_id,void *shared_page,void *ring_page);
tools/xenpaging/xenpaging.c +9 -8
@@ -62,15 +62,11 @@ static void close_handler(int sig)unlink_pagefile (); } -static void xenpaging_mem_paging_flush_ioemu_cache (struct xenpaging *paging) +static int xenpaging_mem_paging_flush_ioemu_cache (struct xenpaging *paging) { -struct xs_handle *xsh = paging->xs_handle; +xc_interface *xch = paging->xc_handle;domid_t domain_id = paging->mem_event.domain_id; -char path[80 ]; - -sprintf (path,"/local/domain/0/device-model/%u/command" , domain_id); - -xs_write (xsh,XBT_NULL , path,"flush-cache" ,strlen ("flush-cache" )); +return xc_mem_paging_flush (xch, domain_id); }static int xenpaging_wait_for_event_or_timeout (struct xenpaging *paging)
@@ -768,7 +764,12 @@ static int evict_victim(struct xenpagingif ( num_paged_out != paging->num_paged_out ) {DPRINTF ("Flushing qemu cache\n" ); -xenpaging_mem_paging_flush_ioemu_cache (paging); + ret =xenpaging_mem_paging_flush_ioemu_cache (paging); +if ( ret <0 ) + { +PERROR ("Flushing qemu cache\n" ); + goto out; + } num_paged_out = paging->num_paged_out; } ret =ENOSPC ;
xen/arch/x86/hvm/hvm.c +12 -0
@@ -2997,6 +2997,7 @@ static long hvm_memory_op(int cmd, XEN_Greturn -ENOSYS ;case XENMEM_decrease_reservation: rc =do_memory_op (cmd, arg); + current->domain->arch.hvm_domain.inv_hvm++; current->domain->arch.hvm_domain.qemu_mapcache_invalidate =1 ;return rc; }
@@ -3088,6 +3089,7 @@ static long hvm_memory_op_compat32(int creturn -ENOSYS ;case XENMEM_decrease_reservation: rc =compat_memory_op (cmd, arg); + current->domain->arch.hvm_domain.inv_hvm32++; current->domain->arch.hvm_domain.qemu_mapcache_invalidate =1 ;return rc; }
@@ -3246,7 +3248,17 @@ int hvm_do_hypercall(struct cpu_user_regif (unlikely (curr->domain->arch.hvm_domain.qemu_mapcache_invalidate) &&test_and_clear_bool (curr->domain->arch.hvm_domain. qemu_mapcache_invalidate) ) + { +printk ("%s: %u %u %u\n" , + __func__, + curr->domain->arch.hvm_domain.inv_paging, + curr->domain->arch.hvm_domain.inv_hvm, + curr->domain->arch.hvm_domain.inv_hvm32); + curr->domain->arch.hvm_domain.inv_paging = + curr->domain->arch.hvm_domain.inv_hvm = + curr->domain->arch.hvm_domain.inv_hvm32 =0 ;return HVM_HCALL_invalidate; + }return HVM_HCALL_completed; }
xen/arch/x86/hvm/io.c +1 -0
@@ -152,6 +152,7 @@ void send_invalidate_req(void)struct vcpu *v = current;ioreq_t *p =get_ioreq (v); +gdprintk (XENLOG_DEBUG ,"%s\n" , __func__);if ( p->state !=STATE_IOREQ_NONE ) { gdprintk(XENLOG_ERR, "WARNING: send invalidate req with something "
xen/arch/x86/mm/mem_paging.c +9 -0
@@ -53,6 +53,15 @@ int mem_paging_memop(struct domain *d, x }break ; +case XENMEM_paging_op_ioemu_flush: + { +/* Flush qemu cache on next VMEXIT_VMCALL */ + d->arch.hvm_domain.inv_paging++; + d->arch.hvm_domain.qemu_mapcache_invalidate =1 ; +return 0 ; + } +break ; +default :return -ENOSYS ;break ;
xen/include/asm-x86/hvm/domain.h +3 -0
@@ -95,6 +95,9 @@ struct hvm_domain {bool_t mem_sharing_enabled;bool_t qemu_mapcache_invalidate;bool_t is_s3_suspended; +unsigned int inv_paging; +unsigned int inv_hvm; +unsigned int inv_hvm32;union {struct vmx_domain vmx;
xen/include/public/memory.h +1 -0
@@ -322,6 +322,7 @@ typedef struct xen_pod_target xen_pod_ta#define XENMEM_paging_op_nominate 0#define XENMEM_paging_op_evict 1#define XENMEM_paging_op_prep 2 +#define XENMEM_paging_op_ioemu_flush 3#define XENMEM_access_op 21#define XENMEM_access_op_resume 0
Quoted 8 lines · Olaf Hering
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1330272880 -3600
# Node IDe17afed13a35989bdf422b75d44843bfd2fda0f4
# Parent3ace34b89ebe3bdd6afb0bca85b0c1270f99c1bb
[RFC]: xenpaging: add command to to flush qemu buffer cache via VMCALLIs the approach taken in this patch ok?
Can you explain a bit more about what you're trying to do?
It looks like you're replacing a xenstore-based flush operation with one that forces Xen to send an invalidation after the next guest hypercall completes. What's the advantage of doing it that way?
As Andres points out, if the guest isn't making hypercalls that means you'll never get any flush requests. And even if not, it seems like an abuse of the system.
Tim
Quoted 11 lines · Tim Deegan
Quoted 8 lines · Olaf Hering
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1330272880 -3600
# Node IDe17afed13a35989bdf422b75d44843bfd2fda0f4
# Parent3ace34b89ebe3bdd6afb0bca85b0c1270f99c1bb
[RFC]: xenpaging: add command to to flush qemu buffer cache via VMCALLIs the approach taken in this patch ok?
Can you explain a bit more about what you're trying to do?
It looked easy to "inject" a request to send a flush to ioemu in this way. But it turned out that this approach will not work.
So both old and new qemu need a change to accept the flush command in some way. For old qemu the xenstore approach looks best, for the new qemu I need to dig into QMP.
Olaf
Quoted 10 lines · Olaf Hering
Quoted 8 lines · Tim Deegan
Quoted 7 lines · Olaf Hering
# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1330272880 -3600
# Node IDe17afed13a35989bdf422b75d44843bfd2fda0f4
# Parent3ace34b89ebe3bdd6afb0bca85b0c1270f99c1bb
[RFC]: xenpaging: add command to to flush qemu buffer cache via VMCALL
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Is the approach taken in this patch ok?
Can you explain a bit more about what you're trying to do?
It looked easy to "inject" a request to send a flush to ioemu in this way. But it turned out that this approach will not work.
I think it could be made to work, but it will need more changes than this. Since the current mechanism is really only intended for guest hypercalls it would need to be updated so that the flag is checked in more places (say, on every VMENTER, or maybe somewhere a little less hot like on interrupt injection).
How synchronous to you need the flush to be, btw? If you need to be sure it's completed then you probably can't go through the hypervisor.
Quoted 3 lines
So both old and new qemu need a change to accept the flush command in some way. For old qemu the xenstore approach looks best, for the new qemu I need to dig into QMP.
Righto. Can you please make sure that whatever you do for new qemu doesn't require xenpaging and qemu to be in the same VM?
Cheers,
Tim.
Quoted 2 lines · Tim Deegan
How synchronous to you need the flush to be, btw? If you need to be sure it's completed then you probably can't go through the hypervisor.
This event is async, just a one-shot signal to kindly ask ioemu to flush its buffers.
If you see a way to inject this sort of request from dom0, that would be great.
Olaf