Make sure shmhuge allocations are huge page size aligned
authorJens Axboe <jens.axboe@oracle.com>
Sat, 12 Sep 2009 19:33:51 +0000 (21:33 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 12 Sep 2009 19:33:51 +0000 (21:33 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
memory.c

index 9b49d39..5285c0a 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -65,8 +65,12 @@ static int alloc_mem_shm(struct thread_data *td, unsigned int total_mem)
 {
        int flags = IPC_CREAT | SHM_R | SHM_W;
 
-       if (td->o.mem_type == MEM_SHMHUGE)
+       if (td->o.mem_type == MEM_SHMHUGE) {
+               unsigned long mask = td->o.hugepage_size - 1;
+
                flags |= SHM_HUGETLB;
+               total_mem = (total_mem + mask) & ~mask;
+       }
 
        td->shm_id = shmget(IPC_PRIVATE, total_mem, flags);
        dprint(FD_MEM, "shmget %u, %d\n", total_mem, td->shm_id);