Skip to content

Commit b13cd24

Browse files
roygerjgross1
authored andcommitted
xen/balloon: improve accuracy of initial balloon target for dom0
The dom0 balloon target set by the toolstack is the value returned by XENMEM_current_reservation. Do the same in the kernel balloon driver and set the current allocation to the value returned by XENMEM_current_reservation. On my test system this causes the kernel balloon driver target to exactly match the value set by the toolstack in xenstore. Note this approach can be used by both PV and PVH dom0s, as the toolstack always uses XENMEM_current_reservation to set the initial target regardless of the dom0 type. Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Juergen Gross <jgross@suse.com> Message-ID: <20260128110510.46425-3-roger.pau@citrix.com>
1 parent 0949c64 commit b13cd24

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

drivers/xen/balloon.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -724,23 +724,30 @@ static int __init balloon_add_regions(void)
724724
static int __init balloon_init(void)
725725
{
726726
struct task_struct *task;
727-
unsigned long current_pages;
727+
long current_pages = 0;
728+
domid_t domid = DOMID_SELF;
728729
int rc;
729730

730731
if (!xen_domain())
731732
return -ENODEV;
732733

733734
pr_info("Initialising balloon driver\n");
734735

735-
if (xen_pv_domain()) {
736-
if (xen_released_pages >= xen_start_info->nr_pages)
737-
goto underflow;
738-
current_pages = min(xen_start_info->nr_pages -
739-
xen_released_pages, max_pfn);
740-
} else {
741-
if (xen_unpopulated_pages >= get_num_physpages())
742-
goto underflow;
743-
current_pages = get_num_physpages() - xen_unpopulated_pages;
736+
if (xen_initial_domain())
737+
current_pages = HYPERVISOR_memory_op(XENMEM_current_reservation,
738+
&domid);
739+
if (current_pages <= 0) {
740+
if (xen_pv_domain()) {
741+
if (xen_released_pages >= xen_start_info->nr_pages)
742+
goto underflow;
743+
current_pages = min(xen_start_info->nr_pages -
744+
xen_released_pages, max_pfn);
745+
} else {
746+
if (xen_unpopulated_pages >= get_num_physpages())
747+
goto underflow;
748+
current_pages = get_num_physpages() -
749+
xen_unpopulated_pages;
750+
}
744751
}
745752

746753
balloon_stats.current_pages = current_pages;

0 commit comments

Comments
 (0)