Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MAP_ANONYMOUS|MAP_SHARED instead of unlinked file in /tmp #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ extern void __attribute__((weak)) testcase_prepare(unsigned long nr_tasks) { }
extern void __attribute__((weak)) testcase_cleanup(void) { }
extern void *testcase(unsigned long long *iterations, unsigned long nr);

#ifdef __linux__
static char *initialise_shared_area(unsigned long size)
{
char *m;
int page_size = getpagesize();

/* Align to page boundary */
size = (size + page_size-1) & ~(page_size-1);

m = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, -1, 0);
if (m == MAP_FAILED) {
perror("initialise_shared_area: mmap");
exit(1);
}

if (madvise(m, size, MADV_NOHUGEPAGE) == -1) {
perror("initialise_shared_area: madvise");
exit(1);
}

return m;
}
#else
static char *initialise_shared_area(unsigned long size)
{
char template[] = "/tmp/shared_area_XXXXXX";
Expand Down Expand Up @@ -65,6 +88,7 @@ static char *initialise_shared_area(unsigned long size)

return m;
}
#endif

static void usage(char *command)
{
Expand Down