bulk commit
[LbmBenchmarkKernelsPublic.git] / src / Memory.c
index d9d1f942c7e11c3c8ddf05e4d2d5ab58fac1f24e..e7dda39419bb03f143bf6777186d755ed3717a64 100644 (file)
 //  along with LbmBenchKernels.  If not, see <http://www.gnu.org/licenses/>.
 //
 // --------------------------------------------------------------------------
+// TODO: make configurable
+#define HAVE_HUGE_PAGES
+
+
+#ifdef HAVE_HUGE_PAGES
+#define _BSD_SOURCE
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>  // strerror
 #include <errno.h>
 
+
+#ifdef HAVE_HUGE_PAGES
+#include <sys/mman.h> // madvise
+#endif
+
 #include "Base.h"
 #include "Memory.h"
 
@@ -60,6 +73,19 @@ int MemAllocAligned(void ** ptr, size_t bytesToAlloc, size_t alignmentBytes)
                exit(1);
        }
 
+#ifdef HAVE_HUGE_PAGES
+
+       if (alignmentBytes % 4096 == 0) {
+               ret = madvise(*ptr, bytesToAlloc, MADV_HUGEPAGE);
+
+               if (ret != 0) {
+                       DEBUG_BREAK_POINT();
+                       Error("madvise(%p, %lu, MADV_HUGEPAGE) failed: %d - %s.\n", *ptr, bytesToAlloc, errno, strerror(errno));
+                       exit(1);
+               }
+       }
+#endif
+
        return 0;
 }
 
This page took 0.056972 seconds and 5 git commands to generate.