ia64/linux-2.6.18-xen.hg

view drivers/acpi/glue.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 * Link physical devices with ACPI devices support
3 *
4 * Copyright (c) 2005 David Shaohua Li <shaohua.li@intel.com>
5 * Copyright (c) 2005 Intel Corp.
6 *
7 * This file is released under the GPLv2.
8 */
9 #include <linux/init.h>
10 #include <linux/list.h>
11 #include <linux/device.h>
12 #include <linux/rwsem.h>
13 #include <linux/acpi.h>
15 #define ACPI_GLUE_DEBUG 0
16 #if ACPI_GLUE_DEBUG
17 #define DBG(x...) printk(PREFIX x)
18 #else
19 #define DBG(x...)
20 #endif
21 static LIST_HEAD(bus_type_list);
22 static DECLARE_RWSEM(bus_type_sem);
24 int register_acpi_bus_type(struct acpi_bus_type *type)
25 {
26 if (acpi_disabled)
27 return -ENODEV;
28 if (type && type->bus && type->find_device) {
29 down_write(&bus_type_sem);
30 list_add_tail(&type->list, &bus_type_list);
31 up_write(&bus_type_sem);
32 printk(KERN_INFO PREFIX "bus type %s registered\n",
33 type->bus->name);
34 return 0;
35 }
36 return -ENODEV;
37 }
39 EXPORT_SYMBOL(register_acpi_bus_type);
41 int unregister_acpi_bus_type(struct acpi_bus_type *type)
42 {
43 if (acpi_disabled)
44 return 0;
45 if (type) {
46 down_write(&bus_type_sem);
47 list_del_init(&type->list);
48 up_write(&bus_type_sem);
49 printk(KERN_INFO PREFIX "ACPI bus type %s unregistered\n",
50 type->bus->name);
51 return 0;
52 }
53 return -ENODEV;
54 }
56 EXPORT_SYMBOL(unregister_acpi_bus_type);
58 static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
59 {
60 struct acpi_bus_type *tmp, *ret = NULL;
62 down_read(&bus_type_sem);
63 list_for_each_entry(tmp, &bus_type_list, list) {
64 if (tmp->bus == type) {
65 ret = tmp;
66 break;
67 }
68 }
69 up_read(&bus_type_sem);
70 return ret;
71 }
73 static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
74 {
75 struct acpi_bus_type *tmp;
76 int ret = -ENODEV;
78 down_read(&bus_type_sem);
79 list_for_each_entry(tmp, &bus_type_list, list) {
80 if (tmp->find_bridge && !tmp->find_bridge(dev, handle)) {
81 ret = 0;
82 break;
83 }
84 }
85 up_read(&bus_type_sem);
86 return ret;
87 }
89 /* Get PCI root bridge's handle from its segment and bus number */
90 struct acpi_find_pci_root {
91 unsigned int seg;
92 unsigned int bus;
93 acpi_handle handle;
94 };
96 static acpi_status
97 do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
98 {
99 unsigned long *busnr = (unsigned long *)data;
100 struct acpi_resource_address64 address;
102 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
103 resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
104 resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
105 return AE_OK;
107 acpi_resource_to_address64(resource, &address);
108 if ((address.address_length > 0) &&
109 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
110 *busnr = address.minimum;
112 return AE_OK;
113 }
115 static int get_root_bridge_busnr(acpi_handle handle)
116 {
117 acpi_status status;
118 unsigned long bus, bbn;
119 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
121 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
123 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL,
124 &bbn);
125 if (status == AE_NOT_FOUND) {
126 /* Assume bus = 0 */
127 printk(KERN_INFO PREFIX
128 "Assume root bridge [%s] bus is 0\n",
129 (char *)buffer.pointer);
130 status = AE_OK;
131 bbn = 0;
132 }
133 if (ACPI_FAILURE(status)) {
134 bbn = -ENODEV;
135 goto exit;
136 }
137 if (bbn > 0)
138 goto exit;
140 /* _BBN in some systems return 0 for all root bridges */
141 bus = -1;
142 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
143 do_root_bridge_busnr_callback, &bus);
144 /* If _CRS failed, we just use _BBN */
145 if (ACPI_FAILURE(status) || (bus == -1))
146 goto exit;
147 /* We select _CRS */
148 if (bbn != bus) {
149 printk(KERN_INFO PREFIX
150 "_BBN and _CRS returns different value for %s. Select _CRS\n",
151 (char *)buffer.pointer);
152 bbn = bus;
153 }
154 exit:
155 kfree(buffer.pointer);
156 return (int)bbn;
157 }
159 static acpi_status
160 find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
161 {
162 struct acpi_find_pci_root *find = (struct acpi_find_pci_root *)context;
163 unsigned long seg, bus;
164 acpi_status status;
165 int tmp;
166 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
168 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
170 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &seg);
171 if (status == AE_NOT_FOUND) {
172 /* Assume seg = 0 */
173 status = AE_OK;
174 seg = 0;
175 }
176 if (ACPI_FAILURE(status)) {
177 status = AE_CTRL_DEPTH;
178 goto exit;
179 }
181 tmp = get_root_bridge_busnr(handle);
182 if (tmp < 0) {
183 printk(KERN_ERR PREFIX
184 "Find root bridge failed for %s\n",
185 (char *)buffer.pointer);
186 status = AE_CTRL_DEPTH;
187 goto exit;
188 }
189 bus = tmp;
191 if (seg == find->seg && bus == find->bus)
192 find->handle = handle;
193 status = AE_OK;
194 exit:
195 kfree(buffer.pointer);
196 return status;
197 }
199 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
200 {
201 struct acpi_find_pci_root find = { seg, bus, NULL };
203 acpi_get_devices(PCI_ROOT_HID_STRING, find_pci_rootbridge, &find, NULL);
204 return find.handle;
205 }
206 EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
208 /* Get device's handler per its address under its parent */
209 struct acpi_find_child {
210 acpi_handle handle;
211 acpi_integer address;
212 };
214 static acpi_status
215 do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
216 {
217 acpi_status status;
218 struct acpi_device_info *info;
219 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
220 struct acpi_find_child *find = (struct acpi_find_child *)context;
222 status = acpi_get_object_info(handle, &buffer);
223 if (ACPI_SUCCESS(status)) {
224 info = buffer.pointer;
225 if (info->address == find->address)
226 find->handle = handle;
227 kfree(buffer.pointer);
228 }
229 return AE_OK;
230 }
232 acpi_handle acpi_get_child(acpi_handle parent, acpi_integer address)
233 {
234 struct acpi_find_child find = { NULL, address };
236 if (!parent)
237 return NULL;
238 acpi_walk_namespace(ACPI_TYPE_DEVICE, parent,
239 1, do_acpi_find_child, &find, NULL);
240 return find.handle;
241 }
243 EXPORT_SYMBOL(acpi_get_child);
245 /* Link ACPI devices with physical devices */
246 static void acpi_glue_data_handler(acpi_handle handle,
247 u32 function, void *context)
248 {
249 /* we provide an empty handler */
250 }
252 /* Note: a success call will increase reference count by one */
253 struct device *acpi_get_physical_device(acpi_handle handle)
254 {
255 acpi_status status;
256 struct device *dev;
258 status = acpi_get_data(handle, acpi_glue_data_handler, (void **)&dev);
259 if (ACPI_SUCCESS(status))
260 return get_device(dev);
261 return NULL;
262 }
264 EXPORT_SYMBOL(acpi_get_physical_device);
266 static int acpi_bind_one(struct device *dev, acpi_handle handle)
267 {
268 acpi_status status;
270 if (dev->firmware_data) {
271 printk(KERN_WARNING PREFIX
272 "Drivers changed 'firmware_data' for %s\n", dev->bus_id);
273 return -EINVAL;
274 }
275 get_device(dev);
276 status = acpi_attach_data(handle, acpi_glue_data_handler, dev);
277 if (ACPI_FAILURE(status)) {
278 put_device(dev);
279 return -EINVAL;
280 }
281 dev->firmware_data = handle;
283 return 0;
284 }
286 static int acpi_unbind_one(struct device *dev)
287 {
288 if (!dev->firmware_data)
289 return 0;
290 if (dev == acpi_get_physical_device(dev->firmware_data)) {
291 /* acpi_get_physical_device increase refcnt by one */
292 put_device(dev);
293 acpi_detach_data(dev->firmware_data, acpi_glue_data_handler);
294 dev->firmware_data = NULL;
295 /* acpi_bind_one increase refcnt by one */
296 put_device(dev);
297 } else {
298 printk(KERN_ERR PREFIX
299 "Oops, 'firmware_data' corrupt for %s\n", dev->bus_id);
300 }
301 return 0;
302 }
304 static int acpi_platform_notify(struct device *dev)
305 {
306 struct acpi_bus_type *type;
307 acpi_handle handle;
308 int ret = -EINVAL;
310 if (!dev->bus || !dev->parent) {
311 /* bridge devices genernally haven't bus or parent */
312 ret = acpi_find_bridge_device(dev, &handle);
313 goto end;
314 }
315 type = acpi_get_bus_type(dev->bus);
316 if (!type) {
317 DBG("No ACPI bus support for %s\n", dev->bus_id);
318 ret = -EINVAL;
319 goto end;
320 }
321 if ((ret = type->find_device(dev, &handle)) != 0)
322 DBG("Can't get handler for %s\n", dev->bus_id);
323 end:
324 if (!ret)
325 acpi_bind_one(dev, handle);
327 #if ACPI_GLUE_DEBUG
328 if (!ret) {
329 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer);
332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer);
333 kfree(buffer.pointer);
334 } else
335 DBG("Device %s -> No ACPI support\n", dev->bus_id);
336 #endif
338 return ret;
339 }
341 static int acpi_platform_notify_remove(struct device *dev)
342 {
343 acpi_unbind_one(dev);
344 return 0;
345 }
347 static int __init init_acpi_device_notify(void)
348 {
349 if (acpi_disabled)
350 return 0;
351 if (platform_notify || platform_notify_remove) {
352 printk(KERN_ERR PREFIX "Can't use platform_notify\n");
353 return 0;
354 }
355 platform_notify = acpi_platform_notify;
356 platform_notify_remove = acpi_platform_notify_remove;
357 return 0;
358 }
360 arch_initcall(init_acpi_device_notify);