This patch adds a check for MAP_HUGETLB support and a flag in
__hugetlb_opts for holding the availability.

Signed-off-by: Eric B Munson <emun...@mgebm.net>
---
 hugeutils.c             |   21 +++++++++++++++++++++
 init.c                  |    1 +
 libhugetlbfs_internal.h |    3 +++
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/hugeutils.c b/hugeutils.c
index 3b442c3..646dea1 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -340,6 +340,27 @@ void hugetlbfs_check_safe_noreserve()
        }
 }
 
+void hugetlbfs_check_map_hugetlb()
+{
+/*
+ * FIXME: MAP_HUGETLB has not been picked up by glibc so even though the
+ * kernel may support it, without the userspace mmap flag it cannot be
+ * used.  This ifdef should be removed when the MAP_HUGETLB flag makes it
+ * into glibc.
+ */
+#ifdef MAP_HUGETLB
+       /*
+        * Kernels after 2.6.32 support mmaping pseudo-anonymous regions
+        * backed by huge pages, use this feature for huge pages we
+        * don't intend to share.
+        */
+       if (hugetlbfs_test_feature(HUGETLB_FEATURE_MAP_HUGETLB) > 0) {
+               INFO("Kernel supports MAP_HUGETLB\n");
+               __hugetlb_opts.map_hugetlb = 1;
+       }
+#endif
+}
+
 /*
  * Pool counters are typically exposed in sysfs in modern kernels, the
  * counters for the default page size are exposed in procfs in all kernels
diff --git a/init.c b/init.c
index 049c9e2..c7f5a05 100644
--- a/init.c
+++ b/init.c
@@ -27,6 +27,7 @@ static void __attribute__ ((constructor)) 
setup_libhugetlbfs(void)
        setup_features();
        hugetlbfs_check_priv_resv();
        hugetlbfs_check_safe_noreserve();
+       hugetlbfs_check_map_hugetlb();
 #ifndef NO_ELFLINK
        hugetlbfs_setup_elflink();
 #endif
diff --git a/libhugetlbfs_internal.h b/libhugetlbfs_internal.h
index 6e9379e..ace64bd 100644
--- a/libhugetlbfs_internal.h
+++ b/libhugetlbfs_internal.h
@@ -61,6 +61,7 @@ struct libhugeopts_t {
        int             shrink_ok;
        int             shm_enabled;
        int             no_reserve;
+       int             map_hugetlb;
        unsigned long   force_elfmap;
        char            *ld_preload;
        char            *elfmap;
@@ -103,6 +104,8 @@ extern void setup_features();
 extern void hugetlbfs_check_priv_resv();
 #define hugetlbfs_check_safe_noreserve __lh_hugetlbfs_check_safe_noreserve
 extern void hugetlbfs_check_safe_noreserve();
+#define hugetlbfs_check_map_hugetlb __lh_hugetblfs_check_map_hugetlb
+extern void hugetlbfs_check_map_hugetlb();
 #define __hugetlbfs_hostname __lh___hugetlbfs_hostname
 extern char __hugetlbfs_hostname[];
 #define hugetlbfs_prefault __lh_hugetlbfs_prefault
-- 
1.7.1


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to