public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Philip P. Moltmann" <moltmann@vmware.com>
To: gregkh@linuxfoundation.org
Cc: "Philip P. Moltmann" <moltmann@vmware.com>,
	dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org,
	xdeguillard@vmware.com, akpm@linux-foundation.org,
	pv-drivers@vmware.com
Subject: [PATCH v5 4/7] VMware balloon: Do not limit the amount of frees and allocations in non-sleep mode.
Date: Thu,  6 Aug 2015 15:18:01 -0700	[thread overview]
Message-ID: <1438899484-2426-5-git-send-email-moltmann@vmware.com> (raw)
In-Reply-To: <1438899484-2426-1-git-send-email-moltmann@vmware.com>
In-Reply-To: <20150806210755.GA18346@kroah.com>

When VMware's hypervisor requests a VM to reclaim memory this is preferrably done
via ballooning. If the balloon driver does not return memory fast enough, more
drastic methods, such as hypervisor-level swapping are needed. These other methods
cause performance issues, e.g. hypervisor-level swapping requires the hypervisor to
swap in a page syncronously while the virtual CPU is blocked.

Hence it is in the interest of the VM to balloon memory as fast as possible. The
problem with doing this is that the VM might end up doing nothing else than
ballooning and the user might notice that the VM is stalled, esp. when the VM has
only a single virtual CPU.

This is less of a problem if the VM and the hypervisor perform balloon operations
faster. Also the balloon driver yields regularly, hence on a single virtual CPU
the Linux scheduler should be able to properly time-slice between ballooning and
other tasks.

Testing Done: quickly ballooned a lot of pages while wathing if there are any
perceived hickups (periods of non-responsiveness) in the execution of the
linux VM. No such hickups were seen.

Signed-off-by: Xavier Deguillard <xdeguillard@vmware.com>
---
 drivers/misc/vmw_balloon.c | 68 +++++++++++-----------------------------------
 1 file changed, 16 insertions(+), 52 deletions(-)

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index f0beb65..aed9525 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -47,7 +47,7 @@
 
 MODULE_AUTHOR("VMware, Inc.");
 MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
-MODULE_VERSION("1.3.3.0-k");
+MODULE_VERSION("1.3.4.0-k");
 MODULE_ALIAS("dmi:*:svnVMware*:*");
 MODULE_ALIAS("vmware_vmmemctl");
 MODULE_LICENSE("GPL");
@@ -58,12 +58,6 @@ MODULE_LICENSE("GPL");
  */
 
 /*
- * Rate of allocating memory when there is no memory pressure
- * (driver performs non-sleeping allocations).
- */
-#define VMW_BALLOON_NOSLEEP_ALLOC_MAX	16384U
-
-/*
  * Rates of memory allocaton when guest experiences memory pressure
  * (driver performs sleeping allocations).
  */
@@ -72,13 +66,6 @@ MODULE_LICENSE("GPL");
 #define VMW_BALLOON_RATE_ALLOC_INC	16U
 
 /*
- * Rates for releasing pages while deflating balloon.
- */
-#define VMW_BALLOON_RATE_FREE_MIN	512U
-#define VMW_BALLOON_RATE_FREE_MAX	16384U
-#define VMW_BALLOON_RATE_FREE_INC	16U
-
-/*
  * When guest is under memory pressure, use a reduced page allocation
  * rate for next several cycles.
  */
@@ -100,9 +87,6 @@ MODULE_LICENSE("GPL");
  */
 #define VMW_PAGE_ALLOC_CANSLEEP		(GFP_HIGHUSER)
 
-/* Maximum number of page allocations without yielding processor */
-#define VMW_BALLOON_YIELD_THRESHOLD	1024
-
 /* Maximum number of refused pages we accumulate during inflation cycle */
 #define VMW_BALLOON_MAX_REFUSED		16
 
@@ -279,7 +263,6 @@ struct vmballoon {
 
 	/* adjustment rates (pages per second) */
 	unsigned int rate_alloc;
-	unsigned int rate_free;
 
 	/* slowdown page allocations for next few cycles */
 	unsigned int slow_allocation_cycles;
@@ -503,18 +486,13 @@ static bool vmballoon_send_batched_unlock(struct vmballoon *b,
 static void vmballoon_pop(struct vmballoon *b)
 {
 	struct page *page, *next;
-	unsigned int count = 0;
 
 	list_for_each_entry_safe(page, next, &b->pages, lru) {
 		list_del(&page->lru);
 		__free_page(page);
 		STATS_INC(b->stats.free);
 		b->size--;
-
-		if (++count >= b->rate_free) {
-			count = 0;
-			cond_resched();
-		}
+		cond_resched();
 	}
 
 	if ((b->capabilities & VMW_BALLOON_BATCHED_CMDS) != 0) {
@@ -716,7 +694,7 @@ static void vmballoon_add_batched_page(struct vmballoon *b, int idx,
  */
 static void vmballoon_inflate(struct vmballoon *b)
 {
-	unsigned int rate;
+	unsigned rate;
 	unsigned int allocations = 0;
 	unsigned int num_pages = 0;
 	int error = 0;
@@ -743,13 +721,13 @@ static void vmballoon_inflate(struct vmballoon *b)
 	 * Start with no sleep allocation rate which may be higher
 	 * than sleeping allocation rate.
 	 */
-	rate = b->slow_allocation_cycles ?
-			b->rate_alloc : VMW_BALLOON_NOSLEEP_ALLOC_MAX;
+	rate = b->slow_allocation_cycles ? b->rate_alloc : UINT_MAX;
 
-	pr_debug("%s - goal: %d, no-sleep rate: %d, sleep rate: %d\n",
+	pr_debug("%s - goal: %d, no-sleep rate: %u, sleep rate: %d\n",
 		 __func__, b->target - b->size, rate, b->rate_alloc);
 
-	while (b->size < b->target && num_pages < b->target - b->size) {
+	while (!b->reset_required &&
+		b->size < b->target && num_pages < b->target - b->size) {
 		struct page *page;
 
 		if (flags == VMW_PAGE_ALLOC_NOSLEEP)
@@ -799,10 +777,7 @@ static void vmballoon_inflate(struct vmballoon *b)
 				break;
 		}
 
-		if (++allocations > VMW_BALLOON_YIELD_THRESHOLD) {
-			cond_resched();
-			allocations = 0;
-		}
+		cond_resched();
 
 		if (allocations >= rate) {
 			/* We allocated enough pages, let's take a break. */
@@ -838,36 +813,29 @@ static void vmballoon_deflate(struct vmballoon *b)
 	unsigned int num_pages = 0;
 	int error;
 
-	pr_debug("%s - size: %d, target %d, rate: %d\n", __func__, b->size,
-						b->target, b->rate_free);
+	pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
 
 	/* free pages to reach target */
 	list_for_each_entry_safe(page, next, &b->pages, lru) {
 		list_del(&page->lru);
 		b->ops->add_page(b, num_pages++, page);
 
+
 		if (num_pages == b->batch_max_pages) {
 			error = b->ops->unlock(b, num_pages, &b->target);
 			num_pages = 0;
-			if (error) {
-				/* quickly decrease rate in case of error */
-				b->rate_free = max(b->rate_free / 2,
-						VMW_BALLOON_RATE_FREE_MIN);
+			if (error)
 				return;
-			}
 		}
 
-		if (++i >= b->size - b->target)
+		if (b->reset_required || ++i >= b->size - b->target)
 			break;
+
+		cond_resched();
 	}
 
 	if (num_pages > 0)
 		b->ops->unlock(b, num_pages, &b->target);
-
-	/* slowly increase rate if there were no errors */
-	if (error == 0)
-		b->rate_free = min(b->rate_free + VMW_BALLOON_RATE_FREE_INC,
-				   VMW_BALLOON_RATE_FREE_MAX);
 }
 
 static const struct vmballoon_ops vmballoon_basic_ops = {
@@ -993,11 +961,8 @@ static int vmballoon_debug_show(struct seq_file *f, void *offset)
 
 	/* format rate info */
 	seq_printf(f,
-		   "rateNoSleepAlloc:   %8d pages/sec\n"
-		   "rateSleepAlloc:     %8d pages/sec\n"
-		   "rateFree:           %8d pages/sec\n",
-		   VMW_BALLOON_NOSLEEP_ALLOC_MAX,
-		   b->rate_alloc, b->rate_free);
+		   "rateSleepAlloc:     %8d pages/sec\n",
+		   b->rate_alloc);
 
 	seq_printf(f,
 		   "\n"
@@ -1088,7 +1053,6 @@ static int __init vmballoon_init(void)
 
 	/* initialize rates */
 	balloon.rate_alloc = VMW_BALLOON_RATE_ALLOC_MAX;
-	balloon.rate_free = VMW_BALLOON_RATE_FREE_MAX;
 
 	INIT_DELAYED_WORK(&balloon.dwork, vmballoon_work);
 
-- 
2.4.3


  parent reply	other threads:[~2015-08-06 22:22 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14 17:29 [PATCH 0/9] VMware balloon: Large page ballooning and VMCI support Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 1/9] VMware balloon: partially inline vmballoon_reserve_page Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 2/9] VMware balloon: Add support for balloon capabilities Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 3/9] VMware balloon: add batching to the vmw_balloon Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 4/9] VMware balloon: Update balloon target on each lock/unlock Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 5/9] VMware balloon: Show capabilities of balloon and resulting capabilities in the debug-fs node Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 5/9] VMware balloon: Show capabilities or " Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 6/9] VMware balloon: Do not limit the amount of frees and allocations in non-sleep mode Philip P. Moltmann
2015-04-16 20:55   ` Dmitry Torokhov
2015-06-11 20:10     ` Philip Moltmann
2015-06-12 11:20       ` dmitry.torokhov
2015-06-12 15:06         ` Philip Moltmann
2015-06-12 15:31           ` dmitry.torokhov
2015-06-12 15:40             ` Philip Moltmann
2015-06-12 16:15               ` dmitry.torokhov
2015-06-12 18:43                 ` [PATCH v3 0/9] Third revision of the performance improvment patch to the VMWare balloon driver Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 1/9] VMware balloon: partially inline vmballoon_reserve_page Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 2/9] VMware balloon: Add support for balloon capabilities Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 3/9] VMware balloon: add batching to the vmw_balloon Philip P. Moltmann
2015-08-05 20:19                   ` Greg KH
2015-08-05 22:36                     ` [PATCH v4 " Philip P. Moltmann
2015-08-05 22:44                       ` Greg KH
2015-08-05 22:47                         ` Philip Moltmann
2015-08-05 23:26                           ` gregkh
2015-08-06 20:33                             ` [PATCH v4 0/9] Fourth revision of the performance improvement patch to the VMware balloon driver Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 1/9] VMware balloon: partially inline vmballoon_reserve_page Philip P. Moltmann
2015-08-06 21:07                               ` Greg KH
2015-08-06 22:17                                 ` [PATCH v5 0/7] Fifth revision of the performance improvement patch to the VMware balloon driver Philip P. Moltmann
2015-08-14 23:27                                   ` Philip Moltmann
2015-08-06 22:17                                 ` [PATCH v5 1/7] VMware balloon: add batching to the vmw_balloon Philip P. Moltmann
2015-08-06 22:17                                 ` [PATCH v5 2/7] VMware balloon: Update balloon target on each lock/unlock Philip P. Moltmann
2015-08-06 22:18                                 ` [PATCH v5 3/7] VMware balloon: Show capabilities of balloon and resulting capabilities in the debug-fs node Philip P. Moltmann
2015-08-06 22:18                                 ` Philip P. Moltmann [this message]
2015-08-06 22:18                                 ` [PATCH v5 5/7] VMware balloon: Support 2m page ballooning Philip P. Moltmann
2015-08-21 14:01                                   ` Kamalneet Singh
2015-08-06 22:18                                 ` [PATCH v5 6/7] VMware balloon: Treat init like reset Philip P. Moltmann
2015-08-06 22:18                                 ` [PATCH v5 7/7] VMware balloon: Enable notification via VMCI Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 2/9] VMware balloon: Add support for balloon capabilities Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 3/9] VMware balloon: add batching to the vmw_balloon Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 4/9] VMware balloon: Update balloon target on each lock/unlock Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 5/9] VMware balloon: Show capabilities of balloon and resulting capabilities in the debug-fs node Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 6/9] VMware balloon: Do not limit the amount of frees and allocations in non-sleep mode Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 7/9] VMware balloon: Support 2m page ballooning Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 8/9] VMware balloon: Treat init like reset Philip P. Moltmann
2015-08-06 20:33                             ` [PATCH v4 9/9] VMware balloon: Enable notification via VMCI Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 4/9] VMware balloon: Update balloon target on each lock/unlock Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 5/9] VMware balloon: Show capabilities of balloon and resulting capabilities in the debug-fs node Philip P. Moltmann
2015-08-05 20:14                   ` Greg KH
2015-08-05 20:22                     ` Philip Moltmann
2015-08-05 20:33                       ` dmitry.torokhov
2015-08-05 20:42                         ` John Savanyo
2015-08-05 20:50                           ` gregkh
2015-08-05 21:11                             ` John Savanyo
2015-08-05 20:40                       ` gregkh
2015-06-12 18:43                 ` [PATCH v3 6/9] VMware balloon: Do not limit the amount of frees and allocations in non-sleep mode Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 7/9] VMware balloon: Support 2m page ballooning Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 8/9] VMware balloon: Treat init like reset Philip P. Moltmann
2015-06-12 18:43                 ` [PATCH v3 9/9] VMware balloon: Enable notification via VMCI Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 7/9] VMware balloon: Support 2m page ballooning Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 8/9] VMware balloon: Treat init like reset Philip P. Moltmann
2015-04-14 17:29 ` [PATCH 9/9] VMware balloon: Enable notification via VMCI Philip P. Moltmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438899484-2426-5-git-send-email-moltmann@vmware.com \
    --to=moltmann@vmware.com \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pv-drivers@vmware.com \
    --cc=xdeguillard@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox