ia64/linux-2.6.18-xen.hg

view drivers/acpi/namespace/nswalk.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 *
3 * Module Name: nswalk - Functions for walking the ACPI namespace
4 *
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
44 #include <acpi/acpi.h>
45 #include <acpi/acnamesp.h>
47 #define _COMPONENT ACPI_NAMESPACE
48 ACPI_MODULE_NAME("nswalk")
50 /*******************************************************************************
51 *
52 * FUNCTION: acpi_ns_get_next_node
53 *
54 * PARAMETERS: Type - Type of node to be searched for
55 * parent_node - Parent node whose children we are
56 * getting
57 * child_node - Previous child that was found.
58 * The NEXT child will be returned
59 *
60 * RETURN: struct acpi_namespace_node - Pointer to the NEXT child or NULL if
61 * none is found.
62 *
63 * DESCRIPTION: Return the next peer node within the namespace. If Handle
64 * is valid, Scope is ignored. Otherwise, the first node
65 * within Scope is returned.
66 *
67 ******************************************************************************/
68 struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type,
69 struct acpi_namespace_node
70 *parent_node,
71 struct acpi_namespace_node
72 *child_node)
73 {
74 struct acpi_namespace_node *next_node = NULL;
76 ACPI_FUNCTION_ENTRY();
78 if (!child_node) {
80 /* It's really the parent's _scope_ that we want */
82 if (parent_node->child) {
83 next_node = parent_node->child;
84 }
85 }
87 else {
88 /* Start search at the NEXT node */
90 next_node = acpi_ns_get_next_valid_node(child_node);
91 }
93 /* If any type is OK, we are done */
95 if (type == ACPI_TYPE_ANY) {
97 /* next_node is NULL if we are at the end-of-list */
99 return (next_node);
100 }
102 /* Must search for the node -- but within this scope only */
104 while (next_node) {
106 /* If type matches, we are done */
108 if (next_node->type == type) {
109 return (next_node);
110 }
112 /* Otherwise, move on to the next node */
114 next_node = acpi_ns_get_next_valid_node(next_node);
115 }
117 /* Not found */
119 return (NULL);
120 }
122 /*******************************************************************************
123 *
124 * FUNCTION: acpi_ns_walk_namespace
125 *
126 * PARAMETERS: Type - acpi_object_type to search for
127 * start_node - Handle in namespace where search begins
128 * max_depth - Depth to which search is to reach
129 * unlock_before_callback- Whether to unlock the NS before invoking
130 * the callback routine
131 * user_function - Called when an object of "Type" is found
132 * Context - Passed to user function
133 * return_value - from the user_function if terminated early.
134 * Otherwise, returns NULL.
135 * RETURNS: Status
136 *
137 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
138 * starting (and ending) at the node specified by start_handle.
139 * The user_function is called whenever a node that matches
140 * the type parameter is found. If the user function returns
141 * a non-zero value, the search is terminated immediately and this
142 * value is returned to the caller.
143 *
144 * The point of this procedure is to provide a generic namespace
145 * walk routine that can be called from multiple places to
146 * provide multiple services; the User Function can be tailored
147 * to each task, whether it is a print function, a compare
148 * function, etc.
149 *
150 ******************************************************************************/
152 acpi_status
153 acpi_ns_walk_namespace(acpi_object_type type,
154 acpi_handle start_node,
155 u32 max_depth,
156 u8 unlock_before_callback,
157 acpi_walk_callback user_function,
158 void *context, void **return_value)
159 {
160 acpi_status status;
161 acpi_status mutex_status;
162 struct acpi_namespace_node *child_node;
163 struct acpi_namespace_node *parent_node;
164 acpi_object_type child_type;
165 u32 level;
167 ACPI_FUNCTION_TRACE(ns_walk_namespace);
169 /* Special case for the namespace Root Node */
171 if (start_node == ACPI_ROOT_OBJECT) {
172 start_node = acpi_gbl_root_node;
173 }
175 /* Null child means "get first node" */
177 parent_node = start_node;
178 child_node = NULL;
179 child_type = ACPI_TYPE_ANY;
180 level = 1;
182 /*
183 * Traverse the tree of nodes until we bubble back up to where we
184 * started. When Level is zero, the loop is done because we have
185 * bubbled up to (and passed) the original parent handle (start_entry)
186 */
187 while (level > 0) {
189 /* Get the next node in this scope. Null if not found */
191 status = AE_OK;
192 child_node =
193 acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node,
194 child_node);
195 if (child_node) {
196 /*
197 * Found node, Get the type if we are not
198 * searching for ANY
199 */
200 if (type != ACPI_TYPE_ANY) {
201 child_type = child_node->type;
202 }
204 if (child_type == type) {
205 /*
206 * Found a matching node, invoke the user
207 * callback function
208 */
209 if (unlock_before_callback) {
210 mutex_status =
211 acpi_ut_release_mutex
212 (ACPI_MTX_NAMESPACE);
213 if (ACPI_FAILURE(mutex_status)) {
214 return_ACPI_STATUS
215 (mutex_status);
216 }
217 }
219 status = user_function(child_node, level,
220 context, return_value);
222 if (unlock_before_callback) {
223 mutex_status =
224 acpi_ut_acquire_mutex
225 (ACPI_MTX_NAMESPACE);
226 if (ACPI_FAILURE(mutex_status)) {
227 return_ACPI_STATUS
228 (mutex_status);
229 }
230 }
232 switch (status) {
233 case AE_OK:
234 case AE_CTRL_DEPTH:
236 /* Just keep going */
237 break;
239 case AE_CTRL_TERMINATE:
241 /* Exit now, with OK status */
243 return_ACPI_STATUS(AE_OK);
245 default:
247 /* All others are valid exceptions */
249 return_ACPI_STATUS(status);
250 }
251 }
253 /*
254 * Depth first search:
255 * Attempt to go down another level in the namespace
256 * if we are allowed to. Don't go any further if we
257 * have reached the caller specified maximum depth
258 * or if the user function has specified that the
259 * maximum depth has been reached.
260 */
261 if ((level < max_depth) && (status != AE_CTRL_DEPTH)) {
262 if (acpi_ns_get_next_node
263 (ACPI_TYPE_ANY, child_node, NULL)) {
264 /*
265 * There is at least one child of this
266 * node, visit the onde
267 */
268 level++;
269 parent_node = child_node;
270 child_node = NULL;
271 }
272 }
273 } else {
274 /*
275 * No more children of this node (acpi_ns_get_next_node
276 * failed), go back upwards in the namespace tree to
277 * the node's parent.
278 */
279 level--;
280 child_node = parent_node;
281 parent_node = acpi_ns_get_parent_node(parent_node);
282 }
283 }
285 /* Complete walk, not terminated by user function */
287 return_ACPI_STATUS(AE_OK);
288 }