aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hv/hv_balloon.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hv/hv_balloon.c')
-rw-r--r--drivers/hv/hv_balloon.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index ea3d33cdf99c..53932b3e1973 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -503,6 +503,8 @@ struct hv_dynmem_device {
503 * Number of pages we have currently ballooned out. 503 * Number of pages we have currently ballooned out.
504 */ 504 */
505 unsigned int num_pages_ballooned; 505 unsigned int num_pages_ballooned;
506 unsigned int num_pages_onlined;
507 unsigned int num_pages_added;
506 508
507 /* 509 /*
508 * State to manage the ballooning (up) operation. 510 * State to manage the ballooning (up) operation.
@@ -556,12 +558,15 @@ static void post_status(struct hv_dynmem_device *dm);
556static int hv_memory_notifier(struct notifier_block *nb, unsigned long val, 558static int hv_memory_notifier(struct notifier_block *nb, unsigned long val,
557 void *v) 559 void *v)
558{ 560{
561 struct memory_notify *mem = (struct memory_notify *)v;
562
559 switch (val) { 563 switch (val) {
560 case MEM_GOING_ONLINE: 564 case MEM_GOING_ONLINE:
561 mutex_lock(&dm_device.ha_region_mutex); 565 mutex_lock(&dm_device.ha_region_mutex);
562 break; 566 break;
563 567
564 case MEM_ONLINE: 568 case MEM_ONLINE:
569 dm_device.num_pages_onlined += mem->nr_pages;
565 case MEM_CANCEL_ONLINE: 570 case MEM_CANCEL_ONLINE:
566 mutex_unlock(&dm_device.ha_region_mutex); 571 mutex_unlock(&dm_device.ha_region_mutex);
567 if (dm_device.ha_waiting) { 572 if (dm_device.ha_waiting) {
@@ -570,8 +575,12 @@ static int hv_memory_notifier(struct notifier_block *nb, unsigned long val,
570 } 575 }
571 break; 576 break;
572 577
573 case MEM_GOING_OFFLINE:
574 case MEM_OFFLINE: 578 case MEM_OFFLINE:
579 mutex_lock(&dm_device.ha_region_mutex);
580 dm_device.num_pages_onlined -= mem->nr_pages;
581 mutex_unlock(&dm_device.ha_region_mutex);
582 break;
583 case MEM_GOING_OFFLINE:
575 case MEM_CANCEL_OFFLINE: 584 case MEM_CANCEL_OFFLINE:
576 break; 585 break;
577 } 586 }
@@ -896,6 +905,8 @@ static void hot_add_req(struct work_struct *dummy)
896 if (do_hot_add) 905 if (do_hot_add)
897 resp.page_count = process_hot_add(pg_start, pfn_cnt, 906 resp.page_count = process_hot_add(pg_start, pfn_cnt,
898 rg_start, rg_sz); 907 rg_start, rg_sz);
908
909 dm->num_pages_added += resp.page_count;
899 mutex_unlock(&dm_device.ha_region_mutex); 910 mutex_unlock(&dm_device.ha_region_mutex);
900#endif 911#endif
901 /* 912 /*
@@ -1009,17 +1020,21 @@ static void post_status(struct hv_dynmem_device *dm)
1009 status.hdr.trans_id = atomic_inc_return(&trans_id); 1020 status.hdr.trans_id = atomic_inc_return(&trans_id);
1010 1021
1011 /* 1022 /*
1012 * The host expects the guest to report free memory. 1023 * The host expects the guest to report free and committed memory.
1013 * Further, the host expects the pressure information to 1024 * Furthermore, the host expects the pressure information to include
1014 * include the ballooned out pages. 1025 * the ballooned out pages. For a given amount of memory that we are
1015 * For a given amount of memory that we are managing, we 1026 * managing we need to compute a floor below which we should not
1016 * need to compute a floor below which we should not balloon. 1027 * balloon. Compute this and add it to the pressure report.
1017 * Compute this and add it to the pressure report. 1028 * We also need to report all offline pages (num_pages_added -
1029 * num_pages_onlined) as committed to the host, otherwise it can try
1030 * asking us to balloon them out.
1018 */ 1031 */
1019 status.num_avail = val.freeram; 1032 status.num_avail = val.freeram;
1020 status.num_committed = vm_memory_committed() + 1033 status.num_committed = vm_memory_committed() +
1021 dm->num_pages_ballooned + 1034 dm->num_pages_ballooned +
1022 compute_balloon_floor(); 1035 (dm->num_pages_added > dm->num_pages_onlined ?
1036 dm->num_pages_added - dm->num_pages_onlined : 0) +
1037 compute_balloon_floor();
1023 1038
1024 /* 1039 /*
1025 * If our transaction ID is no longer current, just don't 1040 * If our transaction ID is no longer current, just don't