Skip to contentSkip to conversation

tmem: self-ballooning and frontswap-selfshrinking

PATCH In review Dan Magenheimer 2 participants 2 messages Jul 5, 2011 – Jul 6, 2011 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 tmem: self-ballooning and frontswap-selfshrinking

Hi Konrad (and other reviewers) --

Here is version 4 of the Xen tmem selfballooning/frontswap-selfshrinking patch. V4 includes the last round of syntactic feedback from Daniel Kiper. I hope V4 is ready for merging as I'm hoping to get this merged for the upcoming 3.1 window.

If it is satisfactory, you may wish to check the commit in my tree:

git://git.kernel.org/pub/scm/linux/kernel/git/djm/tmem.git #xen-tmem-selfballoon-v4

If all looks good and there are no issues raised in the next day or two, you may wish to pull this without a new git-pull request, but I will send another one if you wish; please let me know.

A reminder that this patch has a slight build dependency on a previous commit:

afec6e04922d0c8c7e244be2e544bac5e7e36294 xen: prepare tmem shim to handle frontswap

in your devel/next-3.0 branch (because tmem_enabled is EXPORT_SYM'ed in that commit and extern'ed in a file in this commit). I don't think this is a problem as you've already pushed that commit to linux-next, but am noting the dependency in case some kind of commit reordering were to occur.

---

Quoted 1 line

From: Dan Magenheimer <[email protected]>

Subject: xen: tmem: self-ballooning and frontswap-selfshrinking

This patch introduces two in-kernel drivers for Xen transcendent memory ("tmem") functionality that complement cleancache and frontswap. Both use control theory to dynamically adjust and optimize memory utilization. Selfballooning controls the in-kernel Xen balloon driver, targeting a goal value (vm_committed_as), thus pushing less frequently used clean page cache pages (through the cleancache code) into Xen tmem where Xen can balance needs across all VMs residing on the physical machine. Frontswap-selfshrinking controls the number of pages in frontswap, driving it towards zero (effectively doing a partial swapoff) when in-kernel memory pressure subsides, freeing up RAM for other VMs.

More detail is provided in the header comment of xen-selfballooning.c.

[v4: [email protected]: use strict_strtoul plus a few syntactic nits]
[v3: [email protected]: fix potential divides-by-zero]
[v3: [email protected]: add many more comments, fix nits]
[v2: rebased to linux-3.0-rc1]
[v2: [email protected]: reorganize as new file (xen-selfballoon.c)]
[v2: [email protected]: proper access to vm_committed_as]
[v2: [email protected]: accounting fixes]
Cc Jan Beulich <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>

---

Diffstat:

 drivers/xen/Kconfig            |   12 
 drivers/xen/Makefile           |    1 
 drivers/xen/xen-balloon.c      |    2 
 drivers/xen/xen-selfballoon.c  |  439 +++++++++++++++++++++++++++++++
 include/xen/balloon.h          |   10 
 include/xen/tmem.h             |    5 
 6 files changed, 469 insertions(+)
drivers/xen/Kconfig +12 -0
diff -Napur linux-3.0-rc1-frontswap/drivers/xen/Kconfig linux-3.0-rc1-frontswap-selfballoon/drivers/xen/Kconfig
@@ -9,6 +9,18 @@ config XEN_BALLOON
 	  the system to expand the domain's memory allocation, or alternatively
 	  return unneeded memory to the system.
 
+config XEN_SELFBALLOONING
+	bool "dynamically self-balloon kernel memory to target"
+	depends on XEN && XEN_BALLOON && CLEANCACHE
+	default n
+	help
+	  Self-ballooning dynamically balloons available kernel memory driven
+	  by the current usage of anonymous memory ("committed AS") and
+	  controlled by various sysfs-settable parameters.  May be overridden
+	  by the noselfballooning kernel boot parameter.  If FRONTSWAP
+	  is configured, also enables frontswap-selfshrinking, which can be
+	  overridden by the noselfshrink kernel boot paramater.
+
 config XEN_SCRUB_PAGES
 	bool "Scrub pages before returning them to system"
 	depends on XEN_BALLOON
drivers/xen/Makefile +1 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/drivers/xen/Makefile linux-3.0-rc1-frontswap-selfballoon/drivers/xen/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_BLOCK)			+= biomerge.o
 obj-$(CONFIG_HOTPLUG_CPU)		+= cpu_hotplug.o
 obj-$(CONFIG_XEN_XENCOMM)		+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)		+= xen-balloon.o
+obj-$(CONFIG_XEN_SELFBALLOONING)	+= xen-selfballoon.o
 obj-$(CONFIG_XEN_DEV_EVTCHN)		+= xen-evtchn.o
 obj-$(CONFIG_XEN_GNTDEV)		+= xen-gntdev.o
 obj-$(CONFIG_XEN_GRANT_DEV_ALLOC)	+= xen-gntalloc.o
drivers/xen/xen-balloon.c +2 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/drivers/xen/xen-balloon.c linux-3.0-rc1-frontswap-selfballoon/drivers/xen/xen-balloon.c
@@ -98,6 +98,8 @@ static int __init balloon_init(void)
 
 	register_balloon(&balloon_sysdev);
 
+	register_xen_selfballooning(&balloon_sysdev);
+
 	target_watch.callback = watch_target;
 	xenstore_notifier.notifier_call = balloon_init_watcher;
 
drivers/xen/xen-selfballoon.c +439 -0

439 lines not on this page · raw message

include/xen/balloon.h +10 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/include/xen/balloon.h linux-3.0-rc1-frontswap-selfballoon/include/xen/balloon.h
@@ -23,3 +23,13 @@ void balloon_set_new_target(unsigned lon
 
 int alloc_xenballooned_pages(int nr_pages, struct page** pages);
 void free_xenballooned_pages(int nr_pages, struct page** pages);
+
+struct sys_device;
+#ifdef CONFIG_XEN_SELFBALLOONING
+extern int register_xen_selfballooning(struct sys_device *sysdev);
+#else
+static inline int register_xen_selfballooning(struct sys_device *sysdev)
+{
+	return -ENOSYS;
+}
+#endif
include/xen/tmem.h +5 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/include/xen/tmem.h linux-3.0-rc1-frontswap-selfballoon/include/xen/tmem.h
@@ -0,0 +1,5 @@
+#ifndef _XEN_TMEM_H
+#define _XEN_TMEM_H
+/* defined in drivers/xen/tmem.c */
+extern int tmem_enabled;
+#endif /* _XEN_TMEM_H */

From: Dan Magenheimer <[email protected]>
Subject: xen: tmem: self-ballooning and frontswap-selfshrinking

This patch introduces two in-kernel drivers for Xen transcendent memory ("tmem") functionality that complement cleancache and frontswap. Both use control theory to dynamically adjust and optimize memory utilization. Selfballooning controls the in-kernel Xen balloon driver, targeting a goal value (vm_committed_as), thus pushing less frequently used clean page cache pages (through the cleancache code) into Xen tmem where Xen can balance needs across all VMs residing on the physical machine. Frontswap-selfshrinking controls the number of pages in frontswap, driving it towards zero (effectively doing a partial swapoff) when in-kernel memory pressure subsides, freeing up RAM for other VMs.

More detail is provided in the header comment of xen-selfballooning.c.

[v4: [email protected]: use strict_strtoul plus a few syntactic nits]
[v3: [email protected]: fix potential divides-by-zero]
[v3: [email protected]: add many more comments, fix nits]
[v2: rebased to linux-3.0-rc1]
[v2: [email protected]: reorganize as new file (xen-selfballoon.c)]
[v2: [email protected]: proper access to vm_committed_as]
[v2: [email protected]: accounting fixes]
Cc Jan Beulich <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>

---

Diffstat:

 drivers/xen/Kconfig            |   12 
 drivers/xen/Makefile           |    1 
 drivers/xen/xen-balloon.c      |    2 
 drivers/xen/xen-selfballoon.c  |  439 +++++++++++++++++++++++++++++++
 include/xen/balloon.h          |   10 
 include/xen/tmem.h             |    5 
 6 files changed, 469 insertions(+)
drivers/xen/Kconfig +12 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/drivers/xen/Kconfig linux-3.0-rc1-frontswap-selfballoon/drivers/xen/Kconfig
@@ -9,6 +9,18 @@ config XEN_BALLOON
 	  the system to expand the domain's memory allocation, or alternatively
 	  return unneeded memory to the system.
 
+config XEN_SELFBALLOONING
+	bool "dynamically self-balloon kernel memory to target"
+	depends on XEN && XEN_BALLOON && CLEANCACHE
+	default n
+	help
+	  Self-ballooning dynamically balloons available kernel memory driven
+	  by the current usage of anonymous memory ("committed AS") and
+	  controlled by various sysfs-settable parameters.  May be overridden
+	  by the noselfballooning kernel boot parameter.  If FRONTSWAP
+	  is configured, also enables frontswap-selfshrinking, which can be
+	  overridden by the noselfshrink kernel boot paramater.
+
 config XEN_SCRUB_PAGES
 	bool "Scrub pages before returning them to system"
 	depends on XEN_BALLOON
drivers/xen/Makefile +1 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/drivers/xen/Makefile linux-3.0-rc1-frontswap-selfballoon/drivers/xen/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_BLOCK)			+= biomerge.o
 obj-$(CONFIG_HOTPLUG_CPU)		+= cpu_hotplug.o
 obj-$(CONFIG_XEN_XENCOMM)		+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)		+= xen-balloon.o
+obj-$(CONFIG_XEN_SELFBALLOONING)	+= xen-selfballoon.o
 obj-$(CONFIG_XEN_DEV_EVTCHN)		+= xen-evtchn.o
 obj-$(CONFIG_XEN_GNTDEV)		+= xen-gntdev.o
 obj-$(CONFIG_XEN_GRANT_DEV_ALLOC)	+= xen-gntalloc.o
drivers/xen/xen-balloon.c +2 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/drivers/xen/xen-balloon.c linux-3.0-rc1-frontswap-selfballoon/drivers/xen/xen-balloon.c
@@ -98,6 +98,8 @@ static int __init balloon_init(void)
 
 	register_balloon(&balloon_sysdev);
 
+	register_xen_selfballooning(&balloon_sysdev);
+
 	target_watch.callback = watch_target;
 	xenstore_notifier.notifier_call = balloon_init_watcher;
 
drivers/xen/xen-selfballoon.c +439 -0

439 lines not on this page · raw message

include/xen/balloon.h +10 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/include/xen/balloon.h linux-3.0-rc1-frontswap-selfballoon/include/xen/balloon.h
@@ -23,3 +23,13 @@ void balloon_set_new_target(unsigned lon
 
 int alloc_xenballooned_pages(int nr_pages, struct page** pages);
 void free_xenballooned_pages(int nr_pages, struct page** pages);
+
+struct sys_device;
+#ifdef CONFIG_XEN_SELFBALLOONING
+extern int register_xen_selfballooning(struct sys_device *sysdev);
+#else
+static inline int register_xen_selfballooning(struct sys_device *sysdev)
+{
+	return -ENOSYS;
+}
+#endif
include/xen/tmem.h +5 -0
diff -Napur -X linux-3.0-rc1/Documentation/dontdiff linux-3.0-rc1-frontswap/include/xen/tmem.h linux-3.0-rc1-frontswap-selfballoon/include/xen/tmem.h
@@ -0,0 +1,5 @@
+#ifndef _XEN_TMEM_H
+#define _XEN_TMEM_H
+/* defined in drivers/xen/tmem.c */
+extern int tmem_enabled;
+#endif /* _XEN_TMEM_H */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 1 line · Dan Magenheimer

Hi Konrad (and other reviewers) --

Hey Dan,

Only got two comments.

drivers/xen/xen-selfballoon.c line 383

Quoted 10 lines
drivers/xen/xen-selfballoon.c +10 -0
+static struct attribute *selfballoon_attrs[] = {
+	&attr_selfballooning.attr,
+	&attr_selfballoon_interval.attr,
+	&attr_selfballoon_downhysteresis.attr,
+	&attr_selfballoon_uphysteresis.attr,
+#ifdef CONFIG_FRONTSWAP
+	&attr_frontswap_selfshrinking.attr,
+	&attr_frontswap_hysteresis.attr,
+	&attr_frontswap_inertia.attr,
+#endif

You are still missing the 'NULL' here.

Quoted 32 lines
drivers/xen/xen-selfballoon.c +32 -0
+};
+
+static struct attribute_group selfballoon_group = {
+	.name = "selfballoon",
+	.attrs = selfballoon_attrs
+};
+#endif
+
+int register_xen_selfballooning(struct sys_device *sysdev)
+{
+	int error = -1;
+
+#ifdef CONFIG_SYSFS
+	error = sysfs_create_group(&sysdev->kobj, &selfballoon_group);
+#endif
+	return error;
+}
+EXPORT_SYMBOL(register_xen_selfballooning);
+
+static int __init noselfballooning_setup(char *s)
+{
+	use_selfballooning = false;
+	return 1;
+}
+
+__setup("noselfballooning", noselfballooning_setup);
+
+/*
+ * the default values for the various parameters were deemed reasonable
+ * by experimentation, may be workload-dependent, and can all be
+ * adjusted via sysfs
+ */

drivers/xen/xen-selfballoon.c line 425

Quoted 10 lines
drivers/xen/xen-selfballoon.c +10 -0
+static int __init xen_selfballoon_init(void)
+{
+	if (!xen_domain())
+		return -ENODEV;
+
+	pr_info("xen/balloon: Initializing Xen selfballooning driver.\n");
+	xen_selfballooning_enabled = tmem_enabled && use_selfballooning;
+	selfballoon_interval = 5;
+	selfballoon_downhysteresis = 8;
+	selfballoon_uphysteresis = 1;

I think those hysteris values can be set at the top of the file.

Quoted 5 lines
drivers/xen/xen-selfballoon.c +5 -0
+#ifdef CONFIG_FRONTSWAP
+	pr_info("xen/balloon: Initializing frontswap selfshrinking driver.\n");
+	frontswap_selfshrinking = use_frontswap_selfshrink && frontswap_enabled;
+	frontswap_hysteresis = 20;
+	frontswap_inertia = 3;