pmem – low level persistent memory support

class nvm.pmem.DrainContext(memory_buffer, unmap=True)

A context manager that will automatically drain the specified memory buffer.

Parameters:memory_buffer – the MemoryBuffer object.
nvm.pmem.FILE_CREATE = 1

Create the named file if it does not exist.

nvm.pmem.FILE_EXCL = 2

Ensure that this call creates the file.

nvm.pmem.FILE_SPARSE = 4

When creating a file, create a sparse (holey) file instead of calling posix_fallocate(2)

nvm.pmem.FILE_TMPFILE = 8

Create a mapping for an unnamed temporary file.

class nvm.pmem.FlushContext(memory_buffer, unmap=True)

A context manager that will automatically flush the specified memory buffer.

Parameters:memory_buffer – the MemoryBuffer object.
class nvm.pmem.MemoryBuffer(buffer_, is_pmem, mapped_len)

A file-like I/O (similar to cStringIO) for persistent mmap’d regions.

read(size=0)

Read data from the buffer.

Parameters:size – size to read, zero equals to entire buffer size.
Returns:data read.
seek(pos)

Moves the cursor position in the buffer.

Parameters:pos – the new cursor position
write(data)

Write data into the buffer.

Parameters:data – data to write into the buffer.
nvm.pmem.check_version(major_required, minor_required)

Checks the libpmem version according to the specified major and minor versions required.

Parameters:
  • major_required – Major version required.
  • minor_required – Minor version required.
Returns:

returns True if the nvm has the required version, or raises a RuntimeError exception in case of failure.

nvm.pmem.drain(memory_buffer=None)

Wait for any PM stores to drain from HW buffers.

Parameters:memory_buffer – the MemoryBuffer object, legacy param, not required anymore.
nvm.pmem.flush(memory_buffer)

Flush processor cache for the given memory region.

Parameters:memory_buffer – the MemoryBuffer object.
nvm.pmem.has_hw_drain()

This function returns true if the machine supports the hardware drain function for persistent memory, such as that provided by the PCOMMIT instruction on Intel processors.

Returns:return True if it has hardware drain, False otherwise.
nvm.pmem.is_pmem(memory_buffer)

Return true if entire range is persistent memory.

Returns:True if the entire range is persistent memory, False otherwise.
nvm.pmem.map_file(file_name, file_size, flags, mode)

Given a path, this function creates a new read/write mapping for the named file. It will map the file using mmap, but it also takes extra steps to make large page mappings more likely.

If creation flags are not supplied, then this function creates a mapping for an existing file. In such case, file_size should be zero. The entire file is mapped to memory; its length is used as the length of the mapping.

Parameters:
  • file_name – The file name to use.
  • file_size – the size to allocate
  • flags – The flags argument can be 0 or bitwise OR of one or more of the following file creation flags: FILE_CREATE, FILE_EXCL, FILE_TMPFILE, FILE_SPARSE.
Returns:

The mapping, an exception will rise in case of error.

nvm.pmem.msync(memory_buffer)

Flush to persistence via msync().

Parameters:memory_buffer – the MemoryBuffer object.
Returns:the msync() return result, in case of msync() error, an exception will rise.
nvm.pmem.persist(memory_buffer)

Make any cached changes to a range of pmem persistent.

Parameters:memory_buffer – the MemoryBuffer object.
nvm.pmem.unmap(memory_buffer)

Unmap the specified region.

Parameters:memory_buffer – the MemoryBuffer object.