Skip to content

Instantly share code, notes, and snippets.

@kzk
Created April 6, 2011 05:33
Show Gist options
  • Save kzk/905194 to your computer and use it in GitHub Desktop.
Save kzk/905194 to your computer and use it in GitHub Desktop.
# TransparentHugePage/ libhugetlbfs Benchmark Test
# with...
# Intel(R) Xeon(R) CPU X3430 @ 2.40GHz
# 8Gmem
# THP: enable
# HUGETLBFS: disable
$ echo "always" >/sys/kernel/mm/redhat_transparent_hugepage/enabled
$ echo "0"> /proc/sys/vm/nr_hugepages
$ gcc -O2 a.c; ./a.out
0.562741
# THP: disable
# HUGETLBFS: disable
$ echo "never" >/sys/kernel/mm/redhat_transparent_hugepage/enabled
$ echo "0"> /proc/sys/vm/nr_hugepages
$ gcc -O2 a.c; ./a.out
1.424639
# THP: disable
# HUGETLBFS: enable
$ echo "never" >/sys/kernel/mm/redhat_transparent_hugepage/enabled
$ echo "1024"> /proc/sys/vm/nr_hugepages
$ mount -t hugetlbfs -o mode=0777 none /mnt/hugetlbfs
$ gcc -O2 a.c
$ LD_PRELOAD=/usr/lib64/libhugetlbfs.so HUGETLB_MORECORE=yes ./a.out
0.561169
$ cat a.c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <strings.h>
double gettimeofday_sec()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + (double)tv.tv_usec*1e-6;
}
#define nr_access 50000000UL
int ofs[nr_access];
int main()
{
size_t size = 1024UL*1024*1024*1;
char *p = (char*)malloc(size);
bzero(p, size);
long i;
for (i = 0; i < nr_access; i++)
ofs[i] = random() % size;
double t1 = gettimeofday_sec();
for (i = 0; i < nr_access; i++) {
p[ofs[i]] = '0' + ofs[i];
}
double t2 = gettimeofday_sec();
printf("%f\n", t2-t1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment