tmem: self-ballooning and frontswap-selfshrinking
PATCH v2 1/1 tmem: self-ballooning and frontswap-selfshrinking
Here is V2 of the Xen tmem selfballooning/frontswap-selfshrinking patch for review. Many thanks to the reviewers of the V1 for your excellent comments and feedback.
Major changes since V1 (most suggested by Ian Campbell):
- nearly all code moved from *balloon.c to xen-selfballoon.c
- accounting fixes found by Daniel Kiper
- alternate access to vm_committed_as; now no VM core changes
- macros for repetitive sysfs code
- rebased to 3.0-rc1
- passes checkpatch.pl :-}
This code complements the cleancache and frontswap patchsets to optimize support for Xen Transcendent Memory. The policy it implements is rudimentary, so will almost certainly need to improve over time, but it does work well enough today.
Thanks,
Dan
P.S. Anybody who actually uses this patch is encouraged to read
http://oss.oracle.com/projects/tmem/dist/documentation/internals/linuxpatch
from which the following brief documentation was extracted, which will probably be the git commit comment.
=
[PATCH] [linux-2.6.39.x for xen] tmem: self-ballooning and frontswap-selfshrinking
Selfballooning creates memory pressure by using the Xen balloon driver to decrease and increase available kernel memory, tracking a target value of "Committed_AS" (see /proc/meminfo). Sysfs tunables are provided to adjust the frequency at which memory size is adjusted, the rate at which ballooning is used to approach the target, and to disable selfballooning completely. As of 100827, selfballooning runs in a separate kernel thread, "selfballooning".
Frontswap shrinking accounts for the fact that pages swapped to disk may sit on disk for a very long time, even if very rarely used or if the kernel knows they will never be used again. This is because the kernel need not reclaim disk space because the disk space costs very little and can be overwritten when necessary. When the same pages are in frontswap, however, they are taking up valuable RAM real estate. So when frontswap activity is otherwise stable and the guest kernel is not under memory pressure, the frontswap shrinker removes some pages from frontswap and returns them to kernel memory. Sysfs tunables are provided to adjust the frequency of shrinking opportunities and the shrinking rate, and to create more "inertia".
Diffstat:
drivers/xen/Kconfig | 10 + drivers/xen/Makefile | 1 drivers/xen/xen-balloon.c | 2 drivers/xen/xen-selfballoon.c | 350 ++++++++++++++++++++++++++++++++++++++++++ include/xen/balloon.h | 10 + include/xen/tmem.h | 4 6 files changed, 377 insertions(+)
drivers/xen/Kconfig +10 -0
@@ -9,6 +9,16 @@ 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 y + 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 + 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 +350 -0
350 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 -1 ; +} +#endif
include/xen/tmem.h +4 -0
@@ -0,0 +1,4 @@ +#ifndef _XEN_TMEM_H +#define _XEN_TMEM_H +extern int tmem_enabled; +#endif /* _XEN_TMEM_H */
drivers/xen/Kconfig +10 -0
@@ -9,6 +9,16 @@ 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 y + 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 + 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 +350 -0
350 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 -1 ; +} +#endif
include/xen/tmem.h +4 -0
@@ -0,0 +1,4 @@ +#ifndef _XEN_TMEM_H +#define _XEN_TMEM_H +extern int tmem_enabled; +#endif /* _XEN_TMEM_H */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 21 lines · Dan Magenheimer
Here is V2 of the Xen tmem selfballooning/frontswap-selfshrinking patch for review. Many thanks to the reviewers of the V1 for your excellent comments and feedback.
Major changes since V1 (most suggested by Ian Campbell):
- nearly all code moved from *balloon.c toxen-selfballoon.c
- accounting fixes found by Daniel Kiper
- alternate access tovm_committed_as; now no VM core changes
- macros for repetitive sysfs code
- rebased to 3.0-rc1
- passes checkpatch.pl :-}This code complements the cleancache and frontswap patchsets to optimize support for Xen Transcendent Memory. The policy it implements is rudimentary, so will almost certainly need to improve over time, but it does work well enough today.
Thanks,
Dan
Quoted 8 lines
P.S. Anybody who actually uses this patch is encouraged to read
http://oss.oracle.com/projects/tmem/dist/documentation/internals/linuxpatch
from which the following brief documentation was extracted, which will probably be the git commit comment.=
[PATCH] [linux-2.6.39.x for xen] tmem: self-ballooning and frontswap-selfshrinking
Get rid of the 'linux-2.6.39..'.
Quoted 8 lines
Selfballooning creates memory pressure by using the Xen balloon driver to decrease and increase available kernel memory, tracking a target value of "
Committed_AS" (see/proc/meminfo). Sysfs tunables are provided to adjust the frequency at which memory size is adjusted, the rate at which ballooning is used to approach the target, and to disable selfballooning completely. As of 100827, selfballooning runs in a separate kernel thread, "selfballooning".
As of 100827? That is quite a precise number :-) Is it necccessary to even include this in the patch? It is not like this patch had been in the upstream kernel since 2010. Why not just say:
The kernel thread runs as "seflballooning".
Quoted 10 lines
Frontswap shrinking accounts for the fact that pages swapped to disk may sit on disk for a very long time, even if very rarely used or if the kernel knows they will never be used again. This is because the kernel need not reclaim disk space because the disk space costs very little and can be overwritten when necessary. When the same pages are in frontswap, however, they are taking up valuable RAM real estate. So when frontswap activity is otherwise stable and the guest kernel is not under memory pressure, the frontswap shrinker removes some pages from frontswap and returns them to kernel memory.
OK, and who pokes the shrinker? Is it this patch? If so you might want to mention that? IF not this thread, is the thread just pulling some levers to cause the shrinker to activate?
If it is the first, perhaps a better name is 'shrinker' for the thread? Or 'kick_shrinker' since it would actually use an shrinker API that is widely implemented by other subsystems too.
Quoted 4 lines
Sysfs tunables are provided to adjust the frequency of shrinking opportunities and the shrinking rate, and to create more "inertia".
From the description it sounds like this could be a generic shrinker
thread that is not limited to only frontswap usage pattern?
What are the other "API's that kick the shrinker into action? Would it be worth mentioning them and why they are not suitable or not good enough for this?
Quoted 16 lines
Signed-off-by Dan Magenheimer <[email protected]>Diffstat:
drivers/xen/Kconfig | 10 + drivers/xen/Makefile | 1 drivers/xen/xen-balloon.c | 2 drivers/xen/xen-selfballoon.c | 350 ++++++++++++++++++++++++++++++++++++++++++ include/xen/balloon.h | 10 + include/xen/tmem.h | 4 6 files changed, 377 insertions(+)diff -Napur -X linux-3.0-rc1/Documentation/dontdiff -x
scripts/selinux/mdp/mdplinux-3.0-rc1-frontswap/drivers/xen/Kconfig linux-3.0-rc1-frontswap-selfballoon/drivers/xen/Kconfig
drivers/xen/Kconfig config XEN_BALLOON · line 15
Quoted 7 lines
drivers/xen/Kconfig +4
-0@@ -9,6 +9,16 @@ 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 y
Heheheh.. That needs to be 'n'. But we can fix that in the next posting.
Quoted 69 lines
drivers/xen/Kconfig +6
-0+ 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 + config XEN_SCRUB_PAGES bool "Scrub pages before returning them to system" depends on XEN_BALLOONdiff -Napur -X linux-3.0-rc1/Documentation/dontdiff -x
scripts/selinux/mdp/mdplinux-3.0-rc1-frontswap/drivers/xen/Makefile linux-3.0-rc1-frontswap-selfballoon/drivers/xen/Makefiledrivers/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.odiff -Napur -X linux-3.0-rc1/Documentation/dontdiff -x
scripts/selinux/mdp/mdplinux-3.0-rc1-frontswap/drivers/xen/xen-balloon.clinux-3.0-rc1-frontswap-selfballoon/drivers/xen/xen-balloon.cdrivers/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;diff -Napur -X linux-3.0-rc1/Documentation/dontdiff -x
scripts/selinux/mdp/mdplinux-3.0-rc1-frontswap/drivers/xen/xen-selfballoon.clinux-3.0-rc1-frontswap-selfballoon/drivers/xen/xen-selfballoon.cdrivers/xen/xen-selfballoon.c +33
-0@@ -0,0 +1,350 @@ +/****************************************************************************** +* Xen selfballoon driver +* +* Copyright (c) 2009-2011, Dan Magenheimer, Oracle Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation; or, when distributed +* separately from the Linux kernel or incorporated into other +* software packages, subject to the following license: +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this source file (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, +* merge, publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +*/ + +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/mman.h>
drivers/xen/xen-selfballoon.c line 43
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+ +#include <xen/balloon.h> + +#ifdef CONFIG_FRONTSWAP +#include <linux/frontswap.h> +#endif +#include <xen/tmem.h> + +static int xen_selfballooning_enabled__read_mostly ; +static int use_selfballooning__read_mostly =1 ;
These guys could be in the __initdata section.
drivers/xen/xen-selfballoon.c line 46
Quoted 3 lines
drivers/xen/xen-selfballoon.c +3
-0+static unsigned int selfballoon_interval__read_mostly ; +static unsigned int selfballoon_downhysteresis__read_mostly ; +static unsigned int selfballoon_uphysteresis__read_mostly ;
You should provide a comment explaining what 'up and down' hysteresis means? Is it the watermark level at which point the thread kicks in to action?
Is the interval in seconds? miliseconds? Is the interval how often the thread checks those watermarks values? Perhaps a better name would be selfballoon_wakup_time ?
drivers/xen/xen-selfballoon.c line 49
Quoted 3 lines
drivers/xen/xen-selfballoon.c +3
-0+ +static void selfballoon_process (struct work_struct *work); +DECLARE_DELAYED_WORK (selfballoon_worker, selfballoon_process);
static?
drivers/xen/xen-selfballoon.c line 53
Quoted 4 lines
drivers/xen/xen-selfballoon.c +4
-0+ +#ifdef CONFIG_FRONTSWAP +static bool frontswap_selfshrinking__read_mostly ; +static int use_frontswap_selfshrink__read_mostly =1 ;
__initdata?
drivers/xen/xen-selfballoon.c line 55
Quoted 2 lines
drivers/xen/xen-selfballoon.c +2
-0+static unsigned int frontswap_hysteresis__read_mostly ; +static unsigned int frontswap_inertia__read_mostly ;
Ditto on the explanation. Not sure what 'frontswap_hysterisis' means.
drivers/xen/xen-selfballoon.c line 59
Quoted 4 lines
drivers/xen/xen-selfballoon.c +4
-0+ +#define frontswap_selfshrinking_enabled frontswap_selfshrinking + +static unsigned long frontswap_inertia_counter;
And what is the purpose of this fellow?
drivers/xen/xen-selfballoon.c line 61
Quoted 2 lines
drivers/xen/xen-selfballoon.c +2
-0+ +static void frontswap_selfshrink (void )
Hm, when I saw the name, combined with the #define:
"frontswap_selfshrinking_enabled" I thought this function would return a boolean. But it looks as this function is actually kicking the shrinker in action. Perhaps:
frontswap_shrink_now is a better name?
drivers/xen/xen-selfballoon.c line 65
Quoted 4 lines
drivers/xen/xen-selfballoon.c +4
-0+{ +static unsigned long cur_frontswap_pages; +static unsigned long last_frontswap_pages; +static unsigned long tgt_frontswap_pages;
So you shrunk the 'current', 'target' to something smaller. Why not shrink frontswap too? Say f_swp ?
tgt_fswp_pgs ?
or tgt_frontswap_pgs ?
drivers/xen/xen-selfballoon.c line 74
Quoted 9 lines
drivers/xen/xen-selfballoon.c +9
-0+ +if (!frontswap_selfshrinking) +return ; +if (!frontswap_hysteresis) +return ; + last_frontswap_pages = cur_frontswap_pages; + cur_frontswap_pages =frontswap_curr_pages (); +if (!cur_frontswap_pages || + (cur_frontswap_pages > last_frontswap_pages)) {
Is it possible for cur_frontswap_pages to return -1?
Should the '||' be '&&' ?
drivers/xen/xen-selfballoon.c line 79
Quoted 5 lines
drivers/xen/xen-selfballoon.c +5
-0+ frontswap_inertia_counter = frontswap_inertia; +return ; + } +if (frontswap_inertia_counter && --frontswap_inertia_counter) +return ;
No need for a spinlock on the frontswap_inertia_counter? Is that b/c there is only one caller for this function?
drivers/xen/xen-selfballoon.c line 84
Quoted 5 lines
drivers/xen/xen-selfballoon.c +5
-0+if (cur_frontswap_pages <= frontswap_hysteresis) + tgt_frontswap_pages =0 ; +else + tgt_frontswap_pages = cur_frontswap_pages - + (cur_frontswap_pages / frontswap_hysteresis);
What if frontswap_hysteris is zero?
drivers/xen/xen-selfballoon.c line 94
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+frontswap_shrink (tgt_frontswap_pages); +} + +static int __init no_frontswap_selfshrink_setup (char *s) +{ + use_frontswap_selfshrink =0 ; +return 1 ; +} + +__setup ("noselfshrink" , no_frontswap_selfshrink_setup);
In the patch description it was called 'noselfballooning' ? Which one should it be? [edit: ah, you have another option later on called noselfballooning. you should probably document the noselfshrink somwhere]
drivers/xen/xen-selfballoon.c line 104
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+#else /* !CONFIG_FRONTSWAP */ +static inline void frontswap_selfshrink (void ) +{ +} +#define frontswap_selfshrinking_enabled 0 +#endif + +static void selfballoon_process (struct work_struct *work) +{ +unsigned long cur_pages, goal_pages, tgt_pages;
goal and target sound quite similar. Should tgt be just named 'pages'?
drivers/xen/xen-selfballoon.c line 105
Quoted 1 line
drivers/xen/xen-selfballoon.c +1
-0+int reset_timer =0 ;
How about just using a bool?
drivers/xen/xen-selfballoon.c line 111
Quoted 6 lines
drivers/xen/xen-selfballoon.c +6
-0+ +if (xen_selfballooning_enabled) { + tgt_pages = balloon_stats.current_pages; + cur_pages = balloon_stats.current_pages; + goal_pages =percpu_counter_read_positive (&vm_committed_as) + + balloon_stats.current_pages - totalram_pages;
Hm, you could just reference tgt_pages instead of re-reading the balloon_stats.current_pages as that value might change as you are reading it (since you are not using the balloon spinlock).
Or is that the goal - you are trying to read it to have the latest value? If so, wouldn't it better to take the the balloon spinlock?
Is there any way that goal_pages ends up being negative?
drivers/xen/xen-selfballoon.c line 115
Quoted 4 lines
drivers/xen/xen-selfballoon.c +4
-0+if (cur_pages > goal_pages) + tgt_pages = cur_pages - + ((cur_pages - goal_pages) / + selfballoon_downhysteresis);
What if ..downhysterisis is zero?
drivers/xen/xen-selfballoon.c line 119
Quoted 4 lines
drivers/xen/xen-selfballoon.c +4
-0+else if (cur_pages < goal_pages) + tgt_pages = cur_pages + + ((goal_pages - cur_pages) / + selfballoon_uphysteresis);
Ditto.
No need to check for cur_pages == goal_pages?
Quoted 20 lines
drivers/xen/xen-selfballoon.c +20
-0+balloon_set_new_target (tgt_pages); + reset_timer =1 ; + } +if (frontswap_selfshrinking_enabled) { +frontswap_selfshrink (); + reset_timer =1 ; + } +if (reset_timer) +schedule_delayed_work (&selfballoon_worker, + selfballoon_interval *HZ ); +} + +#ifdef CONFIG_SYSFS +#define SELFBALLOON_SHOW(name, format, args...) \ + static ssize_t show_##name(struct sys_device *dev, \ + struct sysdev_attribute *attr, \ + char *buf) \ + { \ + return sprintf(buf, format, ##args); \ + }
drivers/xen/xen-selfballoon.c line 149
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+ +SELFBALLOON_SHOW (selfballooning,"%d\n" , xen_selfballooning_enabled); + +static ssize_t store_selfballooning (struct sys_device *dev, +struct sysdev_attribute *attr, +const char *buf, +size_t count) +{ +char *endchar; +int was_enabled = xen_selfballooning_enabled;
Make it a bool.
Quoted 18 lines
drivers/xen/xen-selfballoon.c +18
-0+ +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + + xen_selfballooning_enabled = !!memparse (buf, &endchar); + +if (!was_enabled && xen_selfballooning_enabled) +schedule_delayed_work (&selfballoon_worker, + selfballoon_interval *HZ ); + +return count; +} + +static SYSDEV_ATTR(selfballooning, S_IRUGO | S_IWUSR, + show_selfballooning, store_selfballooning); + +SELFBALLOON_SHOW (selfballoon_interval,"%d\n" , selfballoon_interval); +
drivers/xen/xen-selfballoon.c line 177
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+static ssize_t store_selfballoon_interval (struct sys_device *dev, +struct sysdev_attribute *attr, +const char *buf, +size_t count) +{ +char *endchar; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + selfballoon_interval =memparse (buf, &endchar);
No checking to see if the value is out of bounds? Say -1 (well, it would return zero from memparse) so the interval would be set to 0. Is that OK?
Quoted 8 lines
drivers/xen/xen-selfballoon.c +8
-0+return count; +} + +static SYSDEV_ATTR(selfballoon_interval, S_IRUGO | S_IWUSR, + show_selfballoon_interval, store_selfballoon_interval); + +SELFBALLOON_SHOW (selfballoon_downhys,"%d\n" , selfballoon_downhysteresis); +
drivers/xen/xen-selfballoon.c line 195
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+static ssize_t store_selfballoon_downhys (struct sys_device *dev, +struct sysdev_attribute *attr, +const char *buf, +size_t count) +{ +char *endchar; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + selfballoon_downhysteresis =memparse (buf, &endchar);
Ditto. What if I did 'echo -1000 > seflballoon_downhys' .. Then this value ends up being zero and the worker might end up dividing by zero.
Quoted 9 lines
drivers/xen/xen-selfballoon.c +9
-0+return count; +} + +static SYSDEV_ATTR(selfballoon_downhysteresis, S_IRUGO | S_IWUSR, + show_selfballoon_downhys, store_selfballoon_downhys); + + +SELFBALLOON_SHOW (selfballoon_uphys,"%d\n" , selfballoon_uphysteresis); +
drivers/xen/xen-selfballoon.c line 214
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+static ssize_t store_selfballoon_uphys (struct sys_device *dev, +struct sysdev_attribute *attr, +const char *buf, +size_t count) +{ +char *endchar; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + selfballoon_uphysteresis =memparse (buf, &endchar);
Ditto.
Quoted 71 lines
drivers/xen/xen-selfballoon.c +71
-0+return count; +} + +static SYSDEV_ATTR(selfballoon_uphysteresis, S_IRUGO | S_IWUSR, + show_selfballoon_uphys, store_selfballoon_uphys); + +#ifdef CONFIG_FRONTSWAP +SELFBALLOON_SHOW (frontswap_selfshrinking,"%d\n" , frontswap_selfshrinking); + +static ssize_t store_frontswap_selfshrinking (struct sys_device *dev, +struct sysdev_attribute *attr, +const char *buf, +size_t count) +{ +char *endchar; +int was_enabled = frontswap_selfshrinking; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + + frontswap_selfshrinking = !!memparse (buf, &endchar); + +if (!was_enabled && !xen_selfballooning_enabled && + frontswap_selfshrinking) +schedule_delayed_work (&selfballoon_worker, + selfballoon_interval *HZ ); + +return count; +} + +static SYSDEV_ATTR(frontswap_selfshrinking, S_IRUGO | S_IWUSR, + show_frontswap_selfshrinking, store_frontswap_selfshrinking); + +SELFBALLOON_SHOW (frontswap_inertia,"%d\n" , frontswap_inertia); + +static ssize_t store_frontswap_inertia (struct sys_device *dev, +struct sysdev_attribute *attr, +const char *buf, +size_t count) +{ +char *endchar; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + frontswap_inertia =memparse (buf, &endchar); + frontswap_inertia_counter = frontswap_inertia; +return count; +} + +static SYSDEV_ATTR(frontswap_inertia, S_IRUGO | S_IWUSR, + show_frontswap_inertia, store_frontswap_inertia); + +SELFBALLOON_SHOW (frontswap_hysteresis,"%d\n" , frontswap_hysteresis); + +static ssize_t store_frontswap_hysteresis (struct sys_device *dev, +struct sysdev_attribute *attr, +const char *buf, +size_t count) +{ +char *endchar; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + frontswap_hysteresis =memparse (buf, &endchar); +return count; +} + +static SYSDEV_ATTR(frontswap_hysteresis, S_IRUGO | S_IWUSR, + show_frontswap_hysteresis, store_frontswap_hysteresis); + +#endif /* CONFIG_FRONTSWAP */
drivers/xen/xen-selfballoon.c line 295
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,
No NULL at the end?
Quoted 32 lines
drivers/xen/xen-selfballoon.c +32
-0+#endif +}; + +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 =0 ; +return 1 ; +} + +__setup ("noselfballooning" , noselfballooning_setup); + +static int __init xen_selfballoon_init (void ) +{ +if (!xen_domain ()) +return -ENODEV ;
drivers/xen/xen-selfballoon.c line 337
Quoted 10 lines
drivers/xen/xen-selfballoon.c +10
-0+ +pr_info ("xen/balloon: Initializing Xen selfballooning driver.\n" ); +#ifdef CONFIG_FRONTSWAP +pr_info ("xen/balloon: Initializing frontswap selfshrinking driver.\n" ); +#endif + + xen_selfballooning_enabled = tmem_enabled && use_selfballooning; + selfballoon_interval =5 ; + selfballoon_downhysteresis =8 ; + selfballoon_uphysteresis =1 ;
And these values are ... how did you come about them?
drivers/xen/xen-selfballoon.c line 341
Quoted 4 lines
drivers/xen/xen-selfballoon.c +4
-0+#ifdef CONFIG_FRONTSWAP + frontswap_selfshrinking = use_frontswap_selfshrink && frontswap_enabled; + frontswap_hysteresis =20 ; + frontswap_inertia =3 ;
Ditto.
Quoted 30 lines
drivers/xen/xen-selfballoon.c +9
-0+#endif +schedule_delayed_work (&selfballoon_worker, selfballoon_interval *HZ ); + +return 0 ; +} + +subsys_initcall (xen_selfballoon_init); + +MODULE_LICENSE ("GPL" );diff -Napur -X linux-3.0-rc1/Documentation/dontdiff -x
scripts/selinux/mdp/mdplinux-3.0-rc1-frontswap/include/xen/balloon.hlinux-3.0-rc1-frontswap-selfballoon/include/xen/balloon.hinclude/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 -1 ; +} +#endif diff -Napur -X linux-3.0-rc1/Documentation/dontdiff -x
scripts/selinux/mdp/mdplinux-3.0-rc1-frontswap/include/xen/tmem.hlinux-3.0-rc1-frontswap-selfballoon/include/xen/tmem.h
include/xen/tmem.h line 3
Quoted 3 lines
include/xen/tmem.h +3
-0@@ -0,0 +1,4 @@ +#ifndef _XEN_TMEM_H +#define _XEN_TMEM_H +extern int tmem_enabled;
Can you include a comment saying where the 'tmem_enabled' is actuall present? As in in what file?
Quoted 1 line
include/xen/tmem.h +1
-0+#endif /* _XEN_TMEM_H */