This patch adds controls for the new THP related functionality in the library.

Signed-off-by: Eric B Munson <emun...@mgebm.net>
---
 hugectl.c     |   36 ++++++++++++++++++++++++++++++++++++
 man/hugectl.8 |   11 +++++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/hugectl.c b/hugectl.c
index e2a9828..a2841fe 100644
--- a/hugectl.c
+++ b/hugectl.c
@@ -67,6 +67,12 @@ void print_usage()
        OPTION("--heap[=<size>]", "Requests remapping of the program heap");
        CONT("(malloc space)");
        OPTION("--shm", "Requests remapping of shared memory segments");
+       OPTION("--thp", "Setup the heap space to be aligned for merging");
+       CONT("by khugepaged into huge pages.  This requires kernel support");
+       CONT("for transparent huge pages to be enabled");
+       OPTION("--thp-madvise", "This option must be used with --thp, when");
+       CONT("space is allocated for the heap, call madvise(MADV_HUGEPAGE)");
+       CONT("for the new area");
 
        OPTION("--no-preload", "Disable preloading the libhugetlbfs library");
        OPTION("--no-reserve", "Disable huge page reservation for segments");
@@ -171,6 +177,10 @@ void verbose_expose(void)
 #define LONG_NO_LIBRARY                (LONG_BASE | 'L')
 #define LONG_LIBRARY           (LONG_BASE | 'l')
 
+#define LONG_THP               ('t' << 8)
+#define LONG_THP_HEAP          (LONG_THP | 'h')
+#define LONG_THP_MADVISE       (LONG_THP | 'm')
+
 /*
  * Mapping selectors, one per remappable/backable area as requested
  * by the user.  These are also used as returns from getopts where they
@@ -341,6 +351,8 @@ int main(int argc, char** argv)
        int opt_preload = 1;
        int opt_no_reserve = 0;
        int opt_share = 0;
+       int opt_thp_heap = 0;
+       int opt_thp_madvise = 0;
        char *opt_library = NULL;
 
        char opts[] = "+hvq";
@@ -365,6 +377,9 @@ int main(int argc, char** argv)
                {"bss",        optional_argument, NULL, MAP_BASE|MAP_BSS},
                {"heap",       optional_argument, NULL, MAP_BASE|MAP_HEAP},
                {"shm",        optional_argument, NULL, MAP_BASE|MAP_SHM},
+               {"thp",        no_argument, NULL, LONG_THP_HEAP},
+               {"thp-madvise",
+                              no_argument, NULL, LONG_THP_MADVISE},
 
                {0},
        };
@@ -398,6 +413,16 @@ int main(int argc, char** argv)
                        quiet();
                        break;
 
+               case LONG_THP_HEAP:
+                       opt_thp_heap = 1;
+                       INFO("Aligning heap for use with THP\n");
+                       break;
+
+               case LONG_THP_MADVISE:
+                       opt_thp_madvise = 1;
+                       INFO("Using madvise(MADV_HUGEPAGE) on heap region\n");
+                       break;
+
                case LONG_NO_PRELOAD:
                        opt_preload = 0;
                        INFO("LD_PRELOAD disabled\n");
@@ -447,6 +472,11 @@ int main(int argc, char** argv)
                exit(EXIT_FAILURE);
        }
 
+       if (opt_thp_madvise && ! opt_thp_heap) {
+               print_usage();
+               exit(EXIT_FAILURE);
+       }
+
        verbose_expose();
 
        if (opt_library != LIBRARY_DISABLE)
@@ -464,6 +494,12 @@ int main(int argc, char** argv)
        if (opt_share)
                setup_environment("HUGETLB_SHARE", "1");
 
+       if (opt_thp_heap)
+               setup_environment("HUGETLB_MORECORE", "thp");
+
+       if (opt_thp_madvise)
+               setup_environment("HUGETLB_THP_MADVISE", "yes");
+
        if (opt_dry_run)
                exit(EXIT_SUCCESS);
 
diff --git a/man/hugectl.8 b/man/hugectl.8
index 319742e..11de2aa 100644
--- a/man/hugectl.8
+++ b/man/hugectl.8
@@ -63,6 +63,17 @@ Request that multiple application instances share text 
segments that are
 backed with huge pages.  This option sets the environment variable
 HUGETLB_SHARE to 1.
 
+.TP
+.B --thp
+Align heap regions to huge page size for promotion by khugepaged.  For more
+information on transparent huge pages see linux-2.6/Documentation/transhuge.txt
+
+.TP
+.B --thp-madvise
+Call madvise(MADV_HUGEPAGE) on new heap regions as they are allocated.  This
+marks the area to be considered by khugepaged when it is only promoting 
madvised
+areas.  This option must be used with --thp
+
 .PP
 The following options affect how \fBhugectl\fP behaves.
 
-- 
1.7.4.1


------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery, 
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now. 
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to