]> xenbits.xensource.com Git - people/vhanquez/xen-unstable.git/commitdiff
xenpaging: specify policy mru_size at runtime
authorKeir Fraser <keir@xen.org>
Tue, 11 Jan 2011 10:32:05 +0000 (10:32 +0000)
committerKeir Fraser <keir@xen.org>
Tue, 11 Jan 2011 10:32:05 +0000 (10:32 +0000)
The environment variable XENPAGING_POLICY_MRU_SIZE will change the
mru_size in the policy at runtime.  Specifying the mru_size at runtime
allows the admin to keep more pages in memory so guests can make more
progress.  Its also good for development to reduce the value to put
more pressure on the paging related code paths.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
tools/xenpaging/policy_default.c
tools/xenpaging/xenpaging.c
tools/xenpaging/xenpaging.h

index 2ab96b79c5cb33b8e0127072143f9da62cfaa94a..a53f5560f6224c44380cb389e9fd0965b14d0e2e 100644 (file)
 #include "policy.h"
 
 
-#define MRU_SIZE (1024 * 16)
+#define DEFAULT_MRU_SIZE (1024 * 16)
 
 
-static unsigned long mru[MRU_SIZE];
+static unsigned long *mru;
 static unsigned int i_mru;
+static unsigned int mru_size;
 static unsigned long *bitmap;
 static unsigned long *unconsumed;
 static unsigned long current_gfn;
@@ -57,7 +58,19 @@ int policy_init(xenpaging_t *paging)
     max_pages = paging->domain_info->max_pages;
 
     /* Initialise MRU list of paged in pages */
-    for ( i = 0; i < MRU_SIZE; i++ )
+    if ( paging->policy_mru_size > 0 )
+        mru_size = paging->policy_mru_size;
+    else
+        mru_size = DEFAULT_MRU_SIZE;
+
+    mru = malloc(sizeof(*mru) * mru_size);
+    if ( mru == NULL )
+    {
+        rc = -ENOMEM;
+        goto out;
+    }
+
+    for ( i = 0; i < mru_size; i++ )
         mru[i] = INVALID_MFN;
 
     /* Don't page out page 0 */
@@ -100,12 +113,12 @@ void policy_notify_paged_out(unsigned long gfn)
 
 void policy_notify_paged_in(unsigned long gfn)
 {
-    unsigned long old_gfn = mru[i_mru & (MRU_SIZE - 1)];
+    unsigned long old_gfn = mru[i_mru & (mru_size - 1)];
 
     if ( old_gfn != INVALID_MFN )
         clear_bit(old_gfn, bitmap);
     
-    mru[i_mru & (MRU_SIZE - 1)] = gfn;
+    mru[i_mru & (mru_size - 1)] = gfn;
     i_mru++;
 }
 
index aae30ebfa3e1a3045ccc363e905dbdd09eccc709..dc49dce2e476ae685e6744809c6e47d265d05eb4 100644 (file)
@@ -78,6 +78,7 @@ xenpaging_t *xenpaging_init(domid_t domain_id)
     xenpaging_t *paging;
     xc_interface *xch;
     xentoollog_logger *dbg = NULL;
+    char *p;
     int rc;
 
     if ( getenv("XENPAGING_DEBUG") )
@@ -92,6 +93,13 @@ xenpaging_t *xenpaging_init(domid_t domain_id)
     paging = malloc(sizeof(xenpaging_t));
     memset(paging, 0, sizeof(xenpaging_t));
 
+    p = getenv("XENPAGING_POLICY_MRU_SIZE");
+    if ( p && *p )
+    {
+         paging->policy_mru_size = atoi(p);
+         DPRINTF("Setting policy mru_size to %d\n", paging->policy_mru_size);
+    }
+
     /* Open connection to xen */
     paging->xc_handle = xch;
 
index a6bf556200e193ec89de395db58ddfde9607a92a..f4ebcefca802f99b7c6ecf6ec532a4f3979ef19f 100644 (file)
@@ -45,6 +45,7 @@ typedef struct xenpaging {
     unsigned long *bitmap;
 
     mem_event_t mem_event;
+    int policy_mru_size;
 } xenpaging_t;