1() PMDK Programmer's Manual ()
2
3
4
6 pmemobj_open(), pmemobj_create(), pmemobj_close(), pmemobj_check()
7 pmemobj_set_user_data(), pmemobj_get_user_data() - create, open, close
8 and validate persistent memory transactional object store
9
11 #include <libpmemobj.h>
12
13 PMEMobjpool *pmemobj_open(const char *path, const char *layout);
14 PMEMobjpool *pmemobj_create(const char *path, const char *layout,
15 size_t poolsize, mode_t mode);
16 void pmemobj_close(PMEMobjpool *pop);
17 int pmemobj_check(const char *path, const char *layout);
18
19 void pmemobj_set_user_data(PMEMobjpool *pop, void *data);
20 void *pmemobj_get_user_data(PMEMobjpool *pop);
21
23 To use the pmem-resident transactional object store provided by libp‐
24 memobj(7), a memory pool must first be created with the pmemobj_cre‐
25 ate() function described below. Existing pools may be opened with the
26 pmemobj_open() function.
27
28 As of libpmemobj 1.11, these functions are thread-safe; be careful if
29 you have to use earlier versions of the library.
30
31 Once created, the memory pool is represented by an opaque handle, of
32 type PMEMobjpool*, which is passed to most of the other libpmemobj(7)
33 functions. Internally, libpmemobj(7) will use either pmem_persist(3)
34 or msync(2) when it needs to flush changes, depending on whether the
35 memory pool appears to be persistent memory or a regular file (see the
36 pmem_is_pmem(3) function in libpmem(7) for more information). There is
37 no need for applications to flush changes directly when using the ob‐
38 ject memory API provided by libpmemobj(7).
39
40 The pmemobj_create() function creates a transactional object store with
41 the given total poolsize. path specifies the name of the memory pool
42 file to be created. layout specifies the application’s layout type in
43 the form of a string. The layout name is not interpreted by libpmemo‐
44 bj(7), but may be used as a check when pmemobj_open() is called. The
45 layout name, including the terminating null byte (`\0'), cannot be
46 longer than PMEMOBJ_MAX_LAYOUT as defined in <libpmemobj.h>. A NULL
47 layout is equivalent to using an empty string as a layout name. mode
48 specifies the permissions to use when creating the file, as described
49 by creat(2). The memory pool file is fully allocated to the size pool‐
50 size using posix_fallocate(3). The caller may choose to take responsi‐
51 bility for creating the memory pool file by creating it before calling
52 pmemobj_create(), and then specifying poolsize as zero. In this case
53 pmemobj_create() will take the pool size from the size of the existing
54 file and will verify that the file appears to be empty by searching for
55 any non-zero data in the pool header at the beginning of the file. The
56 minimum net pool size allowed by the library for a local transactional
57 object store is defined in <libpmemobj.h> as PMEMOBJ_MIN_POOL.
58
59 Depending on the configuration of the system, the available non-
60 volatile memory space may be divided into multiple memory devices. In
61 such case, the maximum size of the pmemobj memory pool could be limited
62 by the capacity of a single memory device. libpmemobj(7) allows build‐
63 ing persistent memory resident object store spanning multiple memory
64 devices by creation of persistent memory pools consisting of multiple
65 files, where each part of such a pool set may be stored on a different
66 memory device or pmem-aware filesystem.
67
68 Creation of all the parts of the pool set can be done with pmemobj_cre‐
69 ate(); however, the recommended method for creating pool sets is with
70 the pmempool(1) utility.
71
72 When creating a pool set consisting of multiple files, the path argu‐
73 ment passed to pmemobj_create() must point to the special set file that
74 defines the pool layout and the location of all the parts of the pool
75 set. The poolsize argument must be 0. The meaning of the layout and
76 mode arguments does not change, except that the same mode is used for
77 creation of all the parts of the pool set.
78
79 The set file is a plain text file, the structure of which is described
80 in poolset(5).
81
82 The pmemobj_open() function opens an existing object store memory pool.
83 Similar to pmemobj_create(), path must identify either an existing obj
84 memory pool file, or the set file used to create a pool set. If layout
85 is non-NULL, it is compared to the layout name provided to pmemobj_cre‐
86 ate() when the pool was first created. This can be used to verify that
87 the layout of the pool matches what was expected. The application must
88 have permission to open the file and memory map it with read/write per‐
89 missions.
90
91 Be aware that if the pool contains bad blocks inside, opening can be
92 aborted by the SIGBUS signal, because currently the pool is not checked
93 against bad blocks during opening. It can be turned on by setting the
94 CHECK_BAD_BLOCKS compat feature. For details see description of this
95 feature in pmempool-feature(1).
96
97 The pmemobj_close() function closes the memory pool indicated by pop
98 and deletes the memory pool handle. The object store itself lives on
99 in the file that contains it and may be re-opened at a later time using
100 pmemobj_open() as described above.
101
102 The pmemobj_check() function performs a consistency check of the file
103 indicated by path. pmemobj_check() opens the given path read-only so
104 it never makes any changes to the file. This function is not supported
105 on Device DAX.
106
107 The pmemobj_set_user_data() function associates custom volatile state,
108 represented by pointer data, with the given pool pop. This state can
109 later be retrieved using pmemobj_get_user_data() function. This state
110 does not survive pool close. If pmemobj_set_user_data() was not called
111 for a given pool, pmemobj_get_user_data() will return NULL.
112
114 The pmemobj_create() function returns a memory pool handle to be used
115 with most of the functions in libpmemobj(7). On error it returns NULL
116 and sets errno appropriately.
117
118 The pmemobj_open() function returns a memory pool handle to be used
119 with most of the functions in libpmemobj(7). If an error prevents the
120 pool from being opened, or if the given layout does not match the
121 pool’s layout, pmemobj_open() returns NULL and sets errno appropriate‐
122 ly.
123
124 The pmemobj_close() function returns no value.
125
126 The pmemobj_check() function returns 1 if the memory pool is found to
127 be consistent. Any inconsistencies found will cause pmemobj_check() to
128 return 0, in which case the use of the file with libpmemobj(7) will re‐
129 sult in undefined behavior. The debug version of libpmemobj(7) will
130 provide additional details on inconsistencies when PMEMOBJ_LOG_LEVEL is
131 at least 1, as described in the DEBUGGING AND ERROR HANDLING section in
132 libpmemobj(7). pmemobj_check() returns -1 and sets errno if it cannot
133 perform the consistency check due to other errors.
134
136 Not all file systems support posix_fallocate(3). pmemobj_create() will
137 fail if the underlying file system does not support posix_fallocate(3).
138
140 creat(2), msync(2), pmem_is_pmem(3), pmem_persist(3), posix_fallo‐
141 cate(3), libpmem(7), libpmemobj(7) and <https://pmem.io>
142
143
144
145PMDK - 2023-06-05 ()