invalidate=x Invalidate page cache for file prior to doing io
sync=x Use sync writes if x and writing
mem=x If x == malloc, use malloc for buffers. If x == shm,
- use shm for buffers.
+ use shm for buffers. If x == mmap, use anon mmap.
exitall When one thread quits, terminate the others
bwavgtime=x Average bandwidth stats over x msec
create_serialize=x If 'x', serialize file creation.
shmdt(td->orig_buffer);
shmctl(td->shm_id, IPC_RMID, &sbuf);
- }
+ } else if (td->mem_type == MEM_MMAP)
+ munmap(td->orig_buffer, td->orig_buffer_size);
+ else
+ fprintf(stderr, "Bad memory type %d\n", td->mem_type);
+
+ td->orig_buffer = NULL;
}
static int init_io_u(struct thread_data *td)
{
struct io_u *io_u;
- int i, max_units, mem_size;
+ int i, max_units;
char *p;
if (!td->use_aio)
else
max_units = td->aio_depth;
- mem_size = td->max_bs * max_units + MASK;
+ td->orig_buffer_size = td->max_bs * max_units + MASK;
if (td->mem_type == MEM_MALLOC)
- td->orig_buffer = malloc(mem_size);
+ td->orig_buffer = malloc(td->orig_buffer_size);
else if (td->mem_type == MEM_SHM) {
- td->shm_id = shmget(IPC_PRIVATE, mem_size, IPC_CREAT | 0600);
+ td->shm_id = shmget(IPC_PRIVATE, td->orig_buffer_size, IPC_CREAT | 0600);
if (td->shm_id < 0) {
td->error = errno;
perror("shmget");
if (td->orig_buffer == (void *) -1) {
td->error = errno;
perror("shmat");
+ td->orig_buffer = NULL;
+ return 1;
+ }
+ } else if (td->mem_type == MEM_MMAP) {
+ td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ if (td->orig_buffer == MAP_FAILED) {
+ td->error = errno;
+ perror("mmap");
+ td->orig_buffer = NULL;
return 1;
}
}
void *mmap;
pid_t pid;
char *orig_buffer;
+ size_t orig_buffer_size;
volatile int terminate;
volatile int runstate;
volatile int old_runstate;
DDIR_WRITE,
};
+/*
+ * What type of allocation to use for io buffers
+ */
enum {
- MEM_MALLOC,
- MEM_SHM,
+ MEM_MALLOC, /* ordinary malloc */
+ MEM_SHM, /* use shared memory segments */
+ MEM_MMAP, /* use anonynomous mmap */
};
+/*
+ * The type of object we are working on
+ */
enum {
FIO_TYPE_FILE = 1,
FIO_TYPE_BD,