Skip to content

Commit

Permalink
xen/balloon: don't online new memory initially
Browse files Browse the repository at this point in the history
When setting up the Xenstore watch for the memory target size the new
watch will fire at once. Don't try to reach the configured target size
by onlining new memory in this case, as the current memory size will
be smaller in almost all cases due to e.g. BIOS reserved pages.

Onlining new memory will lead to more problems e.g. undesired conflicts
with NVMe devices meant to be operated as block devices.

Instead remember the difference between target size and current size
when the watch fires for the first time and apply it to any further
size changes, too.

In order to avoid races between balloon.c and xen-balloon.c init calls
do the xen-balloon.c initialization from balloon.c.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
  • Loading branch information
jgross1 committed Jul 23, 2017
1 parent c185dde commit 96edd61
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions drivers/xen/balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ static int __init balloon_init(void)
}
#endif

/* Init the xen-balloon driver. */
xen_balloon_init();

return 0;
}
subsys_initcall(balloon_init);
22 changes: 12 additions & 10 deletions drivers/xen/xen-balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static void watch_target(struct xenbus_watch *watch,
{
unsigned long long new_target;
int err;
static bool watch_fired;
static long target_diff;

err = xenbus_scanf(XBT_NIL, "memory", "target", "%llu", &new_target);
if (err != 1) {
Expand All @@ -69,7 +71,14 @@ static void watch_target(struct xenbus_watch *watch,
/* The given memory/target value is in KiB, so it needs converting to
* pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10.
*/
balloon_set_new_target(new_target >> (PAGE_SHIFT - 10));
new_target >>= PAGE_SHIFT - 10;
if (watch_fired) {
balloon_set_new_target(new_target - target_diff);
return;
}

watch_fired = true;
target_diff = new_target - balloon_stats.target_pages;
}
static struct xenbus_watch target_watch = {
.node = "memory/target",
Expand All @@ -94,22 +103,15 @@ static struct notifier_block xenstore_notifier = {
.notifier_call = balloon_init_watcher,
};

static int __init balloon_init(void)
void xen_balloon_init(void)
{
if (!xen_domain())
return -ENODEV;

pr_info("Initialising balloon driver\n");

register_balloon(&balloon_dev);

register_xen_selfballooning(&balloon_dev);

register_xenstore_notifier(&xenstore_notifier);

return 0;
}
subsys_initcall(balloon_init);
EXPORT_SYMBOL_GPL(xen_balloon_init);

#define BALLOON_SHOW(name, format, args...) \
static ssize_t show_##name(struct device *dev, \
Expand Down
8 changes: 8 additions & 0 deletions include/xen/balloon.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ static inline int register_xen_selfballooning(struct device *dev)
return -ENOSYS;
}
#endif

#ifdef CONFIG_XEN_BALLOON
void xen_balloon_init(void);
#else
static inline void xen_balloon_init(void)
{
}
#endif

0 comments on commit 96edd61

Please sign in to comment.