ia64/linux-2.6.18-xen.hg

view lib/hweight.c @ 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 14:01:20 2009 +0100 (2009-06-05)
parents 831230e53067
children
line source
1 #include <linux/module.h>
2 #include <asm/types.h>
4 /**
5 * hweightN - returns the hamming weight of a N-bit word
6 * @x: the word to weigh
7 *
8 * The Hamming Weight of a number is the total number of bits set in it.
9 */
11 unsigned int hweight32(unsigned int w)
12 {
13 unsigned int res = w - ((w >> 1) & 0x55555555);
14 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
15 res = (res + (res >> 4)) & 0x0F0F0F0F;
16 res = res + (res >> 8);
17 return (res + (res >> 16)) & 0x000000FF;
18 }
19 EXPORT_SYMBOL(hweight32);
21 unsigned int hweight16(unsigned int w)
22 {
23 unsigned int res = w - ((w >> 1) & 0x5555);
24 res = (res & 0x3333) + ((res >> 2) & 0x3333);
25 res = (res + (res >> 4)) & 0x0F0F;
26 return (res + (res >> 8)) & 0x00FF;
27 }
28 EXPORT_SYMBOL(hweight16);
30 unsigned int hweight8(unsigned int w)
31 {
32 unsigned int res = w - ((w >> 1) & 0x55);
33 res = (res & 0x33) + ((res >> 2) & 0x33);
34 return (res + (res >> 4)) & 0x0F;
35 }
36 EXPORT_SYMBOL(hweight8);
38 unsigned long hweight64(__u64 w)
39 {
40 #if BITS_PER_LONG == 32
41 return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
42 #elif BITS_PER_LONG == 64
43 __u64 res = w - ((w >> 1) & 0x5555555555555555ul);
44 res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
45 res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
46 res = res + (res >> 8);
47 res = res + (res >> 16);
48 return (res + (res >> 32)) & 0x00000000000000FFul;
49 #else
50 #error BITS_PER_LONG not defined
51 #endif
52 }
53 EXPORT_SYMBOL(hweight64);