tmem: self-ballooning and frontswap-selfshrinking
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.
---
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
@@ -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
@@ -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
@@ -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
@@ -23,3 +23,13 @@ void balloon_set_new_target(unsigned lonint 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
@@ -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.
---
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
@@ -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
@@ -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
@@ -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
@@ -23,3 +23,13 @@ void balloon_set_new_target(unsigned lonint 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
@@ -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
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 ;