X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=memory.c;h=50602239a41c85ede74e124c5e52ef7848ce0ee0;hp=76da8a86269e859889366c283281815e9ffac1dc;hb=19ddc35b9b97be5af371bb65e93a4864d1dce7b6;hpb=4a995ddae8b12d20efc2367ad4e1c9b159f96eed diff --git a/memory.c b/memory.c index 76da8a86..50602239 100644 --- a/memory.c +++ b/memory.c @@ -63,6 +63,7 @@ int fio_pin_memory(struct thread_data *td) static int alloc_mem_shm(struct thread_data *td, unsigned int total_mem) { +#ifndef CONFIG_NO_SHM int flags = IPC_CREAT | S_IRUSR | S_IWUSR; if (td->o.mem_type == MEM_SHMHUGE) { @@ -104,15 +105,21 @@ static int alloc_mem_shm(struct thread_data *td, unsigned int total_mem) } return 0; +#else + log_err("fio: shm not supported\n"); + return 1; +#endif } static void free_mem_shm(struct thread_data *td) { +#ifndef CONFIG_NO_SHM struct shmid_ds sbuf; dprint(FD_MEM, "shmdt/ctl %d %p\n", td->shm_id, td->orig_buffer); shmdt(td->orig_buffer); shmctl(td->shm_id, IPC_RMID, &sbuf); +#endif } static int alloc_mem_mmap(struct thread_data *td, size_t total_mem) @@ -139,12 +146,14 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem) return 1; } if (td->o.mem_type != MEM_MMAPHUGE && + td->o.mem_type != MEM_MMAPSHARED && ftruncate(td->mmapfd, total_mem) < 0) { td_verror(td, errno, "truncate mmap file"); td->orig_buffer = NULL; return 1; } - if (td->o.mem_type == MEM_MMAPHUGE) + if (td->o.mem_type == MEM_MMAPHUGE || + td->o.mem_type == MEM_MMAPSHARED) flags |= MAP_SHARED; else flags |= MAP_PRIVATE; @@ -158,7 +167,7 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem) if (td->orig_buffer == MAP_FAILED) { td_verror(td, errno, "mmap"); td->orig_buffer = NULL; - if (td->mmapfd != 1) { + if (td->mmapfd != 1 && td->mmapfd != -1) { close(td->mmapfd); if (td->o.mmapfile) unlink(td->o.mmapfile); @@ -224,7 +233,8 @@ int allocate_io_mem(struct thread_data *td) ret = alloc_mem_malloc(td, total_mem); else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE) ret = alloc_mem_shm(td, total_mem); - else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE) + else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE || + td->o.mem_type == MEM_MMAPSHARED) ret = alloc_mem_mmap(td, total_mem); else { log_err("fio: bad mem type: %d\n", td->o.mem_type); @@ -249,7 +259,8 @@ void free_io_mem(struct thread_data *td) free_mem_malloc(td); else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE) free_mem_shm(td); - else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE) + else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE || + td->o.mem_type == MEM_MMAPSHARED) free_mem_mmap(td, total_mem); else log_err("Bad memory type %u\n", td->o.mem_type);