2 * librpma_fio_pmem2: allocates pmem using libpmem2.
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 "libpmem2"
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)
25 struct pmem2_config *cfg = NULL;
26 struct pmem2_map *map = NULL;
27 struct pmem2_source *src = NULL;
31 if((fd = open(f->file_name, O_RDWR)) < 0) {
32 log_err("fio: cannot open fio file\n");
36 if (pmem2_source_from_fd(&src, fd) != 0) {
37 log_err("fio: pmem2_source_from_fd() failed\n");
41 if (pmem2_config_new(&cfg) != 0) {
42 log_err("fio: pmem2_config_new() failed\n");
43 goto err_source_delete;
46 if (pmem2_config_set_required_store_granularity(cfg,
47 PMEM2_GRANULARITY_CACHE_LINE) != 0) {
48 log_err("fio: pmem2_config_set_required_store_granularity() failed: %s\n", pmem2_errormsg());
49 goto err_config_delete;
52 if (pmem2_map_new(&map, cfg, src) != 0) {
53 log_err("fio: pmem2_map_new(%s) failed: %s\n", f->file_name, pmem2_errormsg());
54 goto err_config_delete;
57 size_mmap = pmem2_map_get_size(map);
59 /* check size of allocated persistent memory */
60 if (size_mmap < ws_offset + size) {
62 "fio: %s is too small to handle so many threads (%zu < %zu)\n",
63 f->file_name, size_mmap, ws_offset + size);
67 mem->mem_ptr = pmem2_map_get_address(map);
68 mem->size_mmap = size_mmap;
70 pmem2_config_delete(&cfg);
71 pmem2_source_delete(&src);
77 pmem2_map_delete(&map);
79 pmem2_config_delete(&cfg);
81 pmem2_source_delete(&src);
88 static inline void librpma_fio_unmap(struct librpma_fio_mem *mem)
90 (void) pmem2_map_delete(&mem->map);