On (09/10/08 20:20), Andy Whitcroft didst pronounce:
> Allow resize of specific pools via the --pool-minimum-adjust and
> --pool-maximum-adjust commands.  The first affects the number of static
> pages in the pool, the second affects the number of overcommit pages
> for the pool.  These are exposed as lower and upper bound on the pool
> to match the display in --pool-list.  Adjustments are either absolute,
> or relative with a + or - prefix.  For exmaple the following incantion
> increases the 2MB page pool minimum by 10 pages.
> 
>       --pool-minimum-adjust 2048kb:+10
> 
> Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
> ---
>  hpoolcfg.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 84 insertions(+), 2 deletions(-)
> 
> diff --git a/hpoolcfg.c b/hpoolcfg.c
> index 9e21864..8b70389 100644
> --- a/hpoolcfg.c
> +++ b/hpoolcfg.c
> @@ -35,6 +35,7 @@
>  
>  #define REPORT_UTIL "hpoolcfg"
>  #include "libhugetlbfs_internal.h"
> +#include "hugetlbfs.h"
>  
>  extern int optind;
>  extern char *optarg;
> @@ -48,6 +49,10 @@ void print_usage()
>       fprintf(stderr, "options:\n");
>  
>       OPTION("--pool-list", "List all pools");
> +     OPTION("--pool-pages-min <size>=[+|-]<count>", "");
> +     CONT("Adjust pool 'size' lower bound");
> +     OPTION("--pool-pages-max <size>=[+|-]<count>", "");
> +     CONT("Adjust pool 'size' upper bound");
>  
>       OPTION("--help, -h", "Prints this message");
>  }
> @@ -57,8 +62,10 @@ int opt_dry_run = 0;
>  /*
>   * getopts return values for options which are long only.
>   */
> -#define LONG_POOL    ('p' << 8)
> -#define LONG_POOL_LIST       (LONG_POOL|'l')
> +#define LONG_POOL            ('p' << 8)
> +#define LONG_POOL_LIST               (LONG_POOL|'l')
> +#define LONG_POOL_MIN_ADJ    (LONG_POOL|'m')
> +#define LONG_POOL_MAX_ADJ    (LONG_POOL|'M')
>  
>  #define MAX_POOLS    32
>  void pool_list(void)
> @@ -81,6 +88,71 @@ void pool_list(void)
>       }
>  }
>  
> +void pool_adjust(char *cmd, unsigned int counter)
> +{
> +     struct hpage_pool pools[MAX_POOLS];
> +     int pos;
> +     int cnt;
> +
> +     char *iter = NULL;
> +     char *page_size_str = NULL;
> +     char *adjust_str = NULL;
> +     long page_size;
> +     long adjust;
> +     unsigned long base = 0;
> +
> +     /* Extract the pagesize and adjustment. */
> +     page_size_str = strtok_r(cmd, ":", &iter);
> +     if (page_size_str)
> +             adjust_str = strtok_r(NULL, ":", &iter);
> +
> +     if (!page_size_str || !adjust_str) {
> +             ERROR("%s: invalid resize specificiation\n", cmd);
> +             exit(EXIT_FAILURE);
> +     }
> +     DEBUG("page_size<%s> adjust<%s> counter<%d>\n",
> +                                     page_size_str, adjust_str, counter);
> +
> +     /* Convert and validate the page_size. */
> +     page_size = __lh_parse_page_size(page_size_str);
> +
> +     cnt = __lh_hpool_sizes(pools, MAX_POOLS);
> +     if (cnt < 0) {
> +             ERROR("unable to obtain pools list");
> +             exit(EXIT_FAILURE);
> +     }
> +     for (pos = 0; cnt--; pos++) {
> +             if (pools[pos].pagesize_kb == page_size)
> +                     break;
> +     }
> +     if (cnt < 0) {
> +             ERROR("%s: unknown page size\n", page_size_str);
> +             exit(EXIT_FAILURE);
> +     }
> +
> +     /* Convert and validate the adjust. */
> +     adjust = strtol(adjust_str, NULL, 0);
> +     
> +     if (adjust_str[0] == '+' || adjust_str[0] == '-') {
> +
> +             /*
> +              * XXX: reading HUGEPAGES_TOTAL gives you the total pages
> +              * in use not what you wrote.
> +              */
> +             if (counter == HUGEPAGES_TOTAL)
> +                     base = pools[pos].minimum;
> +             else if (counter == HUGEPAGES_OC)
> +                     base = pools[pos].maximum - pools[pos].minimum;
> +             else
> +                     base = get_huge_page_counter(page_size, counter);
> +     } else {
> +             if (counter == HUGEPAGES_OC)
> +                     base = -pools[pos].minimum;
> +     }
> +     adjust += base;
> +     set_huge_page_counter(page_size, counter, adjust);

Nothing stops adjust going negative here or wrapping

> +}
> +
>  int main(int argc, char** argv)
>  {
>       char opts[] = "+h";
> @@ -89,6 +161,8 @@ int main(int argc, char** argv)
>               {"help",       no_argument, NULL, 'h'},
>  
>               {"pool-list", no_argument, NULL, LONG_POOL_LIST},
> +             {"pool-pages-min", required_argument, NULL, LONG_POOL_MIN_ADJ},
> +             {"pool-pages-max", required_argument, NULL, LONG_POOL_MAX_ADJ},
>  
>               {0},
>       };
> @@ -113,6 +187,14 @@ int main(int argc, char** argv)
>                       pool_list();
>                       break;
>  
> +             case LONG_POOL_MIN_ADJ:
> +                     pool_adjust(optarg, HUGEPAGES_TOTAL);
> +                     break;
> +
> +             case LONG_POOL_MAX_ADJ:
> +                     pool_adjust(optarg, HUGEPAGES_OC);
> +                     break;
> +
>               default:
>                       WARNING("unparsed option %08x\n", ret);
>                       ret = -1;
> -- 
> 1.6.0.1.451.gc8d31
> 

-- 
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to