aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hv/hv_balloon.c
diff options
context:
space:
mode:
authorK. Y. Srinivasan <kys@microsoft.com>2013-02-08 18:57:16 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-02-08 18:42:01 -0500
commit1c7db96f6feac95d90200ddd0f9b5d94614ea759 (patch)
tree5facf08f6c2ca913b1ce519b212daf61a3478c22 /drivers/hv/hv_balloon.c
parente500d158fb07794724f12655f2eb5702fec613c4 (diff)
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. Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/hv/hv_balloon.c')
-rw-r--r--drivers/hv/hv_balloon.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index f8fc99600de8..37873213e24f 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -523,6 +523,34 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg)
523 } 523 }
524} 524}
525 525
526unsigned long compute_balloon_floor(void)
527{
528 unsigned long min_pages;
529#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
530 /* Simple continuous piecewiese linear function:
531 * max MiB -> min MiB gradient
532 * 0 0
533 * 16 16
534 * 32 24
535 * 128 72 (1/2)
536 * 512 168 (1/4)
537 * 2048 360 (1/8)
538 * 8192 552 (1/32)
539 * 32768 1320
540 * 131072 4392
541 */
542 if (totalram_pages < MB2PAGES(128))
543 min_pages = MB2PAGES(8) + (totalram_pages >> 1);
544 else if (totalram_pages < MB2PAGES(512))
545 min_pages = MB2PAGES(40) + (totalram_pages >> 2);
546 else if (totalram_pages < MB2PAGES(2048))
547 min_pages = MB2PAGES(104) + (totalram_pages >> 3);
548 else
549 min_pages = MB2PAGES(296) + (totalram_pages >> 5);
550#undef MB2PAGES
551 return min_pages;
552}
553
526/* 554/*
527 * Post our status as it relates memory pressure to the 555 * Post our status as it relates memory pressure to the
528 * host. Host expects the guests to post this status 556 * host. Host expects the guests to post this status
@@ -552,9 +580,14 @@ static void post_status(struct hv_dynmem_device *dm)
552 * The host expects the guest to report free memory. 580 * The host expects the guest to report free memory.
553 * Further, the host expects the pressure information to 581 * Further, the host expects the pressure information to
554 * include the ballooned out pages. 582 * include the ballooned out pages.
583 * For a given amount of memory that we are managing, we
584 * need to compute a floor below which we should not balloon.
585 * Compute this and add it to the pressure report.
555 */ 586 */
556 status.num_avail = val.freeram; 587 status.num_avail = val.freeram;
557 status.num_committed = vm_memory_committed() + dm->num_pages_ballooned; 588 status.num_committed = vm_memory_committed() +
589 dm->num_pages_ballooned +
590 compute_balloon_floor();
558 591
559 vmbus_sendpacket(dm->dev->channel, &status, 592 vmbus_sendpacket(dm->dev->channel, &status,
560 sizeof(struct dm_status), 593 sizeof(struct dm_status),