On Fri, 2008-10-03 at 18:37 +0100, Andy Whitcroft wrote:
> 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

I think using a colon separator might make this easier to read:

Set min to 5:   --adjust-pages-min 2048kb:5
Add 2 to min:   --adjust-pages-min 2048kb:+2
Subtract 3:     --adjust-pages-min 2048kb:-3

> 
> 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 e9ac665..7173d09 100644
> --- a/hpoolcfg.c
> +++ b/hpoolcfg.c
> @@ -35,6 +35,7 @@
> 
>  #define REPORT_UTIL "hpoolcfg"
>  #include "libhugetlbfs_internal.h"
> +#include "hugetlbfs.h"
> 
>  extern int errno;
>  extern int optind;
> @@ -49,6 +50,10 @@ void print_usage()
>       fprintf(stderr, "options:\n");
> 
>       OPTION("--pool-list", "List all pools");
> +     OPTION("--pool-minimum-adjust <size>=<count>", "");
> +     CONT("Adjust pool 'size' lower bound to 'count'");
> +     OPTION("--pool-maximum-adjust <size>=<count>", "");
> +     CONT("Adjust pool 'size' upper bound to 'count'");

I don't particularly like these names.  The command itself already
contains 'pool' so adding it to option names seems redundant.  How about
--adjust-pages-min and --adjust-pages-max ?

>       OPTION("--page-sizes", "List all available page sizes");
>       OPTION("--page-sizes-all", "List all supported page sizes");
> @@ -61,8 +66,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 LONG_PAGE    ('P' << 8)
>  #define LONG_PAGE_SIZES      (LONG_PAGE|'s')
> @@ -89,6 +96,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);
> +}
> +
>  void page_sizes(int all)
>  {
>       struct hpage_pool pools[MAX_POOLS];
> @@ -115,6 +187,8 @@ int main(int argc, char** argv)
>               {"help",       no_argument, NULL, 'h'},
> 
>               {"pool-list", no_argument, NULL, LONG_POOL_LIST},
> +             {"pool-minimum-adjust", required_argument, NULL, 
> LONG_POOL_MIN_ADJ},
> +             {"pool-maximum-adjust", required_argument, NULL, 
> LONG_POOL_MAX_ADJ},
> 
>               {"page-sizes", no_argument, NULL, LONG_PAGE_SIZES},
>               {"page-sizes-all", no_argument, NULL, LONG_PAGE_AVAIL},
> @@ -142,6 +216,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;
> +
>               case LONG_PAGE_SIZES:
>                       page_sizes(0);
>                       break;
-- 
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center


-------------------------------------------------------------------------
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