2 * librpma_fio_pmem: allocates pmem using libpmem.
4 * Copyright 2022, Intel Corporation
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License,
8 * version 2 as published by the Free Software Foundation..
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include "librpma_fio.h"
19 #define RPMA_PMEM_USED "libpmem"
21 static int librpma_fio_pmem_map_file(struct fio_file *f, size_t size,
22 struct librpma_fio_mem *mem, size_t ws_offset)
28 mem->mem_ptr = pmem_map_file(f->file_name, 0 /* len */, 0 /* flags */,
29 0 /* mode */, &size_mmap, &is_pmem);
30 if (mem->mem_ptr == NULL) {
31 /* pmem_map_file() sets errno on failure */
32 log_err("fio: pmem_map_file(%s) failed: %s (errno %i)\n",
33 f->file_name, strerror(errno), errno);
37 /* pmem is expected */
39 log_err("fio: %s is not located in persistent memory\n",
44 /* check size of allocated persistent memory */
45 if (size_mmap < ws_offset + size) {
47 "fio: %s is too small to handle so many threads (%zu < %zu)\n",
48 f->file_name, size_mmap, ws_offset + size);
52 log_info("fio: size of memory mapped from the file %s: %zu\n",
53 f->file_name, size_mmap);
55 mem->size_mmap = size_mmap;
60 (void) pmem_unmap(mem->mem_ptr, size_mmap);
64 static inline void librpma_fio_unmap(struct librpma_fio_mem *mem)
66 (void) pmem_unmap(mem->mem_ptr, mem->size_mmap);