ia64/linux-2.6.18-xen.hg

view lib/kref.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 * kref.c - library routines for handling generic reference counted objects
3 *
4 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2004 IBM Corp.
6 *
7 * based on lib/kobject.c which was:
8 * Copyright (C) 2002-2003 Patrick Mochel <mochel@osdl.org>
9 *
10 * This file is released under the GPLv2.
11 *
12 */
14 #include <linux/kref.h>
15 #include <linux/module.h>
17 /**
18 * kref_init - initialize object.
19 * @kref: object in question.
20 */
21 void kref_init(struct kref *kref)
22 {
23 atomic_set(&kref->refcount,1);
24 }
26 /**
27 * kref_get - increment refcount for object.
28 * @kref: object.
29 */
30 void kref_get(struct kref *kref)
31 {
32 WARN_ON(!atomic_read(&kref->refcount));
33 atomic_inc(&kref->refcount);
34 }
36 /**
37 * kref_put - decrement refcount for object.
38 * @kref: object.
39 * @release: pointer to the function that will clean up the object when the
40 * last reference to the object is released.
41 * This pointer is required, and it is not acceptable to pass kfree
42 * in as this function.
43 *
44 * Decrement the refcount, and if 0, call release().
45 * Return 1 if the object was removed, otherwise return 0. Beware, if this
46 * function returns 0, you still can not count on the kref from remaining in
47 * memory. Only use the return value if you want to see if the kref is now
48 * gone, not present.
49 */
50 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
51 {
52 WARN_ON(release == NULL);
53 WARN_ON(release == (void (*)(struct kref *))kfree);
55 /*
56 * if current count is one, we are the last user and can release object
57 * right now, avoiding an atomic operation on 'refcount'
58 */
59 if ((atomic_read(&kref->refcount) == 1) ||
60 (atomic_dec_and_test(&kref->refcount))) {
61 release(kref);
62 return 1;
63 }
64 return 0;
65 }
67 EXPORT_SYMBOL(kref_init);
68 EXPORT_SYMBOL(kref_get);
69 EXPORT_SYMBOL(kref_put);