All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>
Cc: kvm-devel@lists.sourceforge.net, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 3/3] QEMU: balloon: zap any shadow mappings to a page before madvise(MADV_DONTNEED)
Date: Wed, 12 Mar 2008 16:17:23 -0300	[thread overview]
Message-ID: <20080312191945.400115745@localhost.localdomain> (raw)
In-Reply-To: 20080312191720.490529767@localhost.localdomain

[-- Attachment #1: virtio-ball1 --]
[-- Type: text/plain, Size: 3799 bytes --]

Call into kvm to know whether we can madvise(MADV_DONTNEED) pages.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: kvm-userspace.balloon/libkvm/libkvm.c
===================================================================
--- kvm-userspace.balloon.orig/libkvm/libkvm.c
+++ kvm-userspace.balloon/libkvm/libkvm.c
@@ -840,6 +840,20 @@ int kvm_is_ready_for_interrupt_injection
 	return run->ready_for_interrupt_injection;
 }
 
+int kvm_zap_single_gfn(kvm_context_t kvm, unsigned long gfn)
+{
+	int r = -1;
+
+#ifdef KVM_CAP_ZAP_GFN
+	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_ZAP_GFN);
+	if (r > 0)
+		r = ioctl(kvm->vm_fd, KVM_ZAP_GFN, &gfn);
+	else
+		r = -1;
+#endif
+	return r;
+}
+
 int kvm_run(kvm_context_t kvm, int vcpu)
 {
 	int r;
Index: kvm-userspace.balloon/libkvm/libkvm.h
===================================================================
--- kvm-userspace.balloon.orig/libkvm/libkvm.h
+++ kvm-userspace.balloon/libkvm/libkvm.h
@@ -422,6 +422,7 @@ int kvm_get_dirty_pages_range(kvm_contex
 			      unsigned long end_addr, void *buf, void*opaque,
 			      int (*cb)(unsigned long start, unsigned long len,
 					void*bitmap, void *opaque));
+int kvm_zap_single_gfn(kvm_context_t kvm, unsigned long gfn);
 
 /*!
  * \brief Create a memory alias
Index: kvm-userspace.balloon/qemu/hw/virtio-balloon.c
===================================================================
--- kvm-userspace.balloon.orig/qemu/hw/virtio-balloon.c
+++ kvm-userspace.balloon/qemu/hw/virtio-balloon.c
@@ -17,6 +17,7 @@
 #include "balloon.h"
 #include "sysemu.h"
 #include "console.h"
+#include "qemu-kvm.h"
 
 #include <sys/mman.h>
 
@@ -60,22 +61,21 @@ static void virtio_balloon_handle_output
 	unsigned int wlen = 0;
 
 	for (i = 0; i < elem.out_num; i++) {
-	    int flags;
 	    uint32_t *pfns = elem.out_sg[i].iov_base;
 	    unsigned int n_pfns = elem.out_sg[i].iov_len / 4;
 	    int j;
 
 	    for (j = 0; j < n_pfns; j++) {
-		if (vq == s->dvq) /* deflate */
-		    flags = MADV_WILLNEED;
-		else /* inflate */
-		    flags = MADV_DONTNEED;
-
-#if 0
-		/* can't use this until we have mmu notifier support */
-		madvise(phys_ram_base + (pfns[j] << TARGET_PAGE_BITS),
-			TARGET_PAGE_SIZE, flags);
-#endif
+		if (vq == s->dvq)
+                    /* deflate */
+		        madvise(phys_ram_base + (pfns[j] << TARGET_PAGE_BITS),
+			        TARGET_PAGE_SIZE, MADV_WILLNEED);
+		else { /* inflate */
+			if (kvm_zap_gfn(pfns[j]) == 0)
+				madvise(phys_ram_base +
+					(pfns[j] << TARGET_PAGE_BITS),
+					TARGET_PAGE_SIZE, MADV_DONTNEED);
+		}
 	    }
 
 	    wlen += elem.out_sg[i].iov_len;
Index: kvm-userspace.balloon/qemu/qemu-kvm.c
===================================================================
--- kvm-userspace.balloon.orig/qemu/qemu-kvm.c
+++ kvm-userspace.balloon/qemu/qemu-kvm.c
@@ -65,6 +65,11 @@ static void sig_ipi_handler(int n)
 {
 }
 
+int kvm_zap_gfn(unsigned long gfn)
+{
+	return kvm_zap_single_gfn(kvm_context, gfn);
+}
+
 void kvm_update_interrupt_request(CPUState *env)
 {
     if (env && vcpu && env != vcpu->env) {
Index: kvm-userspace.balloon/qemu/qemu-kvm.h
===================================================================
--- kvm-userspace.balloon.orig/qemu/qemu-kvm.h
+++ kvm-userspace.balloon/qemu/qemu-kvm.h
@@ -24,6 +24,7 @@ int kvm_qemu_init_env(CPUState *env);
 int kvm_qemu_check_extension(int ext);
 void kvm_apic_init(CPUState *env);
 int kvm_set_irq(int irq, int level);
+int kvm_zap_gfn(unsigned long gfn);
 
 int kvm_physical_memory_set_dirty_tracking(int enable);
 int kvm_update_dirty_pages_log(void);

-- 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  parent reply	other threads:[~2008-03-12 19:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-12 19:17 [patch 0/3] QEMU balloon support Marcelo Tosatti
2008-03-12 19:17 ` [patch 1/3] QEMU support for virtio balloon driver Marcelo Tosatti
2008-03-12 19:17 ` [patch 2/3] QEMU: balloon: dont allow target larger than ram size Marcelo Tosatti
2008-03-12 19:17 ` Marcelo Tosatti [this message]
2008-03-16 14:00 ` [patch 0/3] QEMU balloon support Avi Kivity
2008-03-16 18:59   ` Marcelo Tosatti
2008-03-17 11:11     ` Avi Kivity
2008-03-17 13:08       ` Marcelo Tosatti
2008-03-17 14:56         ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080312191945.400115745@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.