From 74b025b071b5bfbffa7ad7682b66b749e8d1f955 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 19 Dec 2006 15:18:14 +0100 Subject: [PATCH] [PATCH] Support for hugetlb backed shared memory Signed-off-by: Jens Axboe --- HOWTO | 2 ++ fio.c | 7 ++++++- fio.h | 1 + init.c | 10 +++++++++- memory.c | 9 +++++++-- os-linux.h | 1 + os.h | 7 +++++++ 7 files changed, 33 insertions(+), 4 deletions(-) diff --git a/HOWTO b/HOWTO index a5caea3d..6ac744cd 100644 --- a/HOWTO +++ b/HOWTO @@ -357,6 +357,8 @@ mem=str Fio can use various types of memory as the io unit buffer. shm Use shared memory as the buffers. Allocated through shmget(2). + shmhuge Same as shm, but use huge pages as backing. + mmap Use anonymous memory maps as the buffers. Allocated through mmap(2). diff --git a/fio.c b/fio.c index 3ffe1e17..87136141 100644 --- a/fio.c +++ b/fio.c @@ -507,7 +507,12 @@ static int init_io_u(struct thread_data *td) max_units = td->iodepth; max_bs = max(td->max_bs[DDIR_READ], td->max_bs[DDIR_WRITE]); - td->orig_buffer_size = max_bs * max_units + MASK; + td->orig_buffer_size = max_bs * max_units; + + if (td->mem_type == MEM_SHMHUGE) + td->orig_buffer_size = (td->orig_buffer_size + FIO_HUGE_PAGE - 1) & ~FIO_HUGE_PAGE; + else + td->orig_buffer_size += MASK; if (allocate_io_mem(td)) return 1; diff --git a/fio.h b/fio.h index f0b4e6a1..c4facfbe 100644 --- a/fio.h +++ b/fio.h @@ -123,6 +123,7 @@ struct group_run_stats { enum fio_memtype { MEM_MALLOC = 0, /* ordinary malloc */ MEM_SHM, /* use shared memory segments */ + MEM_SHMHUGE, /* use shared memory segments with huge pages */ MEM_MMAP, /* use anonynomous mmap */ }; diff --git a/init.c b/init.c index ae960302..bfe69810 100644 --- a/init.c +++ b/init.c @@ -833,9 +833,17 @@ static int str_mem_cb(void *data, const char *mem) } else if (!strncmp(mem, "mmap", 4)) { td->mem_type = MEM_MMAP; return 0; + } else if (!strncmp(mem, "shmhuge", 7)) { +#ifdef FIO_HAVE_HUGETLB + td->mem_type = MEM_SHMHUGE; + return 0; +#else + log_err("fio: shmhuge not available\n"); + return 1; +#endif } - log_err("fio: mem type: malloc, shm, mmap\n"); + log_err("fio: mem type: malloc, shm, mmap, shmhuge\n"); return 1; } diff --git a/memory.c b/memory.c index 39dc250c..a7bf82a8 100644 --- a/memory.c +++ b/memory.c @@ -61,8 +61,13 @@ int allocate_io_mem(struct thread_data *td) { if (td->mem_type == MEM_MALLOC) td->orig_buffer = malloc(td->orig_buffer_size); - else if (td->mem_type == MEM_SHM) { - td->shm_id = shmget(IPC_PRIVATE, td->orig_buffer_size, IPC_CREAT | 0600); + else if (td->mem_type == MEM_SHM || td->mem_type == MEM_SHMHUGE) { + int flags = IPC_CREAT | SHM_R | SHM_W; + + if (td->mem_type == MEM_SHMHUGE) + flags |= SHM_HUGETLB; + + td->shm_id = shmget(IPC_PRIVATE, td->orig_buffer_size, flags); if (td->shm_id < 0) { td_verror(td, errno); perror("shmget"); diff --git a/os-linux.h b/os-linux.h index 752d17e1..e456ebca 100644 --- a/os-linux.h +++ b/os-linux.h @@ -18,6 +18,7 @@ #define FIO_HAVE_SPLICE #define FIO_HAVE_IOSCHED_SWITCH #define FIO_HAVE_ODIRECT +#define FIO_HAVE_HUGETLB #define OS_MAP_ANON (MAP_ANONYMOUS) diff --git a/os.h b/os.h index b44d34c6..b5f43e59 100644 --- a/os.h +++ b/os.h @@ -47,4 +47,11 @@ #define OS_O_DIRECT O_DIRECT #endif +#ifndef FIO_HAVE_HUGETLB +#define SHM_HUGETLB 0 +#define FIO_HUGE_PAGE 0 +#else +#define FIO_HUGE_PAGE (2048 * 1024) +#endif + #endif -- 2.25.1