ia64/linux-2.6.18-xen.hg

annotate lib/cmdline.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
rev   line source
ian@0 1 /*
ian@0 2 * linux/lib/cmdline.c
ian@0 3 * Helper functions generally used for parsing kernel command line
ian@0 4 * and module options.
ian@0 5 *
ian@0 6 * Code and copyrights come from init/main.c and arch/i386/kernel/setup.c.
ian@0 7 *
ian@0 8 * This source code is licensed under the GNU General Public License,
ian@0 9 * Version 2. See the file COPYING for more details.
ian@0 10 *
ian@0 11 * GNU Indent formatting options for this file: -kr -i8 -npsl -pcs
ian@0 12 *
ian@0 13 */
ian@0 14
ian@0 15 #include <linux/module.h>
ian@0 16 #include <linux/kernel.h>
ian@0 17 #include <linux/string.h>
ian@0 18
ian@0 19
ian@0 20 /**
ian@0 21 * get_option - Parse integer from an option string
ian@0 22 * @str: option string
ian@0 23 * @pint: (output) integer value parsed from @str
ian@0 24 *
ian@0 25 * Read an int from an option string; if available accept a subsequent
ian@0 26 * comma as well.
ian@0 27 *
ian@0 28 * Return values:
ian@0 29 * 0 : no int in string
ian@0 30 * 1 : int found, no subsequent comma
ian@0 31 * 2 : int found including a subsequent comma
ian@0 32 */
ian@0 33
ian@0 34 int get_option (char **str, int *pint)
ian@0 35 {
ian@0 36 char *cur = *str;
ian@0 37
ian@0 38 if (!cur || !(*cur))
ian@0 39 return 0;
ian@0 40 *pint = simple_strtol (cur, str, 0);
ian@0 41 if (cur == *str)
ian@0 42 return 0;
ian@0 43 if (**str == ',') {
ian@0 44 (*str)++;
ian@0 45 return 2;
ian@0 46 }
ian@0 47
ian@0 48 return 1;
ian@0 49 }
ian@0 50
ian@0 51 /**
ian@0 52 * get_options - Parse a string into a list of integers
ian@0 53 * @str: String to be parsed
ian@0 54 * @nints: size of integer array
ian@0 55 * @ints: integer array
ian@0 56 *
ian@0 57 * This function parses a string containing a comma-separated
ian@0 58 * list of integers. The parse halts when the array is
ian@0 59 * full, or when no more numbers can be retrieved from the
ian@0 60 * string.
ian@0 61 *
ian@0 62 * Return value is the character in the string which caused
ian@0 63 * the parse to end (typically a null terminator, if @str is
ian@0 64 * completely parseable).
ian@0 65 */
ian@0 66
ian@0 67 char *get_options(const char *str, int nints, int *ints)
ian@0 68 {
ian@0 69 int res, i = 1;
ian@0 70
ian@0 71 while (i < nints) {
ian@0 72 res = get_option ((char **)&str, ints + i);
ian@0 73 if (res == 0)
ian@0 74 break;
ian@0 75 i++;
ian@0 76 if (res == 1)
ian@0 77 break;
ian@0 78 }
ian@0 79 ints[0] = i - 1;
ian@0 80 return (char *)str;
ian@0 81 }
ian@0 82
ian@0 83 /**
ian@0 84 * memparse - parse a string with mem suffixes into a number
ian@0 85 * @ptr: Where parse begins
ian@0 86 * @retptr: (output) Pointer to next char after parse completes
ian@0 87 *
ian@0 88 * Parses a string into a number. The number stored at @ptr is
ian@0 89 * potentially suffixed with %K (for kilobytes, or 1024 bytes),
ian@0 90 * %M (for megabytes, or 1048576 bytes), or %G (for gigabytes, or
ian@0 91 * 1073741824). If the number is suffixed with K, M, or G, then
ian@0 92 * the return value is the number multiplied by one kilobyte, one
ian@0 93 * megabyte, or one gigabyte, respectively.
ian@0 94 */
ian@0 95
ian@0 96 unsigned long long memparse (char *ptr, char **retptr)
ian@0 97 {
ian@0 98 unsigned long long ret = simple_strtoull (ptr, retptr, 0);
ian@0 99
ian@0 100 switch (**retptr) {
ian@0 101 case 'G':
ian@0 102 case 'g':
ian@0 103 ret <<= 10;
ian@0 104 case 'M':
ian@0 105 case 'm':
ian@0 106 ret <<= 10;
ian@0 107 case 'K':
ian@0 108 case 'k':
ian@0 109 ret <<= 10;
ian@0 110 (*retptr)++;
ian@0 111 default:
ian@0 112 break;
ian@0 113 }
ian@0 114 return ret;
ian@0 115 }
ian@0 116
ian@0 117
ian@0 118 EXPORT_SYMBOL(memparse);
ian@0 119 EXPORT_SYMBOL(get_option);
ian@0 120 EXPORT_SYMBOL(get_options);