diff --git a/hammersuite/src/allocator.c b/hammersuite/src/allocator.c index 1876ada..d93b52c 100644 --- a/hammersuite/src/allocator.c +++ b/hammersuite/src/allocator.c @@ -1,74 +1,68 @@ #include "allocator.h" -#include -#include -#include +#include +#include #include #include #include -#include -#include -#include #include +#include +#include +#include +#include #include "utils.h" -int alloc_buffer(MemoryBuffer * mem) +int +alloc_buffer(MemoryBuffer *mem) { - if (mem->buffer != NULL) { - fprintf(stderr, "[ERROR] - Memory already allocated\n"); - } + if (mem->buffer != NULL) { fprintf(stderr, "[ERROR] - Memory already allocated\n"); } - if (mem->align < _SC_PAGE_SIZE) { - mem->align = 0; - } + if (mem->align < _SC_PAGE_SIZE) { mem->align = 0; } - uint64_t alloc_size = mem->align ? mem->size + mem->align : mem->size; - uint64_t alloc_flags = MAP_PRIVATE | MAP_POPULATE; + uint64_t alloc_size = mem->align ? mem->size + mem->align : mem->size; + uint64_t alloc_flags = MAP_PRIVATE | MAP_POPULATE; - if (mem->flags & F_ALLOC_HUGE) { - if (mem->fd == 0) { - fprintf(stderr, - "[ERROR] - Missing file descriptor to allocate hugepage\n"); - exit(1); - } - alloc_flags |= - (mem->flags & F_ALLOC_HUGE_1G) ? MAP_ANONYMOUS | MAP_HUGETLB - | (30 << MAP_HUGE_SHIFT) - : (mem->flags & F_ALLOC_HUGE_2M) ? MAP_ANONYMOUS | - MAP_HUGETLB | (21 << MAP_HUGE_SHIFT) - : MAP_ANONYMOUS; - } else { - mem->fd = -1; - alloc_flags |= MAP_ANONYMOUS; - } - mem->buffer = (char *)mmap(NULL, mem->size, PROT_READ | PROT_WRITE, - alloc_flags, mem->fd, 0); - if (mem->buffer == MAP_FAILED) { - perror("[ERROR] - mmap() failed"); - exit(1); - } - if (mem->align) { - size_t error = (uint64_t) mem->buffer % mem->align; - size_t left = error ? mem->align - error : 0; - munmap(mem->buffer, left); - mem->buffer += left; - assert((uint64_t) mem->buffer % mem->align == 0); - } - - if (mem->flags & F_VERBOSE) { - fprintf(stderr, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); - fprintf(stderr, "[ MEM ] - Buffer: %p\n", mem->buffer); - fprintf(stderr, "[ MEM ] - Size: %ld\n", alloc_size); - fprintf(stderr, "[ MEM ] - Alignment: %ld\n", mem->align); - fprintf(stderr, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); - } - return 0; + if (mem->flags & F_ALLOC_HUGE) { + if (mem->fd == 0) { + fprintf(stderr, "[ERROR] - Missing file descriptor to allocate hugepage\n"); + exit(1); + } + alloc_flags |= (mem->flags & F_ALLOC_HUGE_1G) ? MAP_ANONYMOUS | MAP_HUGETLB | (30 << MAP_HUGE_SHIFT) + : (mem->flags & F_ALLOC_HUGE_2M) + ? MAP_ANONYMOUS | MAP_HUGETLB | (21 << MAP_HUGE_SHIFT) + : MAP_ANONYMOUS; + } else { + mem->fd = -1; + alloc_flags |= MAP_ANONYMOUS; + } + mem->buffer = (char *) mmap(NULL, mem->size, PROT_READ | PROT_WRITE, alloc_flags, mem->fd, 0); + if (mem->buffer == MAP_FAILED) { + perror("[ERROR] - mmap() failed"); + fprintf(stderr, "mem->size: %ld\n", mem->size); + exit(1); + } + if (mem->align) { + size_t error = (uint64_t) mem->buffer % mem->align; + size_t left = error ? mem->align - error : 0; + munmap(mem->buffer, left); + mem->buffer += left; + assert((uint64_t) mem->buffer % mem->align == 0); + } + if (mem->flags & F_VERBOSE) { + fprintf(stderr, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + fprintf(stderr, "[ MEM ] - Buffer: %p\n", mem->buffer); + fprintf(stderr, "[ MEM ] - Size: %ld\n", alloc_size); + fprintf(stderr, "[ MEM ] - Alignment: %ld\n", mem->align); + fprintf(stderr, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); + } + return 0; } -int free_buffer(MemoryBuffer * mem) +int +free_buffer(MemoryBuffer *mem) { - free(mem->physmap); - return munmap(mem->buffer, mem->size); + free(mem->physmap); + return munmap(mem->buffer, mem->size); } diff --git a/hammersuite/src/include/params.h b/hammersuite/src/include/params.h index ff18686..f5d49fe 100644 --- a/hammersuite/src/include/params.h +++ b/hammersuite/src/include/params.h @@ -14,7 +14,7 @@ #define HUGETLB_std "/mnt/huge/buff" #define CONFIG_NAME_std "tmp/s_cfg.bin" #define O_FILE_std "DIMM00" -#define ALLOC_SIZE 1 << 29 +#define ALLOC_SIZE 1 << 30 #define ALIGN_std 2 << 20 #define PATT_LEN 1024 #define AGGR_std 2