From: Jens Axboe Date: Fri, 18 Nov 2005 10:10:00 +0000 (+0100) Subject: [PATCH] Add mem=mmap option to use anon mmap for buffer memory X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=891e70f85ee35826fee5cefd0c533f900635dc59;p=disktools.git [PATCH] Add mem=mmap option to use anon mmap for buffer memory --- diff --git a/README.fio b/README.fio index ed9cae2..f789bce 100644 --- a/README.fio +++ b/README.fio @@ -47,7 +47,7 @@ The format is as follows: 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. diff --git a/fio-ini.c b/fio-ini.c index 55347ac..4a8f474 100644 --- a/fio-ini.c +++ b/fio-ini.c @@ -608,6 +608,11 @@ int parse_jobs_ini(char *file) fgetpos(f, &off); continue; } + if (!check_str(p, "mem", "mmap")) { + td->mem_type = MEM_MMAP; + fgetpos(f, &off); + continue; + } if (!check_strset(p, "sequential")) { td->sequential = 1; fgetpos(f, &off); diff --git a/fio.c b/fio.c index c46b5ac..976e0a6 100644 --- a/fio.c +++ b/fio.c @@ -1105,13 +1105,18 @@ static void cleanup_io_u(struct thread_data *td) 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) @@ -1119,12 +1124,12 @@ static int init_io_u(struct thread_data *td) 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"); @@ -1135,6 +1140,15 @@ static int init_io_u(struct thread_data *td) 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; } } diff --git a/fio.h b/fio.h index 6dfdc47..b8d3967 100644 --- a/fio.h +++ b/fio.h @@ -64,6 +64,7 @@ struct thread_data { void *mmap; pid_t pid; char *orig_buffer; + size_t orig_buffer_size; volatile int terminate; volatile int runstate; volatile int old_runstate; @@ -179,11 +180,18 @@ enum { 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,