Skip to contentSkip to conversation

xenpaging: no poll timeout while page-out is in progress

PATCH New Olaf Hering 1 participant 1 message Jan 9, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xenpaging: no poll timeout while page-out is in progress

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1326117284 -3600
# Node ID 3394ca5ef6f768aa2fe0988c121b2a86698f1400 # Parent 3a22ed3ec534799b3cab55b0dc0a7380e701ecbe
xenpaging: no poll timeout while page-out is in progress

The main loop calls xenpaging_wait_for_event_or_timeout() unconditionally before doing any work. This function calls poll() with a timeout of 100ms. As a result the page-out process is very slow due to the delay in poll().

Call poll() without timeout so that it returns immediately until the page-out is done. Page-out is done when either the policy finds no more pages to nominate or when the requested number of pages is reached.

The condition is cleared when a watch event arrives, so that processing the new target is not delayed once again by poll().

tools/xenpaging/policy_default.c +1 -0
diff -r 3a22ed3ec534 -r 3394ca5ef6f7 tools/xenpaging/policy_default.c
@@ -90,6 +90,7 @@ int policy_choose_victim(xenpaging_t *pa
         /* Could not nominate any gfn */
         if ( wrap == current_gfn )
         {
+            paging->use_poll_timeout = 1;
             /* Count wrap arounds */
             unconsumed_cleared++;
             /* Force retry every few seconds (depends on poll() timeout) */
tools/xenpaging/xenpaging.c +11 -1
diff -r 3a22ed3ec534 -r 3394ca5ef6f7 tools/xenpaging/xenpaging.c
@@ -85,6 +85,7 @@ static int xenpaging_wait_for_event_or_t
     struct pollfd fd[2];
     int port;
     int rc;
+    int timeout;
 
     /* Wait for event channel and xenstore */
     fd[0].fd = xc_evtchn_fd(xce);
@@ -92,7 +93,9 @@ static int xenpaging_wait_for_event_or_t
     fd[1].fd = xs_fileno(paging->xs_handle);
     fd[1].events = POLLIN | POLLERR;
 
-    rc = poll(fd, 2, 100);
+    /* No timeout while page-out is still in progress */
+    timeout = paging->use_poll_timeout ? 100 : 0;
+    rc = poll(fd, 2, timeout);
     if ( rc < 0 )
     {
         if (errno == EINTR)
@@ -134,6 +137,8 @@ static int xenpaging_wait_for_event_or_t
                         if ( target_tot_pages < 0 || target_tot_pages > paging->max_pages )
                             target_tot_pages = paging->max_pages;
                         paging->target_tot_pages = target_tot_pages;
+                        /* Disable poll() delay while new target is not yet reached */
+                        paging->use_poll_timeout = 0;
                         DPRINTF("new target_tot_pages %d\n", target_tot_pages);
                     }
                     free(val);
@@ -985,6 +990,11 @@ int main(int argc, char *argv[])
             }
             resume_pages(paging, num);
         }
+        /* Now target was reached, enable poll() timeout */
+        else
+        {
+            paging->use_poll_timeout = 1;
+        }
 
     }
     DPRINTF("xenpaging got signal %d\n", interrupted);
tools/xenpaging/xenpaging.h +1 -0
diff -r 3a22ed3ec534 -r 3394ca5ef6f7 tools/xenpaging/xenpaging.h
@@ -52,6 +52,7 @@ typedef struct xenpaging {
     int num_paged_out;
     int target_tot_pages;
     int policy_mru_size;
+    int use_poll_timeout;
     int debug;
     unsigned long pagein_queue[XENPAGING_PAGEIN_QUEUE_SIZE];
 } xenpaging_t;