# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1261031277 0
# Node ID 1b81d0607af90b33ae80232855afc68eefce94d0
# Parent 617071a8c6387a5414e22869cce585811ae27e77
Maintains/cleans-up the sharing map. At the moment a simple FIFO policy is
applied.
Signed-off-by: Grzegorz Milos <Grzegorz.Milos@xxxxxxxxxx>
---
tools/memshr/Makefile | 2
tools/memshr/bidir-daemon.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
tools/memshr/bidir-daemon.h | 25 ++++++++++++
tools/memshr/interface.c | 4 +
4 files changed, 120 insertions(+)
diff -r 617071a8c638 -r 1b81d0607af9 tools/memshr/Makefile
--- a/tools/memshr/Makefile Thu Dec 17 06:27:57 2009 +0000
+++ b/tools/memshr/Makefile Thu Dec 17 06:27:57 2009 +0000
@@ -17,10 +17,12 @@ DEPS = .*.d
LIB-SRCS := interface.c
LIB-SRCS += shm.c
+LIB-SRCS += bidir-daemon.c
LIB-SRCS += bidir-hash.c
LIB-OBJS := interface.o
LIB-OBJS += shm.o
+LIB-OBJS += bidir-daemon.o
LIB-OBJS += bidir-hash-fgprtshr.o
LIB-OBJS += bidir-hash-blockshr.o
diff -r 617071a8c638 -r 1b81d0607af9 tools/memshr/bidir-daemon.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/memshr/bidir-daemon.c Thu Dec 17 06:27:57 2009 +0000
@@ -0,0 +1,89 @@
+/******************************************************************************
+ *
+ * Copyright (c) 2009 Citrix (R&D) Inc. (Grzegorz Milos)
+ *
+ * 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 <pthread.h>
+#include <inttypes.h>
+
+#include "bidir-hash.h"
+#include "memshr-priv.h"
+
+static struct blockshr_hash *blks_hash;
+
+void* bidir_daemon(void *unused)
+{
+ uint32_t nr_ent, max_nr_ent, tab_size, max_load, min_load;
+ static uint64_t shrhnd = 1;
+
+ while(1)
+ {
+ blockshr_hash_sizes( blks_hash,
+ &nr_ent,
+ &max_nr_ent,
+ &tab_size,
+ &max_load,
+ &min_load);
+ /* Remove some hints as soon as we get to 90% capacity */
+ if(10 * nr_ent > 9 * max_nr_ent)
+ {
+ uint64_t next_remove = shrhnd;
+ int to_remove;
+ int ret;
+
+ to_remove = 0.1 * max_nr_ent;
+ while(to_remove > 0)
+ {
+ ret = blockshr_shrhnd_remove(blks_hash, next_remove, NULL);
+ if(ret < 0)
+ {
+ /* We failed to remove an entry, because of a serious hash
+ * table error */
+ DPRINTF("Could not remove handle %"PRId64", error: %d\n",
+ next_remove, ret);
+ /* Force to exit the loop early */
+ to_remove = 0;
+ } else
+ if(ret > 0)
+ {
+ /* Managed to remove the entry. Note next_remove not
+ * incremented, in case there are duplicates */
+ shrhnd = next_remove;
+ to_remove--;
+ } else
+ {
+ /* Failed to remove, because there is no such handle */
+ next_remove++;
+ }
+ }
+ }
+
+ sleep(1);
+ }
+}
+
+void bidir_daemon_launch(void)
+{
+ pthread_t thread;
+
+ pthread_create(&thread, NULL, bidir_daemon, NULL);
+}
+
+void bidir_daemon_initialize(struct blockshr_hash *blks)
+{
+ blks_hash = blks;
+ bidir_daemon_launch();
+}
diff -r 617071a8c638 -r 1b81d0607af9 tools/memshr/bidir-daemon.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/memshr/bidir-daemon.h Thu Dec 17 06:27:57 2009 +0000
@@ -0,0 +1,25 @@
+/******************************************************************************
+ *
+ * Copyright (c) 2009 Citrix (R&D) Inc. (Grzegorz Milos)
+ *
+ * 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
+ */
+
+#ifndef __BIDIR_DAEMON_H__
+#define __BIDIR_DAEMON_H__
+
+void bidir_daemon_initialize(struct blockshr_hash *blks);
+
+#endif /* __BIDIR_DAEMON_H__ */
diff -r 617071a8c638 -r 1b81d0607af9 tools/memshr/interface.c
--- a/tools/memshr/interface.c Thu Dec 17 06:27:57 2009 +0000
+++ b/tools/memshr/interface.c Thu Dec 17 06:27:57 2009 +0000
@@ -23,6 +23,7 @@
#include "memshr-priv.h"
#include "bidir-hash.h"
#include "shm.h"
+#include "bidir-daemon.h"
typedef struct {
int enabled;
@@ -32,6 +33,7 @@ typedef struct {
memshr_vbd_info_t vbd_info = {0, DOMID_INVALID};
+
typedef struct {
struct shared_memshr_info *shared_info;
struct fgprtshr_hash *fgprts;
@@ -73,6 +75,8 @@ void memshr_daemon_initialize(void)
return;
}
memshr.shared_info->blockshr_hash_inited = 1;
+
+ bidir_daemon_initialize(memshr.blks);
}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|