WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] xenpaging: handle XENMEM_decrease_reservation

To: Patrick Colp <pjcolp@xxxxxxxxx>
Subject: [Xen-devel] [PATCH] xenpaging: handle XENMEM_decrease_reservation
From: Olaf Hering <olaf@xxxxxxxxx>
Date: Wed, 22 Sep 2010 17:38:40 +0200
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 22 Sep 2010 08:39:42 -0700
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1285169929; l=2302; s=domk; d=aepfle.de; h=In-Reply-To:Content-Type:MIME-Version:References:Subject:Cc:To:From: Date:X-RZG-CLASS-ID:X-RZG-AUTH; bh=Sw4ttWvoUsY7XGgAE4zsW9nERzw=; b=rK9QyqP5/Ud9nbrcuPio/NbkB4TvLI/Qzv9+17P6rn3uCtHtzX/MmtHY3sYVFz2BLAE 1YHlOLARTGklG3NF/6KOAQ0pRqekcyb3Sshv+itoBw24uixl70W3vTVCqGrgM/sb1Y/jT LpE7qmQu6y+aX1sRgrjS0bBUANS44OcobRw=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <20100915160521.GA16644@xxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <20100915160521.GA16644@xxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.20 (2009-06-14)
Handle paged-out pages for XENMEM_decrease_reservation memory op.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>

---
 tools/libxc/xc_domain.c |   38 ++++++++++++++++++++++++++------------
 xen/common/memory.c     |    4 ++++
 2 files changed, 30 insertions(+), 12 deletions(-)

--- xen-unstable.hg-4.1.22155.orig/tools/libxc/xc_domain.c
+++ xen-unstable.hg-4.1.22155/tools/libxc/xc_domain.c
@@ -620,15 +620,15 @@ int xc_domain_memory_decrease_reservatio
                                           xen_pfn_t *extent_start)
 {
     int err;
+    unsigned long delay = 0;
+    unsigned long start = 0;
+    unsigned long count= nr_extents;
     struct xen_memory_reservation reservation = {
-        .nr_extents   = nr_extents,
         .extent_order = extent_order,
         .mem_flags    = 0,
         .domid        = domid
     };
 
-    set_xen_guest_handle(reservation.extent_start, extent_start);
-
     if ( extent_start == NULL )
     {
         DPRINTF("decrease_reservation extent_start is NULL!\n");
@@ -636,16 +636,30 @@ int xc_domain_memory_decrease_reservatio
         return -1;
     }
 
-    err = xc_memory_op(xch, XENMEM_decrease_reservation, &reservation);
-    if ( err == nr_extents )
-        return 0;
+    while (1) {
+        set_xen_guest_handle(reservation.extent_start, extent_start + start);
+        reservation.nr_extents = count;
 
-    if ( err >= 0 )
-    {
-        DPRINTF("Failed deallocation for dom %d: %ld extents of order %d\n",
-                domid, nr_extents, extent_order);
-        errno = EINVAL;
-        err = -1;
+        err = xc_memory_op(xch, XENMEM_decrease_reservation, &reservation);
+        if ( err == count )
+        {
+            err = 0;
+            break;
+        }
+
+        if ( err > count || err <= 0 || delay > 1000 * 1000)
+        {
+            DPRINTF("Failed deallocation for dom %d: %ld extents of order %d: 
0x%x\n",
+                    domid, nr_extents, extent_order, err);
+            errno = EINVAL;
+            err = -1;
+            break;
+        }
+
+        start += err;
+        count -= err;
+        usleep(delay);
+        delay += 666; /* 1500 iterations, 12 seconds */
     }
 
     return err;
--- xen-unstable.hg-4.1.22155.orig/xen/common/memory.c
+++ xen-unstable.hg-4.1.22155/xen/common/memory.c
@@ -162,6 +162,10 @@ int guest_remove_page(struct domain *d,
 
 #ifdef CONFIG_X86
     mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(d), gmfn, &p2mt)); 
+    if ( p2m_is_paged(p2mt) )
+        p2m_mem_paging_populate(p2m_get_hostp2m(d), gmfn);
+    if ( p2m_is_paging(p2mt) )
+        return -ENOENT;
 #else
     mfn = gmfn_to_mfn(d, gmfn);
 #endif

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel