aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@shadowen.org>2008-10-22 16:23:22 +0100
committerAndy Whitcroft <apw@shadowen.org>2008-10-24 13:19:32 +0100
commit9b1efd2840b0cf26eb8b0a52b55ed4d80d9e0b07 (patch)
tree0047dacef6a44ddee4632f13a97f5a5fa14dba9f
parentea45ea0c9067bda5f31ea489a0895ef99dd9d051 (diff)
downloadlibhugetlbfs-9b1efd2840b0cf26eb8b0a52b55ed4d80d9e0b07.tar.gz
hugeadm: check for and report the lack of hugepage support in the kernel
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 <apw@shadowen.org> Acked-by: Eric B Munson <ebmunson@us.ibm.com> Acked-by: Mel Gorman <mel@csn.ul.ie>
-rw-r--r--hugeadm.c9
-rw-r--r--hugeutils.c13
-rw-r--r--libhugetlbfs_privutils.h3
3 files changed, 25 insertions, 0 deletions
diff --git a/hugeadm.c b/hugeadm.c
index 036d603..530fe63 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,14 @@ 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;
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);