All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: Patrick Colp <pjcolp@cs.ubc.ca>
Cc: xen-devel@lists.xensource.com
Subject: [PATCH] xenpaging: break endless loop during inital page-out with large pagefiles
Date: Wed, 22 Sep 2010 17:40:26 +0200	[thread overview]
Message-ID: <20100922154026.GB25088@aepfle.de> (raw)
In-Reply-To: <20100915160521.GA16644@aepfle.de>


To allow the starting for xenpaging right after 'xm start XYZ', I
specified a pagefile size equal to the guest memory size in the hope to
catch more errors where the paged-out state of a p2mt is not checked.

While doing that, xenpaging got into an endless loop because some pages
cant be paged out right away. Now the policy reports an error if the gfn
number wraps.

Signed-off-by: Olaf Hering <olaf@aepfle.de>

---
 tools/xenpaging/policy_default.c |   30 ++++++++++++++++++++++++------
 tools/xenpaging/xenpaging.c      |    7 +++++--
 2 files changed, 29 insertions(+), 8 deletions(-)

--- xen-unstable.hg-4.1.22155.orig/tools/xenpaging/policy_default.c
+++ xen-unstable.hg-4.1.22155/tools/xenpaging/policy_default.c
@@ -32,6 +32,10 @@
 static unsigned long mru[MRU_SIZE];
 static unsigned int i_mru = 0;
 static unsigned long *bitmap;
+static unsigned long *unconsumed;
+static unsigned long current_gfn;
+static unsigned long bitmap_size;
+static unsigned long max_pages;
 
 
 int policy_init(xenpaging_t *paging)
@@ -43,6 +47,14 @@ int policy_init(xenpaging_t *paging)
     rc = alloc_bitmap(&bitmap, paging->bitmap_size);
     if ( rc != 0 )
         goto out;
+    /* Allocate bitmap to track unusable pages */
+    rc = alloc_bitmap(&unconsumed, paging->bitmap_size);
+    if ( rc != 0 )
+        goto out;
+
+    /* record bitmap_size */
+    bitmap_size = paging->bitmap_size;
+    max_pages = paging->domain_info->max_pages;
 
     /* Initialise MRU list of paged in pages */
     for ( i = 0; i < MRU_SIZE; i++ )
@@ -51,8 +63,6 @@ int policy_init(xenpaging_t *paging)
     /* Don't page out page 0 */
     set_bit(0, bitmap);
 
-    rc = 0;
-
  out:
     return rc;
 }
@@ -61,17 +71,24 @@ int policy_choose_victim(xc_interface *x
                          xenpaging_t *paging, domid_t domain_id,
                          xenpaging_victim_t *victim)
 {
+    unsigned long wrap = current_gfn;
     ASSERT(victim != NULL);
 
     /* Domain to pick on */
     victim->domain_id = domain_id;
-    
+
     do
     {
-        /* Randomly choose a gfn to evict */
-        victim->gfn = rand() % paging->domain_info->max_pages;
+        current_gfn++;
+        if ( current_gfn >= max_pages )
+            current_gfn = 0;
+        if ( wrap == current_gfn )
+            return -ENOSPC;
     }
-    while ( test_bit(victim->gfn, bitmap) );
+    while ( test_bit(current_gfn, bitmap) || test_bit(current_gfn, unconsumed) );
+
+    set_bit(current_gfn, unconsumed);
+    victim->gfn = current_gfn;
 
     return 0;
 }
@@ -79,6 +96,7 @@ int policy_choose_victim(xc_interface *x
 void policy_notify_paged_out(domid_t domain_id, unsigned long gfn)
 {
     set_bit(gfn, bitmap);
+    clear_bit(gfn, unconsumed);
 }
 
 void policy_notify_paged_in(domid_t domain_id, unsigned long gfn)
--- xen-unstable.hg-4.1.22155.orig/tools/xenpaging/xenpaging.c
+++ xen-unstable.hg-4.1.22155/tools/xenpaging/xenpaging.c
@@ -446,7 +446,8 @@ static int evict_victim(xc_interface *xc
         ret = policy_choose_victim(xch, paging, domain_id, victim);
         if ( ret != 0 )
         {
-            ERROR("Error choosing victim");
+            if ( ret != -ENOSPC )
+                ERROR("Error choosing victim");
             goto out;
         }
 
@@ -525,7 +526,9 @@ int main(int argc, char *argv[])
     memset(victims, 0, sizeof(xenpaging_victim_t) * num_pages);
     for ( i = 0; i < num_pages; i++ )
     {
-        evict_victim(xch, paging, domain_id, &victims[i], fd, i);
+        rc = evict_victim(xch, paging, domain_id, &victims[i], fd, i);
+        if ( rc == -ENOSPC )
+		break;
         if ( i % 100 == 0 )
             DPRINTF("%d pages evicted\n", i);
     }

  parent reply	other threads:[~2010-09-22 15:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-15 16:05 xenpaging fixes for kernel and hypervisor Olaf Hering
2010-09-15 16:08 ` [PATCH] xenpaging: handle GNTST_eagain in kernel drivers Olaf Hering
2010-09-16  3:44   ` Patrick Colp
2010-09-16  9:05     ` Keir Fraser
2010-09-16 13:33     ` Olaf Hering
2010-09-15 16:10 ` [PATCH] xenpaging: page-in granttable entries Olaf Hering
2010-09-15 16:11 ` [PATCH] xenpaging: fix crash in notify_via_xen_event_channel Olaf Hering
2010-09-15 16:12 ` [PATCH] xenpaging: avoid empty pagefile on unsupported hardware Olaf Hering
2010-09-22 15:38 ` [PATCH] xenpaging: handle XENMEM_decrease_reservation Olaf Hering
2010-09-22 15:40 ` Olaf Hering [this message]
2010-09-22 15:41 ` [PATCH] xenpaging: allow only one xenpaging call per guest Olaf Hering
2010-09-22 15:48 ` xenpaging fixes for kernel and hypervisor Olaf Hering
2010-09-22 16:49   ` Patrick Colp
2010-09-22 17:13     ` Keir Fraser
2010-09-22 17:14     ` Keir Fraser
2010-09-22 17:20     ` Olaf Hering

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=20100922154026.GB25088@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=pjcolp@cs.ubc.ca \
    --cc=xen-devel@lists.xensource.com \
    /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.