From: Jens Axboe Date: Thu, 24 Mar 2016 23:07:05 +0000 (-0600) Subject: t/memlock: sample utility to use X memory from Y threads X-Git-Tag: fio-2.9~17 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=ae46d0f5618d1d2e63d0a733b79f136d88ccac90 t/memlock: sample utility to use X memory from Y threads Signed-off-by: Jens Axboe --- diff --git a/Makefile b/Makefile index 07609e65..007ae400 100644 --- a/Makefile +++ b/Makefile @@ -234,6 +234,9 @@ T_VS_PROGS = t/fio-verify-state T_PIPE_ASYNC_OBJS = t/read-to-pipe-async.o T_PIPE_ASYNC_PROGS = t/read-to-pipe-async +T_MEMLOCK_OBJS = t/memlock.o +T_MEMLOCK_PROGS = t/memlock + T_OBJS = $(T_SMALLOC_OBJS) T_OBJS += $(T_IEEE_OBJS) T_OBJS += $(T_ZIPF_OBJS) @@ -244,6 +247,7 @@ T_OBJS += $(T_BTRACE_FIO_OBJS) T_OBJS += $(T_DEDUPE_OBJS) T_OBJS += $(T_VS_OBJS) T_OBJS += $(T_PIPE_ASYNC_OBJS) +T_OBJS += $(T_MEMLOCK_OBJS) ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS))) T_DEDUPE_OBJS += os/windows/posix.o lib/hweight.o @@ -379,6 +383,9 @@ printing.o: printing.c printing.h t/read-to-pipe-async: $(T_PIPE_ASYNC_OBJS) $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_PIPE_ASYNC_OBJS) $(LIBS) +t/memlock: $(T_MEMLOCK_OBJS) + $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_MEMLOCK_OBJS) $(LIBS) + t/stest: $(T_SMALLOC_OBJS) $(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_SMALLOC_OBJS) $(LIBS) diff --git a/t/memlock.c b/t/memlock.c new file mode 100644 index 00000000..d9d586d8 --- /dev/null +++ b/t/memlock.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +static struct thread_data { + unsigned long mb; +} td; + +static void *worker(void *data) +{ + struct thread_data *td = data; + unsigned long index; + size_t size; + char *buf; + int i, first = 1; + + size = td->mb * 1024UL * 1024UL; + buf = malloc(size); + + for (i = 0; i < 100000; i++) { + for (index = 0; index + 4096 < size; index += 4096) + memset(&buf[index+512], 0x89, 512); + if (first) { + printf("loop%d: did %lu MB\n", i+1, size/(1024UL*1024UL)); + first = 0; + } + } + return NULL; +} + +int main(int argc, char *argv[]) +{ + unsigned long mb, threads; + pthread_t *pthreads; + int i; + + if (argc < 3) { + printf("%s: \n", argv[0]); + return 1; + } + + mb = strtoul(argv[1], NULL, 10); + threads = strtoul(argv[2], NULL, 10); + + pthreads = calloc(threads, sizeof(pthread_t)); + td.mb = mb; + + for (i = 0; i < threads; i++) + pthread_create(&pthreads[i], NULL, worker, &td); + + for (i = 0; i < threads; i++) { + void *ret; + + pthread_join(pthreads[i], &ret); + } + return 0; +}