Skip to contentSkip to conversation

Drivers: hv: balloon

PATCH New K. Y. Srinivasan 1 participant 3 messages Feb 8, 2013 Hyper-V/Azure core and drivers

lore
Share & tools
lore
#0 lore raw

cover Drivers: hv: balloon

Make furher adjustments to memory pressure reporting and computation. In the current code, we begin to report pressure soon after the balloon driver loads and typically report a very low pressure until the system is fully operational. To avoid having the host take memory balancing decisions on data that does not fully reflect the memory pressure, delay reporting the pressure. Additionally, implement a floor for ballooning based on the amount of memory being managed.

K. Y. Srinivasan (2):
Drivers: hv: balloon: Add a parameter to delay pressure reporting
Drivers: hv: balloon: Prevent the host from ballooning the guest too
low

 drivers/hv/hv_balloon.c |   48 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 45 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/2 Drivers: hv: balloon: Add a parameter to delay pressure reporting

Delay reporting memory pressure by a specified amount of time. This addresses the problem where the host may take memory balancing decisions based on incorrect memory pressure data that will be posted as soon as the balloon driver is loaded.

---
 drivers/hv/hv_balloon.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
drivers/hv/hv_balloon.c +11 -2
index 32a96f1..f8fc996 100644
@@ -414,10 +414,17 @@ struct dm_info_msg {
 
 static bool hot_add;
 static bool do_hot_add;
+/*
+ * Delay reporting memory pressure by
+ * the specified number of seconds.
+ */
+static uint pressure_report_delay = 30;
 
 module_param(hot_add, bool, (S_IRUGO | S_IWUSR));
 MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
 
+module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
+MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
 static atomic_t trans_id = ATOMIC_INIT(0);
 
 static int dm_ring_size = (5 * PAGE_SIZE);
@@ -531,6 +538,10 @@ static void post_status(struct hv_dynmem_device *dm)
 	struct dm_status status;
 	struct sysinfo val;
 
+	if (pressure_report_delay > 0) {
+		--pressure_report_delay;
+		return;
+	}
 	si_meminfo(&val);
 	memset(&status, 0, sizeof(struct dm_status));
 	status.hdr.type = DM_STATUS_REPORT;
@@ -552,8 +563,6 @@ static void post_status(struct hv_dynmem_device *dm)
 
 }
 
-
-
 static void free_balloon_pages(struct hv_dynmem_device *dm,
 			 union dm_mem_page_range *range_array)
 {
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/2 Drivers: hv: balloon: Prevent the host from ballooning the guest too low

Based on the amount of memory being managed set a floor on how low the guest can be ballooned.

---
 drivers/hv/hv_balloon.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
drivers/hv/hv_balloon.c +34 -1
index f8fc996..3787321 100644
@@ -523,6 +523,34 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg)
 	}
 }
 
+unsigned long compute_balloon_floor(void)
+{
+	unsigned long min_pages;
+#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
+	/* Simple continuous piecewiese linear function:
+	 *  max MiB -> min MiB  gradient
+	 *       0         0
+	 *      16        16
+	 *      32        24
+	 *     128        72    (1/2)
+	 *     512       168    (1/4)
+	 *    2048       360    (1/8)
+	 *    8192       552    (1/32)
+	 *   32768      1320
+	 *  131072      4392
+	 */
+	if (totalram_pages < MB2PAGES(128))
+		min_pages = MB2PAGES(8) + (totalram_pages >> 1);
+	else if (totalram_pages < MB2PAGES(512))
+		min_pages = MB2PAGES(40) + (totalram_pages >> 2);
+	else if (totalram_pages < MB2PAGES(2048))
+		min_pages = MB2PAGES(104) + (totalram_pages >> 3);
+	else
+		min_pages = MB2PAGES(296) + (totalram_pages >> 5);
+#undef MB2PAGES
+	return min_pages;
+}
+
 /*
  * Post our status as it relates memory pressure to the
  * host. Host expects the guests to post this status
@@ -552,9 +580,14 @@ static void post_status(struct hv_dynmem_device *dm)
 	 * The host expects the guest to report free memory.
 	 * Further, the host expects the pressure information to
 	 * include the ballooned out pages.
+	 * For a given amount of memory that we are managing, we
+	 * need to compute a floor below which we should not balloon.
+	 * Compute this and add it to the pressure report.
 	 */
 	status.num_avail = val.freeram;
-	status.num_committed = vm_memory_committed() + dm->num_pages_ballooned;
+	status.num_committed = vm_memory_committed() +
+				dm->num_pages_ballooned +
+				compute_balloon_floor();
 
 	vmbus_sendpacket(dm->dev->channel, &status,
 				sizeof(struct dm_status),
Signature · 1 line
1.7.4.1