First snapshot of FIO for Windows
[fio.git] / memory.c
index 9b49d3986fc78584743cc4e047cd11cdfdd7e4ac..39fb9f237bb6fcb3d2a378997ed6debe71e2f236 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -63,16 +63,20 @@ int fio_pin_memory(void)
 
 static int alloc_mem_shm(struct thread_data *td, unsigned int total_mem)
 {
-       int flags = IPC_CREAT | SHM_R | SHM_W;
+       int flags = IPC_CREAT | S_IRUSR | S_IWUSR;
+
+       if (td->o.mem_type == MEM_SHMHUGE) {
+               unsigned long mask = td->o.hugepage_size - 1;
 
-       if (td->o.mem_type == MEM_SHMHUGE)
                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);
        if (td->shm_id < 0) {
                td_verror(td, errno, "shmget");
-               if (geteuid() != 0 && errno == ENOMEM)
+               if (geteuid() != 0 && (errno == ENOMEM || errno == EPERM))
                        log_err("fio: you may need to run this job as root\n");
                if (td->o.mem_type == MEM_SHMHUGE) {
                        if (errno == EINVAL) {
@@ -177,7 +181,7 @@ static void free_mem_malloc(struct thread_data *td)
 }
 
 /*
- * Setup the buffer area we need for io.
+ * Set up the buffer area we need for io.
  */
 int allocate_io_mem(struct thread_data *td)
 {
@@ -189,7 +193,8 @@ int allocate_io_mem(struct thread_data *td)
 
        total_mem = td->orig_buffer_size;
 
-       if (td->o.odirect || td->o.mem_align) {
+       if (td->o.odirect || td->o.mem_align ||
+           (td->io_ops->flags & FIO_MEMALIGN)) {
                total_mem += page_mask;
                if (td->o.mem_align && td->o.mem_align > page_size)
                        total_mem += td->o.mem_align - page_size;