On Wed, Oct 22, 2008 at 04:59:56PM +0100, Andy Whitcroft wrote:
> A lot of commands simply will go horribly wrong if we do not have hugepage
> support in the kernel.  Check for and error out if we do not have hugepage
> support.  Note that we still allow usage checks and the like regardless.
> 
> Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
> ---
>  hugeadm.c                |   11 +++++++++++
>  hugeutils.c              |   13 +++++++++++++
>  libhugetlbfs_privutils.h |    3 +++
>  3 files changed, 27 insertions(+), 0 deletions(-)
> 
> diff --git a/hugeadm.c b/hugeadm.c
> index 036d603..c642555 100644
> --- a/hugeadm.c
> +++ b/hugeadm.c
> @@ -249,6 +249,7 @@ void page_sizes(int all)
>  int main(int argc, char** argv)
>  {
>       int ops;
> +     int has_hugepages = kernel_has_hugepages();
>  
>       char opts[] = "+h";
>       int ret = 0, index = 0;
> @@ -283,6 +284,16 @@ int main(int argc, char** argv)
>                       print_usage();
>                       exit(EXIT_SUCCESS);
>  
> +             default:
> +                     /* All other commands require hugepage support. */
> +                     if (! has_hugepages) {
> +                             ERROR("kernel does not support huge pages\n");
> +                             exit(EXIT_FAILURE);
> +                     }
> +             }
> +
> +
> +             switch (ret) {
>               case LONG_POOL_LIST:
>                       pool_list();
>                       break;

Spurious whitespace change there

> diff --git a/hugeutils.c b/hugeutils.c
> index 36a91c0..a3a677d 100644
> --- a/hugeutils.c
> +++ b/hugeutils.c
> @@ -539,6 +539,19 @@ int hpool_sizes(struct hpage_pool *pools, int pcnt)
>  }
>  
>  /*
> + * If we have a default page size then we support hugepages.
> + */
> +int kernel_has_hugepages(void)
> +{
> +     long default_size = file_read_ulong(MEMINFO, "Hugepagesize:");
> +     default_size = size_to_smaller_unit(default_size);
> +     if (default_size < 0)
> +             return 0;
> +
> +     return 1;
> +}
> +
> +/*
>   * If we can find the default page size, and if we can find an overcommit
>   * control for it then the kernel must support overcommit.
>   */
> diff --git a/libhugetlbfs_privutils.h b/libhugetlbfs_privutils.h
> index e11583b..4e01aac 100644
> --- a/libhugetlbfs_privutils.h
> +++ b/libhugetlbfs_privutils.h
> @@ -52,6 +52,9 @@ int set_nr_hugepages(long pagesize, unsigned long val);
>  #define set_nr_overcommit_hugepages __pu_set_nr_overcommit_hugepages
>  int set_nr_overcommit_hugepages(long pagesize, unsigned long val);
>  
> +#define kernel_has_hugepages __pu_kernel_has_hugepages
> +int kernel_has_hugepages(void);
> +
>  #define kernel_has_overcommit __pu_kernel_has_overcommit
>  int kernel_has_overcommit(void);
>  
> -- 
> 1.6.0.2.711.gf1ba4
> 

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