ia64/linux-2.6.18-xen.hg

view drivers/md/dm-path-selector.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 * Copyright (C) 2003 Sistina Software.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
4 *
5 * Module Author: Heinz Mauelshagen
6 *
7 * This file is released under the GPL.
8 *
9 * Path selector registration.
10 */
12 #include "dm.h"
13 #include "dm-path-selector.h"
15 #include <linux/slab.h>
17 struct ps_internal {
18 struct path_selector_type pst;
20 struct list_head list;
21 long use;
22 };
24 #define pst_to_psi(__pst) container_of((__pst), struct ps_internal, pst)
26 static LIST_HEAD(_path_selectors);
27 static DECLARE_RWSEM(_ps_lock);
29 static struct ps_internal *__find_path_selector_type(const char *name)
30 {
31 struct ps_internal *psi;
33 list_for_each_entry(psi, &_path_selectors, list) {
34 if (!strcmp(name, psi->pst.name))
35 return psi;
36 }
38 return NULL;
39 }
41 static struct ps_internal *get_path_selector(const char *name)
42 {
43 struct ps_internal *psi;
45 down_read(&_ps_lock);
46 psi = __find_path_selector_type(name);
47 if (psi) {
48 if ((psi->use == 0) && !try_module_get(psi->pst.module))
49 psi = NULL;
50 else
51 psi->use++;
52 }
53 up_read(&_ps_lock);
55 return psi;
56 }
58 struct path_selector_type *dm_get_path_selector(const char *name)
59 {
60 struct ps_internal *psi;
62 if (!name)
63 return NULL;
65 psi = get_path_selector(name);
66 if (!psi) {
67 request_module("dm-%s", name);
68 psi = get_path_selector(name);
69 }
71 return psi ? &psi->pst : NULL;
72 }
74 void dm_put_path_selector(struct path_selector_type *pst)
75 {
76 struct ps_internal *psi;
78 if (!pst)
79 return;
81 down_read(&_ps_lock);
82 psi = __find_path_selector_type(pst->name);
83 if (!psi)
84 goto out;
86 if (--psi->use == 0)
87 module_put(psi->pst.module);
89 BUG_ON(psi->use < 0);
91 out:
92 up_read(&_ps_lock);
93 }
95 static struct ps_internal *_alloc_path_selector(struct path_selector_type *pst)
96 {
97 struct ps_internal *psi = kmalloc(sizeof(*psi), GFP_KERNEL);
99 if (psi) {
100 memset(psi, 0, sizeof(*psi));
101 psi->pst = *pst;
102 }
104 return psi;
105 }
107 int dm_register_path_selector(struct path_selector_type *pst)
108 {
109 int r = 0;
110 struct ps_internal *psi = _alloc_path_selector(pst);
112 if (!psi)
113 return -ENOMEM;
115 down_write(&_ps_lock);
117 if (__find_path_selector_type(pst->name)) {
118 kfree(psi);
119 r = -EEXIST;
120 } else
121 list_add(&psi->list, &_path_selectors);
123 up_write(&_ps_lock);
125 return r;
126 }
128 int dm_unregister_path_selector(struct path_selector_type *pst)
129 {
130 struct ps_internal *psi;
132 down_write(&_ps_lock);
134 psi = __find_path_selector_type(pst->name);
135 if (!psi) {
136 up_write(&_ps_lock);
137 return -EINVAL;
138 }
140 if (psi->use) {
141 up_write(&_ps_lock);
142 return -ETXTBSY;
143 }
145 list_del(&psi->list);
147 up_write(&_ps_lock);
149 kfree(psi);
151 return 0;
152 }
154 EXPORT_SYMBOL_GPL(dm_register_path_selector);
155 EXPORT_SYMBOL_GPL(dm_unregister_path_selector);