LLVM 22.0.0git
llvm::cas::MappedFileRegionArena Class Reference

Allocator for an owned mapped file region that supports thread-safe and process-safe bump pointer allocation. More...

#include "llvm/CAS/MappedFileRegionArena.h"

Classes

struct  Header
 Header for MappedFileRegionArena. More...

Public Types

using RegionT = sys::fs::mapped_file_region

Public Member Functions

Expected< char * > allocate (uint64_t AllocSize)
 Allocate at least AllocSize. Rounds up to getAlign().
Expected< int64_t > allocateOffset (uint64_t AllocSize)
 Allocate, returning the offset from data() instead of a pointer.
chardata () const
uint64_t size () const
uint64_t capacity () const
RegionTgetRegion ()
 ~MappedFileRegionArena ()
 MappedFileRegionArena ()=default
 MappedFileRegionArena (MappedFileRegionArena &&RHS)
MappedFileRegionArenaoperator= (MappedFileRegionArena &&RHS)
 MappedFileRegionArena (const MappedFileRegionArena &)=delete
MappedFileRegionArenaoperator= (const MappedFileRegionArena &)=delete

Static Public Member Functions

static Expected< MappedFileRegionArenacreate (const Twine &Path, uint64_t Capacity, uint64_t HeaderOffset, function_ref< Error(MappedFileRegionArena &)> NewFileConstructor)
 Create a MappedFileRegionArena.
static constexpr Align getAlign ()
 Minimum alignment for allocations, currently hardcoded to 8B.

Detailed Description

Allocator for an owned mapped file region that supports thread-safe and process-safe bump pointer allocation.

This allocator is designed to create a sparse file when supported by the filesystem's ftruncate so that it can be used with a large maximum size. It will also attempt to shrink the underlying file down to its current allocation size when the last concurrent mapping is closed.

Process-safe. Uses file locks when resizing the file during initialization and destruction.

Thread-safe. Requires OS support thread-safe file lock.

Provides 8-byte alignment for all allocations.

Definition at line 38 of file MappedFileRegionArena.h.

Member Typedef Documentation

◆ RegionT

Constructor & Destructor Documentation

◆ ~MappedFileRegionArena()

llvm::cas::MappedFileRegionArena::~MappedFileRegionArena ( )
inline

Definition at line 92 of file MappedFileRegionArena.h.

◆ MappedFileRegionArena() [1/3]

llvm::cas::MappedFileRegionArena::MappedFileRegionArena ( )
default

◆ MappedFileRegionArena() [2/3]

llvm::cas::MappedFileRegionArena::MappedFileRegionArena ( MappedFileRegionArena && RHS)
inline

Definition at line 95 of file MappedFileRegionArena.h.

References MappedFileRegionArena(), and RHS.

◆ MappedFileRegionArena() [3/3]

llvm::cas::MappedFileRegionArena::MappedFileRegionArena ( const MappedFileRegionArena & )
delete

Member Function Documentation

◆ allocate()

Expected< char * > llvm::cas::MappedFileRegionArena::allocate ( uint64_t AllocSize)
inline

Allocate at least AllocSize. Rounds up to getAlign().

Definition at line 77 of file MappedFileRegionArena.h.

References allocateOffset(), data(), LLVM_UNLIKELY, and llvm::Offset.

◆ allocateOffset()

Expected< int64_t > MappedFileRegionArena::allocateOffset ( uint64_t AllocSize)

Allocate, returning the offset from data() instead of a pointer.

Definition at line 336 of file MappedFileRegionArena.cpp.

References llvm::alignTo(), assert(), capacity(), createAllocatorOutOfSpaceError(), getAlign(), LLVM_UNLIKELY, and llvm::cas::ondisk::preallocateFileTail().

Referenced by allocate().

◆ capacity()

uint64_t llvm::cas::MappedFileRegionArena::capacity ( ) const
inline

Definition at line 88 of file MappedFileRegionArena.h.

Referenced by allocateOffset().

◆ create()

Expected< MappedFileRegionArena > MappedFileRegionArena::create ( const Twine & Path,
uint64_t Capacity,
uint64_t HeaderOffset,
function_ref< Error(MappedFileRegionArena &)> NewFileConstructor )
static

Create a MappedFileRegionArena.

Parameters
Paththe path to open the mapped region.
Capacitythe maximum size for the mapped file region.
HeaderOffsetthe offset at which to store the header. This is so that information can be stored before the header, like a file magic.
NewFileConstructoris for constructing new files. It has exclusive access to the file. Must call initializeBumpPtr.

Definition at line 160 of file MappedFileRegionArena.cpp.

References llvm::SmallString< InternalLen >::append(), assert(), llvm::sys::fs::convertFDToNativeFile(), llvm::createFileError(), llvm::createStringError(), llvm::sys::fs::Exclusive, MappedFileRegionArena(), llvm::sys::fs::readNativeFileSlice(), llvm::sys::fs::mapped_file_region::readwrite, llvm::sys::fs::resize_file_sparse(), llvm::sys::fs::Shared, Size, and llvm::utostr().

◆ data()

char * llvm::cas::MappedFileRegionArena::data ( ) const
inline

Definition at line 86 of file MappedFileRegionArena.h.

Referenced by allocate().

◆ getAlign()

constexpr Align llvm::cas::MappedFileRegionArena::getAlign ( )
inlinestaticconstexpr

Minimum alignment for allocations, currently hardcoded to 8B.

Definition at line 69 of file MappedFileRegionArena.h.

References llvm::Align::Of(), and T.

Referenced by allocateOffset().

◆ getRegion()

RegionT & llvm::cas::MappedFileRegionArena::getRegion ( )
inline

Definition at line 90 of file MappedFileRegionArena.h.

◆ operator=() [1/2]

MappedFileRegionArena & llvm::cas::MappedFileRegionArena::operator= ( const MappedFileRegionArena & )
delete

References MappedFileRegionArena(), and RHS.

◆ operator=() [2/2]

MappedFileRegionArena & llvm::cas::MappedFileRegionArena::operator= ( MappedFileRegionArena && RHS)
inline

Definition at line 96 of file MappedFileRegionArena.h.

References MappedFileRegionArena(), and RHS.

◆ size()

uint64_t llvm::cas::MappedFileRegionArena::size ( ) const
inline

Definition at line 87 of file MappedFileRegionArena.h.


The documentation for this class was generated from the following files: