ia64/linux-2.6.18-xen.hg

view arch/sparc/lib/atomic32.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 /*
2 * atomic32.c: 32-bit atomic_t implementation
3 *
4 * Copyright (C) 2004 Keith M Wesolowski
5 *
6 * Based on asm-parisc/atomic.h Copyright (C) 2000 Philipp Rumpf
7 */
9 #include <asm/atomic.h>
10 #include <linux/spinlock.h>
11 #include <linux/module.h>
13 #ifdef CONFIG_SMP
14 #define ATOMIC_HASH_SIZE 4
15 #define ATOMIC_HASH(a) (&__atomic_hash[(((unsigned long)a)>>8) & (ATOMIC_HASH_SIZE-1)])
17 spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] = {
18 [0 ... (ATOMIC_HASH_SIZE-1)] = SPIN_LOCK_UNLOCKED
19 };
21 #else /* SMP */
23 static DEFINE_SPINLOCK(dummy);
24 #define ATOMIC_HASH_SIZE 1
25 #define ATOMIC_HASH(a) (&dummy)
27 #endif /* SMP */
29 int __atomic_add_return(int i, atomic_t *v)
30 {
31 int ret;
32 unsigned long flags;
33 spin_lock_irqsave(ATOMIC_HASH(v), flags);
35 ret = (v->counter += i);
37 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
38 return ret;
39 }
40 EXPORT_SYMBOL(__atomic_add_return);
42 int atomic_cmpxchg(atomic_t *v, int old, int new)
43 {
44 int ret;
45 unsigned long flags;
47 spin_lock_irqsave(ATOMIC_HASH(v), flags);
48 ret = v->counter;
49 if (likely(ret == old))
50 v->counter = new;
52 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
53 return ret;
54 }
56 int atomic_add_unless(atomic_t *v, int a, int u)
57 {
58 int ret;
59 unsigned long flags;
61 spin_lock_irqsave(ATOMIC_HASH(v), flags);
62 ret = v->counter;
63 if (ret != u)
64 v->counter += a;
65 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
66 return ret != u;
67 }
69 /* Atomic operations are already serializing */
70 void atomic_set(atomic_t *v, int i)
71 {
72 unsigned long flags;
74 spin_lock_irqsave(ATOMIC_HASH(v), flags);
75 v->counter = i;
76 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
77 }
78 EXPORT_SYMBOL(atomic_set);