Skip to contentSkip to conversation

xen: Fix selfballooning and ensure it doesn't go too far

PATCH Superseded Dan Magenheimer 2 participants 3 messages Sep 24, 2011 – Sep 26, 2011 Xen hypervisor interface

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: Fix selfballooning and ensure it doesn't go too far

[PATCH] xen: Fix selfballooning and ensure it doesn't go too far

The balloon driver's "current_pages" is very different from totalram_pages. Self-ballooning needs to be driven by the latter. Also, Committed_AS doesn't account for pages used by the kernel so enforce a floor for when there are little or no user-space threads using memory.

drivers/xen/xen-selfballoon.c +10 -5
index 6ea852e..e3e48f1 100644
@@ -195,14 +195,13 @@ __setup("selfballooning", xen_selfballooning_setup);
  */
 static void selfballoon_process(struct work_struct *work)
 {
-	unsigned long cur_pages, goal_pages, tgt_pages;
+	unsigned long cur_pages, goal_pages, tgt_pages, floor_pages;
 	bool reset_timer = false;
 
 	if (xen_selfballooning_enabled) {
-		cur_pages = balloon_stats.current_pages;
+		cur_pages = totalram_pages;
 		tgt_pages = cur_pages; /* default is no change */
-		goal_pages = percpu_counter_read_positive(&vm_committed_as) +
-			balloon_stats.current_pages - totalram_pages;
+		goal_pages = percpu_counter_read_positive(&vm_committed_as);
 #ifdef CONFIG_FRONTSWAP
 		/* allow space for frontswap pages to be repatriated */
 		if (frontswap_selfshrinking && frontswap_enabled)
@@ -217,7 +216,13 @@ static void selfballoon_process(struct work_struct *work)
 				((goal_pages - cur_pages) /
 				  selfballoon_uphysteresis);
 		/* else if cur_pages == goal_pages, no change */
-		balloon_set_new_target(tgt_pages);
+		floor_pages = totalreserve_pages +
+				(roundup_pow_of_two(max_pfn) >> 5);
+		/* don't balloon too far, lest OOMs occur... */
+		if (tgt_pages < floor_pages)
+			tgt_pages = floor_pages;
+		balloon_set_new_target(tgt_pages +
+			balloon_stats.current_pages - totalram_pages);
 		reset_timer = true;
 	}
 #ifdef CONFIG_FRONTSWAP
#1 lore raw
Quoted 7 lines · Dan Magenheimer

[PATCH] xen: Fix selfballooning and ensure it doesn't go too far

The balloon driver's "current_pages" is very different from totalram_pages. Self-ballooning needs to be driven by the latter. Also, Committed_AS doesn't account for pages used by the kernel so enforce a floor for when there are little or no user-space threads using memory.

Hey Dan,
..

drivers/xen/xen-selfballoon.c static void selfballoon_process(struct work_struct *work) · line 220

Quoted 2 lines
drivers/xen/xen-selfballoon.c +2 -0
+		floor_pages = totalreserve_pages +
+				(roundup_pow_of_two(max_pfn) >> 5);

Would it make sense to make the shift be a runtime argument in case some users report problems with that calculation?

drivers/xen/xen-selfballoon.c static void selfballoon_process(struct work_struct *work) · line 228

Quoted 8 lines
drivers/xen/xen-selfballoon.c +5 -0
+		/* don't balloon too far, lest OOMs occur... */
+		if (tgt_pages < floor_pages)
+			tgt_pages = floor_pages;
+		balloon_set_new_target(tgt_pages +
+			balloon_stats.current_pages - totalram_pages);
 		reset_timer = true;
 	}
 #ifdef CONFIG_FRONTSWAP

Otherwise it looks OK to me. Would you like me to queue it up for 3.1-rc7?

#2 lore raw
Quoted 15 lines

From: Konrad Rzeszutek Wilk
Sent: Monday, September 26, 2011 11:23 AM
To: Dan Magenheimer
Cc: [email protected]; [email protected]; David Vrabel; Jeremy Fitzhardinge
Subject: Re: [PATCH] xen: Fix selfballooning and ensure it doesn't go too far

Quoted 7 lines · Dan Magenheimer

[PATCH] xen: Fix selfballooning and ensure it doesn't go too far

The balloon driver's "current_pages" is very different from totalram_pages. Self-ballooning needs to be driven by the latter. Also, Committed_AS doesn't account for pages used by the kernel so enforce a floor for when there are little or no user-space threads using memory.

Quoted 7 lines

Hey Dan,
..

drivers/xen/xen-selfballoon.c static void selfballoon_process(struct work_struct *work) · line 220

Quoted 2 lines
drivers/xen/xen-selfballoon.c +2 -0
+		floor_pages = totalreserve_pages +
+				(roundup_pow_of_two(max_pfn) >> 5);

Would it make sense to make the shift be a runtime argument in case some users report problems with that calculation?

Good idea. I'll take a look at that.

Quoted 11 lines

drivers/xen/xen-selfballoon.c static void selfballoon_process(struct work_struct *work) · line 228

Quoted 8 lines
drivers/xen/xen-selfballoon.c +5 -0
+		/* don't balloon too far, lest OOMs occur... */
+		if (tgt_pages < floor_pages)
+			tgt_pages = floor_pages;
+		balloon_set_new_target(tgt_pages +
+			balloon_stats.current_pages - totalram_pages);
 		reset_timer = true;
 	}
 #ifdef CONFIG_FRONTSWAP

Otherwise it looks OK to me. Would you like me to queue it up for 3.1-rc7?

Will let you know when I have that change done/tested.

Thanks,
Dan