current changes
This commit is contained in:
@@ -24,22 +24,81 @@ int count = 0; /* number of bytes allocated so far*/
|
||||
int max = 0; /* upper limit for count */
|
||||
char *buffer = NULL; /* the allocation buffer */
|
||||
|
||||
void init_alloc(int size_in_bytes)
|
||||
void init_alloc()
|
||||
{
|
||||
/* request memory for our allocation buffer
|
||||
* NB mmap min bounds for capability is 1 page (4K)
|
||||
*/
|
||||
char *res = mmap(NULL, size_in_bytes, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
// /* request memory for our allocation buffer
|
||||
// * NB mmap min bounds for capability is 1 page (4K)
|
||||
// */
|
||||
// char *res = mmap(NULL, size_in_bytes, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
|
||||
if (res == MAP_FAILED)
|
||||
// if (res == MAP_FAILED)
|
||||
// {
|
||||
// perror("error in initial mem allocation");
|
||||
// exit(-1);
|
||||
// }
|
||||
|
||||
// buffer = res;
|
||||
// max = size_in_bytes;
|
||||
// return;
|
||||
|
||||
size_t sz;
|
||||
// Pre Allocate 400 MB
|
||||
sz = 1073741824;
|
||||
|
||||
int error, fd, pscnt, pn;
|
||||
|
||||
size_t ps[MAXPAGESIZES];
|
||||
|
||||
size_t size[3];
|
||||
|
||||
pn = getpagesizes(size, 3);
|
||||
printf("page size is [%d]", size[2]);
|
||||
|
||||
pscnt = pagesizes(ps);
|
||||
|
||||
fd = shm_create_largepage(SHM_ANON, O_CREAT | O_RDWR, 1, SHM_LARGEPAGE_ALLOC_DEFAULT, 0);
|
||||
|
||||
if (fd < 0 && errno == ENOTTY) {
|
||||
perror("sh_create_largepages");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// if (fd < 0)
|
||||
// perror("no large page supported");
|
||||
// exit(EXIT_FAILURE);
|
||||
// if (fd < 0 && errno == ENOTTY)
|
||||
// atf_tc_skip("no large page support");
|
||||
// ATF_REQUIRE_MSG(fd >= 0, "shm_create_largepage failed; errno=%d", errno);
|
||||
|
||||
if (ftruncate(fd, sz) < 0) {
|
||||
perror("ftruncate");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// if (error != 0 && errno == ENOMEM)
|
||||
// /*
|
||||
// * The test system might not have enough memory to accommodate
|
||||
// * the request.
|
||||
// */
|
||||
// atf_tc_skip("failed to allocate %zu-byte superpage", sz);
|
||||
// ATF_REQUIRE_MSG(error == 0, "ftruncate failed; errno=%d", errno);
|
||||
|
||||
ptr = mmap(NULL, sz,
|
||||
PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
|
||||
|
||||
// Added error handling
|
||||
if(ptr == MAP_FAILED)
|
||||
{
|
||||
perror("error in initial mem allocation");
|
||||
exit(-1);
|
||||
perror("mmap");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
buffer = res;
|
||||
max = size_in_bytes;
|
||||
return;
|
||||
buffer = ptr;
|
||||
|
||||
// Hard-coded huge page size
|
||||
max = 1073741824;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user