aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenpaging/policy_default.c
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2009-12-17 06:27:55 +0000
committerKeir Fraser <keir.fraser@citrix.com>2009-12-17 06:27:55 +0000
commit287d07f6a7b84d9caf6e734f987a02ef5de7561c (patch)
tree9621123f10a616f72073e5706d1e4fffa17d1889 /tools/xenpaging/policy_default.c
parentc0c8c01d6776b3cb2c42a6a3c82e484992dc9265 (diff)
downloadxen-287d07f6a7b84d9caf6e734f987a02ef5de7561c.tar.gz
xen-287d07f6a7b84d9caf6e734f987a02ef5de7561c.tar.bz2
xen-287d07f6a7b84d9caf6e734f987a02ef5de7561c.zip
User-land tool for memory paging.
This tool will page out the specified number of pages from the specified domain. When a paged out page is accessed, Xen will issue a request and notify the tool over an event channel. The tool will process ther request, page the page in, and notify Xen. The current (default) policy tracks the 1024 most recently paged in pages and will not choose to evict any of those. This is done with the assumption that if a page is accessed, it is likely to be accessed again soon. Signed-off-by: Patrick Colp <Patrick.Colp@citrix.com>
Diffstat (limited to 'tools/xenpaging/policy_default.c')
-rw-r--r--tools/xenpaging/policy_default.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/tools/xenpaging/policy_default.c b/tools/xenpaging/policy_default.c
new file mode 100644
index 0000000000..068b51fb5f
--- /dev/null
+++ b/tools/xenpaging/policy_default.c
@@ -0,0 +1,103 @@
+/******************************************************************************
+ * tools/xenpaging/policy.c
+ *
+ * Xen domain paging default policy.
+ *
+ * Copyright (c) 2009 Citrix (R&D) Inc. (Patrick Colp)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "bitops.h"
+#include "xc.h"
+#include "policy.h"
+
+
+#define MRU_SIZE 1024
+
+
+static unsigned long mru[MRU_SIZE];
+static unsigned int i_mru = 0;
+static unsigned long *bitmap;
+
+
+int policy_init(xenpaging_t *paging)
+{
+ int i;
+ int rc;
+
+ /* Allocate bitmap for pages not to page out */
+ rc = alloc_bitmap(&bitmap, paging->bitmap_size);
+ if ( rc != 0 )
+ goto out;
+
+ /* Initialise MRU list of paged in pages */
+ for ( i = 0; i < MRU_SIZE; i++ )
+ mru[i] = INVALID_MFN;
+
+ /* Don't page out page 0 */
+ set_bit(0, bitmap);
+
+ rc = 0;
+
+ out:
+ return rc;
+}
+
+int policy_choose_victim(xenpaging_t *paging, domid_t domain_id,
+ xenpaging_victim_t *victim)
+{
+ 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;
+ }
+ while ( test_bit(victim->gfn, bitmap) );
+
+ return 0;
+}
+
+void policy_notify_paged_out(domid_t domain_id, unsigned long gfn)
+{
+ set_bit(gfn, bitmap);
+}
+
+void policy_notify_paged_in(domid_t domain_id, unsigned long gfn)
+{
+ 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;
+ i_mru++;
+}
+
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */