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: Xavier Deguillard <xdeguillard@vmware.com>,
	dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, pv-drivers@vmware.com,
	"Philip P. Moltmann" <moltmann@vmware.com>
Subject: [PATCH v4 4/9] VMware balloon: Update balloon target on each lock/unlock.
Date: Thu,  6 Aug 2015 13:33:42 -0700	[thread overview]
Message-ID: <1438893227-2230-5-git-send-email-moltmann@vmware.com> (raw)
In-Reply-To: <1438893227-2230-1-git-send-email-moltmann@vmware.com>
In-Reply-To: <20150805232613.GA22752@kroah.com>

From: Xavier Deguillard <xdeguillard@vmware.com>

Instead of waiting for the next GET_TARGET command, we can react faster
by exploiting the fact that each hypervisor call also returns the
balloon target.

Signed-off-by: Xavier Deguillard <xdeguillard@vmware.com>
Acked-by: Dmitry Torokhov <dtor@vmware.com>
Signed-off-by: Philip P. Moltmann <moltmann@vmware.com>
Acked-by: Andy King <acking@vmware.com>
---
 drivers/misc/vmw_balloon.c | 85 +++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 43 deletions(-)

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 64f275e..0b5aa93 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.1.0-k");
+MODULE_VERSION("1.3.2.0-k");
 MODULE_ALIAS("dmi:*:svnVMware*:*");
 MODULE_ALIAS("vmware_vmmemctl");
 MODULE_LICENSE("GPL");
@@ -255,8 +255,10 @@ struct vmballoon;
 
 struct vmballoon_ops {
 	void (*add_page)(struct vmballoon *b, int idx, struct page *p);
-	int (*lock)(struct vmballoon *b, unsigned int num_pages);
-	int (*unlock)(struct vmballoon *b, unsigned int num_pages);
+	int (*lock)(struct vmballoon *b, unsigned int num_pages,
+						unsigned int *target);
+	int (*unlock)(struct vmballoon *b, unsigned int num_pages,
+						unsigned int *target);
 };
 
 struct vmballoon {
@@ -413,7 +415,7 @@ static bool vmballoon_send_get_target(struct vmballoon *b, u32 *new_target)
  * check the return value and maybe submit a different page.
  */
 static int vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn,
-				     unsigned int *hv_status)
+				unsigned int *hv_status, unsigned int *target)
 {
 	unsigned long status, dummy = 0;
 	u32 pfn32;
@@ -424,7 +426,7 @@ static int vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn,
 
 	STATS_INC(b->stats.lock);
 
-	*hv_status = status = VMWARE_BALLOON_CMD(LOCK, pfn, dummy, dummy);
+	*hv_status = status = VMWARE_BALLOON_CMD(LOCK, pfn, dummy, *target);
 	if (vmballoon_check_status(b, status))
 		return 0;
 
@@ -434,14 +436,14 @@ static int vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn,
 }
 
 static int vmballoon_send_batched_lock(struct vmballoon *b,
-					unsigned int num_pages)
+				unsigned int num_pages, unsigned int *target)
 {
-	unsigned long status, dummy;
+	unsigned long status;
 	unsigned long pfn = page_to_pfn(b->page);
 
 	STATS_INC(b->stats.lock);
 
-	status = VMWARE_BALLOON_CMD(BATCHED_LOCK, pfn, num_pages, dummy);
+	status = VMWARE_BALLOON_CMD(BATCHED_LOCK, pfn, num_pages, *target);
 	if (vmballoon_check_status(b, status))
 		return 0;
 
@@ -454,7 +456,8 @@ static int vmballoon_send_batched_lock(struct vmballoon *b,
  * Notify the host that guest intends to release given page back into
  * the pool of available (to the guest) pages.
  */
-static bool vmballoon_send_unlock_page(struct vmballoon *b, unsigned long pfn)
+static bool vmballoon_send_unlock_page(struct vmballoon *b, unsigned long pfn,
+							unsigned int *target)
 {
 	unsigned long status, dummy = 0;
 	u32 pfn32;
@@ -465,7 +468,7 @@ static bool vmballoon_send_unlock_page(struct vmballoon *b, unsigned long pfn)
 
 	STATS_INC(b->stats.unlock);
 
-	status = VMWARE_BALLOON_CMD(UNLOCK, pfn, dummy, dummy);
+	status = VMWARE_BALLOON_CMD(UNLOCK, pfn, dummy, *target);
 	if (vmballoon_check_status(b, status))
 		return true;
 
@@ -475,14 +478,14 @@ static bool vmballoon_send_unlock_page(struct vmballoon *b, unsigned long pfn)
 }
 
 static bool vmballoon_send_batched_unlock(struct vmballoon *b,
-						unsigned int num_pages)
+				unsigned int num_pages, unsigned int *target)
 {
-	unsigned long status, dummy;
+	unsigned long status;
 	unsigned long pfn = page_to_pfn(b->page);
 
 	STATS_INC(b->stats.unlock);
 
-	status = VMWARE_BALLOON_CMD(BATCHED_UNLOCK, pfn, num_pages, dummy);
+	status = VMWARE_BALLOON_CMD(BATCHED_UNLOCK, pfn, num_pages, *target);
 	if (vmballoon_check_status(b, status))
 		return true;
 
@@ -528,12 +531,14 @@ static void vmballoon_pop(struct vmballoon *b)
  * refuse list, those refused page are then released at the end of the
  * inflation cycle.
  */
-static int vmballoon_lock_page(struct vmballoon *b, unsigned int num_pages)
+static int vmballoon_lock_page(struct vmballoon *b, unsigned int num_pages,
+							unsigned int *target)
 {
 	int locked, hv_status;
 	struct page *page = b->page;
 
-	locked = vmballoon_send_lock_page(b, page_to_pfn(page), &hv_status);
+	locked = vmballoon_send_lock_page(b, page_to_pfn(page), &hv_status,
+								target);
 	if (locked > 0) {
 		STATS_INC(b->stats.refused_alloc);
 
@@ -567,11 +572,11 @@ static int vmballoon_lock_page(struct vmballoon *b, unsigned int num_pages)
 }
 
 static int vmballoon_lock_batched_page(struct vmballoon *b,
-				unsigned int num_pages)
+				unsigned int num_pages, unsigned int *target)
 {
 	int locked, i;
 
-	locked = vmballoon_send_batched_lock(b, num_pages);
+	locked = vmballoon_send_batched_lock(b, num_pages, target);
 	if (locked > 0) {
 		for (i = 0; i < num_pages; i++) {
 			u64 pa = vmballoon_batch_get_pa(b->batch_page, i);
@@ -620,11 +625,12 @@ static int vmballoon_lock_batched_page(struct vmballoon *b,
  * the host so it can make sure the page will be available for the guest
  * to use, if needed.
  */
-static int vmballoon_unlock_page(struct vmballoon *b, unsigned int num_pages)
+static int vmballoon_unlock_page(struct vmballoon *b, unsigned int num_pages,
+							unsigned int *target)
 {
 	struct page *page = b->page;
 
-	if (!vmballoon_send_unlock_page(b, page_to_pfn(page))) {
+	if (!vmballoon_send_unlock_page(b, page_to_pfn(page), target)) {
 		list_add(&page->lru, &b->pages);
 		return -EIO;
 	}
@@ -640,12 +646,12 @@ static int vmballoon_unlock_page(struct vmballoon *b, unsigned int num_pages)
 }
 
 static int vmballoon_unlock_batched_page(struct vmballoon *b,
-					unsigned int num_pages)
+				unsigned int num_pages, unsigned int *target)
 {
 	int locked, i, ret = 0;
 	bool hv_success;
 
-	hv_success = vmballoon_send_batched_unlock(b, num_pages);
+	hv_success = vmballoon_send_batched_unlock(b, num_pages, target);
 	if (!hv_success)
 		ret = -EIO;
 
@@ -710,9 +716,7 @@ static void vmballoon_add_batched_page(struct vmballoon *b, int idx,
  */
 static void vmballoon_inflate(struct vmballoon *b)
 {
-	unsigned int goal;
 	unsigned int rate;
-	unsigned int i;
 	unsigned int allocations = 0;
 	unsigned int num_pages = 0;
 	int error = 0;
@@ -735,7 +739,6 @@ static void vmballoon_inflate(struct vmballoon *b)
 	 * slowdown page allocations considerably.
 	 */
 
-	goal = b->target - b->size;
 	/*
 	 * Start with no sleep allocation rate which may be higher
 	 * than sleeping allocation rate.
@@ -744,16 +747,17 @@ static void vmballoon_inflate(struct vmballoon *b)
 			b->rate_alloc : VMW_BALLOON_NOSLEEP_ALLOC_MAX;
 
 	pr_debug("%s - goal: %d, no-sleep rate: %d, sleep rate: %d\n",
-		 __func__, goal, rate, b->rate_alloc);
+		 __func__, b->target - b->size, rate, b->rate_alloc);
 
-	for (i = 0; i < goal; i++) {
-		struct page *page = alloc_page(flags);
+	while (b->size < b->target && num_pages < b->target - b->size) {
+		struct page *page;
 
 		if (flags == VMW_PAGE_ALLOC_NOSLEEP)
 			STATS_INC(b->stats.alloc);
 		else
 			STATS_INC(b->stats.sleep_alloc);
 
+		page = alloc_page(flags);
 		if (!page) {
 			if (flags == VMW_PAGE_ALLOC_CANSLEEP) {
 				/*
@@ -778,7 +782,7 @@ static void vmballoon_inflate(struct vmballoon *b)
 			 */
 			b->slow_allocation_cycles = VMW_BALLOON_SLOW_CYCLES;
 
-			if (i >= b->rate_alloc)
+			if (allocations >= b->rate_alloc)
 				break;
 
 			flags = VMW_PAGE_ALLOC_CANSLEEP;
@@ -789,7 +793,7 @@ static void vmballoon_inflate(struct vmballoon *b)
 
 		b->ops->add_page(b, num_pages++, page);
 		if (num_pages == b->batch_max_pages) {
-			error = b->ops->lock(b, num_pages);
+			error = b->ops->lock(b, num_pages, &b->target);
 			num_pages = 0;
 			if (error)
 				break;
@@ -800,21 +804,21 @@ static void vmballoon_inflate(struct vmballoon *b)
 			allocations = 0;
 		}
 
-		if (i >= rate) {
+		if (allocations >= rate) {
 			/* We allocated enough pages, let's take a break. */
 			break;
 		}
 	}
 
 	if (num_pages > 0)
-		b->ops->lock(b, num_pages);
+		b->ops->lock(b, num_pages, &b->target);
 
 	/*
 	 * We reached our goal without failures so try increasing
 	 * allocation rate.
 	 */
-	if (error == 0 && i >= b->rate_alloc) {
-		unsigned int mult = i / b->rate_alloc;
+	if (error == 0 && allocations >= b->rate_alloc) {
+		unsigned int mult = allocations / b->rate_alloc;
 
 		b->rate_alloc =
 			min(b->rate_alloc + mult * VMW_BALLOON_RATE_ALLOC_INC,
@@ -831,16 +835,11 @@ static void vmballoon_deflate(struct vmballoon *b)
 {
 	struct page *page, *next;
 	unsigned int i = 0;
-	unsigned int goal;
 	unsigned int num_pages = 0;
 	int error;
 
-	pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
-
-	/* limit deallocation rate */
-	goal = min(b->size - b->target, b->rate_free);
-
-	pr_debug("%s - goal: %d, rate: %d\n", __func__, goal, b->rate_free);
+	pr_debug("%s - size: %d, target %d, rate: %d\n", __func__, b->size,
+						b->target, b->rate_free);
 
 	/* free pages to reach target */
 	list_for_each_entry_safe(page, next, &b->pages, lru) {
@@ -848,7 +847,7 @@ static void vmballoon_deflate(struct vmballoon *b)
 		b->ops->add_page(b, num_pages++, page);
 
 		if (num_pages == b->batch_max_pages) {
-			error = b->ops->unlock(b, num_pages);
+			error = b->ops->unlock(b, num_pages, &b->target);
 			num_pages = 0;
 			if (error) {
 				/* quickly decrease rate in case of error */
@@ -858,12 +857,12 @@ static void vmballoon_deflate(struct vmballoon *b)
 			}
 		}
 
-		if (++i >= goal)
+		if (++i >= b->size - b->target)
 			break;
 	}
 
 	if (num_pages > 0)
-		b->ops->unlock(b, num_pages);
+		b->ops->unlock(b, num_pages, &b->target);
 
 	/* slowly increase rate if there were no errors */
 	if (error == 0)
-- 
2.4.3


  parent reply	other threads:[~2015-08-06 20:35 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                                 ` [PATCH v5 4/7] VMware balloon: Do not limit the amount of frees and allocations in non-sleep mode Philip P. Moltmann
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                             ` Philip P. Moltmann [this message]
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=1438893227-2230-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