summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
c51074e)
We have the stuff in place for huge page backed memory, so it's little
extra code to support io buffers inside mmap file backed memory.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
shmhuge Same as shm, but use huge pages as backing.
shmhuge Same as shm, but use huge pages as backing.
- mmap Use anonymous memory maps as the buffers.
- Allocated through mmap(2).
+ mmap Use mmap to allocate buffers. May either be
+ anonymous memory, or can be file backed if
+ a filename is given after the option. The
+ format is mem=mmap:/path/to/file.
mmaphuge Use a memory mapped huge file as the buffer
backing. Append filename after mmaphuge, ala
mmaphuge Use a memory mapped huge file as the buffer
backing. Append filename after mmaphuge, ala
unsigned long long zone_size;
unsigned long long zone_skip;
enum fio_memtype mem_type;
unsigned long long zone_size;
unsigned long long zone_skip;
enum fio_memtype mem_type;
- char *hugefile;
- int hugefd;
+ char *mmapfile;
+ int mmapfd;
unsigned int stonewall;
unsigned int numjobs;
unsigned int iodepth;
unsigned int stonewall;
unsigned int numjobs;
unsigned int iodepth;
+/*
+ * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
+ */
+static char *get_mmap_file(const char *str)
+{
+ char *p = strstr(str, ":");
+
+ if (!p)
+ return NULL;
+
+ p++;
+ strip_blank_front(&p);
+ strip_blank_end(p);
+ return strdup(p);
+}
+
static int str_mem_cb(void *data, const char *mem)
{
struct thread_data *td = data;
static int str_mem_cb(void *data, const char *mem)
{
struct thread_data *td = data;
return 0;
} else if (!strncmp(mem, "mmaphuge", 8)) {
#ifdef FIO_HAVE_HUGETLB
return 0;
} else if (!strncmp(mem, "mmaphuge", 8)) {
#ifdef FIO_HAVE_HUGETLB
/*
* mmaphuge must be appended with the actual file
*/
/*
* mmaphuge must be appended with the actual file
*/
- hugefile = strstr(mem, ":");
- if (!hugefile) {
+ td->mmapfile = get_mmap_file(mem);
+ if (!td->mmapfile) {
log_err("fio: mmaphuge:/path/to/file\n");
return 1;
}
log_err("fio: mmaphuge:/path/to/file\n");
return 1;
}
- hugefile++;
- strip_blank_front(&hugefile);
- strip_blank_end(hugefile);
- td->hugefile = strdup(hugefile);
td->mem_type = MEM_MMAPHUGE;
return 0;
#else
td->mem_type = MEM_MMAPHUGE;
return 0;
#else
return 1;
#endif
} else if (!strncmp(mem, "mmap", 4)) {
return 1;
#endif
} else if (!strncmp(mem, "mmap", 4)) {
+ /*
+ * Check if the user wants file backed memory. It's ok
+ * if there's no file given, we'll just use anon mamp then.
+ */
+ td->mmapfile = get_mmap_file(mem);
td->mem_type = MEM_MMAP;
return 0;
} else if (!strncmp(mem, "shmhuge", 7)) {
td->mem_type = MEM_MMAP;
return 0;
} else if (!strncmp(mem, "shmhuge", 7)) {
} else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
int flags = MAP_PRIVATE;
} else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
int flags = MAP_PRIVATE;
- if (td->mem_type == MEM_MMAPHUGE) {
- td->hugefd = open(td->hugefile, O_RDWR|O_CREAT, 0644);
+ if (td->mmapfile) {
+ td->mmapfd = open(td->mmapfile, O_RDWR|O_CREAT, 0644);
- perror("open huge file");
+ perror("open mmap file");
td->orig_buffer = NULL;
return 1;
}
} else
flags |= OS_MAP_ANON;
td->orig_buffer = NULL;
return 1;
}
} else
flags |= OS_MAP_ANON;
- td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, flags, td->hugefd, 0);
+ td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, flags, td->mmapfd, 0);
if (td->orig_buffer == MAP_FAILED) {
td_verror(td, errno);
perror("mmap");
td->orig_buffer = NULL;
if (td->orig_buffer == MAP_FAILED) {
td_verror(td, errno);
perror("mmap");
td->orig_buffer = NULL;
- if (td->hugefd)
- close(td->hugefd);
+ if (td->mmapfd) {
+ close(td->mmapfd);
+ unlink(td->mmapfile);
+ }
shmctl(td->shm_id, IPC_RMID, &sbuf);
} else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
munmap(td->orig_buffer, td->orig_buffer_size);
shmctl(td->shm_id, IPC_RMID, &sbuf);
} else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
munmap(td->orig_buffer, td->orig_buffer_size);
- if (td->mem_type == MEM_MMAPHUGE) {
- close(td->hugefd);
- unlink(td->hugefile);
- free(td->hugefile);
+ if (td->mmapfile) {
+ close(td->mmapfd);
+ unlink(td->mmapfile);
+ free(td->mmapfile);
}
} else
log_err("Bad memory type %u\n", td->mem_type);
}
} else
log_err("Bad memory type %u\n", td->mem_type);