xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xensource.com
Subject: [PATCH 06 of 10] xenpaging: improve performance in policy_choose_victim
Date: Mon, 30 Jan 2012 16:59:29 +0100	[thread overview]
Message-ID: <b7906ad2815304272686.1327939169@probook.site> (raw)
In-Reply-To: <patchbomb.1327939163@probook.site>

# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1327937798 -3600
# Node ID b7906ad28153042726866cfbef40f8adf8dc1520
# Parent  2e9a4bfaf79d64863f18a519c448afc54315aa1d
xenpaging: improve performance in policy_choose_victim

policy_choose_victim() is one of the bottlenecks in xenpaging. It is called
alot to find free bits in the fragmented bitmaps.

Reduce turnaround time by skipping longs with all bits set.
Adjust wrap detection in loop.

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

diff -r 2e9a4bfaf79d -r b7906ad28153 tools/xenpaging/policy_default.c
--- a/tools/xenpaging/policy_default.c
+++ b/tools/xenpaging/policy_default.c
@@ -80,33 +80,58 @@ int policy_init(struct xenpaging *paging
 unsigned long policy_choose_victim(struct xenpaging *paging)
 {
     xc_interface *xch = paging->xc_handle;
-    unsigned long wrap = current_gfn;
+    unsigned long i;
 
-    do
+    /* One iteration over all possible gfns */
+    for ( i = 0; i < max_pages; i++ )
     {
+        /* Try next gfn */
         current_gfn++;
+
+        /* Restart on wrap */
         if ( current_gfn >= max_pages )
             current_gfn = 0;
-        /* Could not nominate any gfn */
-        if ( wrap == current_gfn )
+
+        if ( (current_gfn & (BITS_PER_LONG - 1)) == 0 )
         {
-            paging->use_poll_timeout = 1;
-            /* Count wrap arounds */
-            unconsumed_cleared++;
-            /* Force retry every few seconds (depends on poll() timeout) */
-            if ( unconsumed_cleared > 123)
+            /* All gfns busy */
+            if ( ~bitmap[current_gfn >> ORDER_LONG] == 0 || ~unconsumed[current_gfn >> ORDER_LONG] == 0 )
             {
-                /* Force retry of unconsumed gfns */
-                bitmap_clear(unconsumed, max_pages);
-                unconsumed_cleared = 0;
-                DPRINTF("clearing unconsumed, wrap %lx", wrap);
-                /* One more round before returning ENOSPC */
+                current_gfn += BITS_PER_LONG;
+                i += BITS_PER_LONG;
                 continue;
             }
-            return INVALID_MFN;
         }
+
+        /* gfn busy */
+        if ( test_bit(current_gfn, bitmap) )
+            continue;
+
+        /* gfn already tested */
+        if ( test_bit(current_gfn, bitmap) )
+            continue;
+
+        /* gfn found */
+        break;
     }
-    while ( test_bit(current_gfn, bitmap) || test_bit(current_gfn, unconsumed) );
+
+    /* Could not nominate any gfn */
+    if ( i >= max_pages )
+    {
+        /* No more pages, wait in poll */
+        paging->use_poll_timeout = 1;
+        /* Count wrap arounds */
+        unconsumed_cleared++;
+        /* Force retry every few seconds (depends on poll() timeout) */
+        if ( unconsumed_cleared > 123)
+        {
+            /* Force retry of unconsumed gfns on next call */
+            bitmap_clear(unconsumed, max_pages);
+            unconsumed_cleared = 0;
+            DPRINTF("clearing unconsumed, current_gfn %lx", current_gfn);
+        }
+        return INVALID_MFN;
+    }
 
     set_bit(current_gfn, unconsumed);
     return current_gfn;

  parent reply	other threads:[~2012-01-30 15:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-30 15:59 [PATCH 00 of 10] tools/xenpaging: cleanups and performance improvements Olaf Hering
2012-01-30 15:59 ` [PATCH 01 of 10] xenpaging: use flat index for pagefile and page-in requests Olaf Hering
2012-01-30 15:59 ` [PATCH 02 of 10] xenpaging: no poll timeout while page-out is in progress Olaf Hering
2012-01-30 15:59 ` [PATCH 03 of 10] xenpaging: mmap guest pages read-only Olaf Hering
2012-01-30 15:59 ` [PATCH 04 of 10] xenpaging: reduce number of qemu cache flushes Olaf Hering
2012-01-30 15:59 ` [PATCH 05 of 10] xenpaging: move nominate+evict into single function Olaf Hering
2012-01-30 15:59 ` Olaf Hering [this message]
2012-02-14 21:08   ` [PATCH 06 of 10] xenpaging: improve performance in policy_choose_victim Olaf Hering
2012-02-20 17:25     ` [PATCH 06 of 10] xenpaging: improve performance in policy_choose_victim [and 1 more messages] Ian Jackson
2012-02-20 18:48       ` Olaf Hering
2012-01-30 15:59 ` [PATCH 07 of 10] xenpaging: unify error handling Olaf Hering
2012-01-30 15:59 ` [PATCH 08 of 10] xenpaging: move pagefile filedescriptor into struct xenpaging Olaf Hering
2012-01-30 15:59 ` [PATCH 09 of 10] xenpaging: move page_buffer " Olaf Hering
2012-01-30 15:59 ` [PATCH 10 of 10] xenpaging: implement stack of free slots in pagefile Olaf Hering
2012-02-09 17:57 ` [PATCH 00 of 10] tools/xenpaging: cleanups and performance improvements Ian Jackson

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=b7906ad2815304272686.1327939169@probook.site \
    --to=olaf@aepfle.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).