xen/balloon: add late_initcall_sync() for initial ballooning done
Subsystems (2)
Juergen Gross
maintainerPATCH v3 1/1 xen/balloon: add late_initcall_sync() for initial ballooning done
When running as PVH or HVM guest with actual memory < max memory the hypervisor is using "populate on demand" in order to allow the guest to balloon down from its maximum memory size. For this to work correctly the guest must not touch more memory pages than its target memory size as otherwise the PoD cache will be exhausted and the guest is crashed as a result of that.
In extreme cases ballooning down might not be finished today before the init process is started, which can consume lots of memory.
In order to avoid random boot crashes in such cases, add a late init call to wait for ballooning down having finished for PVH/HVM guests.
Warn on console if initial ballooning fails, panic() after stalling for more than 3 minutes per default. Add a module parameter for changing this timeout.
---
V2:
- add warning and panic() when stalling (Marek Marczykowski-Górecki)
- don't wait if credit > 0
V3:
- issue warning only after ballooning failed (Marek Marczykowski-Górecki)
- make panic() timeout configurable via parameter
--- .../stable/sysfs-devices-system-xen_memory | 10 +++ drivers/xen/balloon.c | 63 +++++++++++++++---- drivers/xen/xen-balloon.c | 2 + include/xen/balloon.h | 1 + 4 files changed, 63 insertions(+), 13 deletions(-)
Documentation/ABI/stable/sysfs-devices-system-xen_memory +10 -0
@@ -84,3 +84,13 @@ Description: Control scrubbing pages before returning them to Xen for others domains use. Can be set with xen_scrub_pages cmdline parameter. Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT. + +What: /sys/devices/system/xen_memory/xen_memory0/boot_timeout +Date: November 2021 +KernelVersion: 5.16 +Contact: [email protected] +Description: + The time (in seconds) to wait before giving up to boot in case + initial ballooning fails to free enough memory. Applies only + when running as HVM or PVH guest and started with less memory + configured than allowed at max.
drivers/xen/balloon.c +50 -13
122 lines not on this page · raw message
drivers/xen/xen-balloon.c +2 -0
@@ -150,6 +150,7 @@ static DEVICE_ULONG_ATTR(schedule_delay, 0444, balloon_stats.schedule_delay); static DEVICE_ULONG_ATTR(max_schedule_delay, 0644, balloon_stats.max_schedule_delay); static DEVICE_ULONG_ATTR(retry_count, 0444, balloon_stats.retry_count); static DEVICE_ULONG_ATTR(max_retry_count, 0644, balloon_stats.max_retry_count); +static DEVICE_ULONG_ATTR(boot_timeout, 0644, balloon_stats.boot_timeout); static DEVICE_BOOL_ATTR(scrub_pages, 0644, xen_scrub_pages); static ssize_t target_kb_show(struct device *dev, struct device_attribute *attr,
@@ -211,6 +212,7 @@ static struct attribute *balloon_attrs[] = { &dev_attr_max_schedule_delay.attr.attr, &dev_attr_retry_count.attr.attr, &dev_attr_max_retry_count.attr.attr, + &dev_attr_boot_timeout.attr.attr, &dev_attr_scrub_pages.attr.attr, NULL };
include/xen/balloon.h +1 -0
@@ -20,6 +20,7 @@ struct balloon_stats {unsigned long max_schedule_delay;unsigned long retry_count;unsigned long max_retry_count; +unsigned long boot_timeout; };extern struct balloon_stats balloon_stats;
Signature · 1 line
2.26.2
Quoted 6 lines · Juergen Gross
Documentation/ABI/stable/sysfs-devices-system-xen_memory +0
-0@@ -84,3 +84,13 @@ Description: Control scrubbing pages before returning them to Xen for others domains use. Can be set with xen_scrub_pages cmdline parameter. Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT.
Documentation/ABI/stable/sysfs-devices-system-xen_memory Description: · line 96
Quoted 10 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +10
-0+ +What: /sys/devices/system/xen_memory/xen_memory0/boot_timeout +Date: November 2021 +KernelVersion: 5.16 +Contact: [email protected] +Description: + The time (in seconds) to wait before giving up to boot in case + initial ballooning fails to free enough memory. Applies only + when running as HVM or PVH guest and started with less memory + configured than allowed at max.
How is this going to be used? We only need this during boot.
Documentation/ABI/stable/sysfs-devices-system-xen_memory
Quoted 3 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +1
-1- state = update_schedule(state); + balloon_state = update_schedule(balloon_state);
Now that balloon_state has whole file scope it can probably be updated inside update_schedule().
Documentation/ABI/stable/sysfs-devices-system-xen_memory
Quoted 6 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +6
-0+ while ((credit = current_credit()) < 0) { + if (credit != last_credit) { + last_changed = jiffies; + last_credit = credit; + } + if (balloon_state == BP_ECANCELED) {
What about other states? We are really waiting for BP_DONE, aren't we?
-boris
Quoted 7 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +7
-0+ pr_warn_once("Initial ballooning failed, %ld pages need to be freed.\n", + -credit); + if (jiffies - last_changed >= + HZ * balloon_stats.boot_timeout) + panic("Initial ballooning failed!\n"); + } +
Quoted 30 lines · Boris Ostrovsky
Quoted 6 lines · Juergen Gross
Documentation/ABI/stable/sysfs-devices-system-xen_memory +0
-0@@ -84,3 +84,13 @@ Description: Control scrubbing pages before returning them to Xen for others domains use. Can be set with xen_scrub_pages cmdline parameter. Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT.Documentation/ABI/stable/sysfs-devices-system-xen_memory Description: · line 96
Quoted 10 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +10
-0+ +What: /sys/devices/system/xen_memory/xen_memory0/boot_timeout +Date: November 2021 +KernelVersion: 5.16 +Contact: [email protected] +Description: + The time (in seconds) to wait before giving up to boot in case + initial ballooning fails to free enough memory. Applies only + when running as HVM or PVH guest and started with less memory + configured than allowed at max.How is this going to be used? We only need this during boot.
Documentation/ABI/stable/sysfs-devices-system-xen_memory
Quoted 2 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +1
-1- state = update_schedule(state); + balloon_state = update_schedule(balloon_state);Now that
balloon_statehas whole file scope it can probably be updated insideupdate_schedule().
Quoted 9 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory
Quoted 6 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +6
-0+ while ((credit = current_credit()) < 0) { + if (credit != last_credit) { + last_changed = jiffies; + last_credit = credit; + } + if (balloon_state == BP_ECANCELED) {What about other states? We are really waiting for
BP_DONE, aren't we?
BP_DONE is set also as an intermediate step:
balloon_state = decrease_reservation(n_pages,
GFP_BALLOON);
if (balloon_state == BP_DONE && n_pages != -credit &&
n_pages < totalreserve_pages)
balloon_state = BP_EAGAIN;It would be bad to finish waiting in this case.
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Quoted 38 lines · Marek Marczykowski-Górecki
Quoted 27 lines · Boris Ostrovsky
Quoted 6 lines · Juergen Gross
Documentation/ABI/stable/sysfs-devices-system-xen_memory +0
-0@@ -84,3 +84,13 @@ Description: Control scrubbing pages before returning them to Xen for others domains use. Can be set with xen_scrub_pages cmdline parameter. Default value controlled with CONFIG_XEN_SCRUB_PAGES_DEFAULT.Documentation/ABI/stable/sysfs-devices-system-xen_memory Description: · line 96
Quoted 10 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +10
-0+ +What: /sys/devices/system/xen_memory/xen_memory0/boot_timeout +Date: November 2021 +KernelVersion: 5.16 +Contact: [email protected] +Description: + The time (in seconds) to wait before giving up to boot in case + initial ballooning fails to free enough memory. Applies only + when running as HVM or PVH guest and started with less memory + configured than allowed at max.How is this going to be used? We only need this during boot.
Documentation/ABI/stable/sysfs-devices-system-xen_memory
Quoted 2 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +1
-1- state = update_schedule(state); + balloon_state = update_schedule(balloon_state);Now that
balloon_statehas whole file scope it can probably be updated insideupdate_schedule().Quoted 8 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory
Quoted 6 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +6
-0+ while ((credit = current_credit()) < 0) { + if (credit != last_credit) { + last_changed = jiffies; + last_credit = credit; + } + if (balloon_state == BP_ECANCELED) {What about other states? We are really waiting for
BP_DONE, aren't we?
BP_DONEis set also as an intermediate step:
Quoted 7 lines
balloon_state = decrease_reservation(n_pages, GFP_BALLOON); if (balloon_state == BP_DONE && n_pages != -credit && n_pages < totalreserve_pages) balloon_state = BP_EAGAIN;It would be bad to finish waiting in this case.
RIght, but if we were to say 'if (balloon_state != BP_DONE)' the worst that can happen is that we will continue on to the next iteration without warning and/or panicing. Of course, there is a chance thaton the next iteration the same thing will happen but I think chances of hitting this race every time are infinitely low. We can also check for current_credit() again.
The question is whether we do want to continue waiting if we are in BP_AGAIN. I don't think BP_WAIT is possible in this case although this may change in the future and we will forget to update this code.
-boris
Juergen Gross
maintainerQuoted 48 lines · Boris Ostrovsky
Quoted 46 lines · Marek Marczykowski-Górecki
Quoted 27 lines · Boris Ostrovsky
Quoted 6 lines · Juergen Gross
Documentation/ABI/stable/sysfs-devices-system-xen_memory +0
-0@@ -84,3 +84,13 @@ Description:Control scrubbing pages before returning them to Xen for others domains use. Can be set with
xen_scrub_pagescmdline
parameter. Default value controlled withCONFIG_XEN_SCRUB_PAGES_DEFAULT.Documentation/ABI/stable/sysfs-devices-system-xen_memory Description: · line 96
Quoted 10 lines
Documentation/ABI/stable/sysfs-devices-system-xen_memory +10
-0+ +What: /sys/devices/system/xen_memory/xen_memory0/boot_timeout +Date: November 2021 +KernelVersion: 5.16 +Contact: [email protected] +Description: + The time (in seconds) to wait before giving up to boot in case + initial ballooning fails to free enough memory. Applies only + when running as HVM or PVH guest and started with less memory + configured than allowed at max.How is this going to be used? We only need this during boot.
Quoted 2 lines
- state =
update_schedule(state);
+balloon_state=update_schedule(balloon_state);Now that
balloon_statehas whole file scope it can probably be updated insideupdate_schedule().Quoted 8 lines
Quoted 6 lines
+ while ((credit =
current_credit()) < 0) {
+ if (credit !=last_credit) {
+last_changed= jiffies;
+last_credit= credit;
+ }
+ if (balloon_state==BP_ECANCELED) {What about other states? We are really waiting for
BP_DONE, aren't we?
BP_DONEis set also as an intermediate step:
balloon_state= decrease_reservation(n_pages,
GFP_BALLOON);
if (balloon_state==BP_DONE&&n_pages!= -credit &&
n_pages<totalreserve_pages)balloon_state=BP_EAGAIN;
Quoted 7 lines
Quoted 1 line
It would be bad to finish waiting in this case.
RIght, but if we were to say 'if (
balloon_state!=BP_DONE)' the worst that can happen is that we will continue on to the next iteration without warning and/or panicing. Of course, there is a chance thaton the next iteration the same thing will happen but I think chances of hitting this race every time are infinitely low. We can also check forcurrent_credit()again.The question is whether we do want to continue waiting if we are in
BP_AGAIN. I don't thinkBP_WAITis possible in this case although this may change in the future and we will forget to update this code.
BP_EAGAIN should not stop waiting, as it might be intermediate in case some caches or buffers are freed.
Juergen
Juergen Gross
maintainerQuoted 13 lines · Boris Ostrovsky
Quoted 11 lines · Juergen Gross
Documentation/ABI/stable/sysfs-devices-system-xen_memory +0
-0@@ -84,3 +84,13 @@ Description:Control scrubbing pages before returning them to Xen for others domains use. Can be set with
xen_scrub_pagescmdline
parameter. Default value controlled withCONFIG_XEN_SCRUB_PAGES_DEFAULT.Documentation/ABI/stable/sysfs-devices-system-xen_memory +5
-0+ +What: /sys/devices/system/xen_memory/xen_memory0/boot_timeout +Date: November 2021 +KernelVersion: 5.16 +Contact: [email protected]
Quoted 8 lines
Quoted 5 lines
+Description:
+ The time (in seconds) to wait before giving up to boot in case + initial ballooning fails to free enough memory. Applies only + when running as HVM or PVH guest and started with less memory + configured than allowed at max.How is this going to be used? We only need this during boot.
Of course. Will switch to module_param().
Quoted 5 lines
Quoted 2 lines
- state =
update_schedule(state);
+balloon_state=update_schedule(balloon_state);Now that
balloon_statehas whole file scope it can probably be updated insideupdate_schedule().
I can do that.
Quoted 9 lines
Quoted 6 lines
+ while ((credit =
current_credit()) < 0) {
+ if (credit !=last_credit) {
+last_changed= jiffies;
+last_credit= credit;
+ }
+ if (balloon_state==BP_ECANCELED) {What about other states? We are really waiting for
BP_DONE, aren't we?
Nearly. We are waiting for credit not being negative.
And in case of cancelled we know this won't happen without Xen admin intervention.
Juergen