LLFIO v2.00
Loading...
Searching...
No Matches
Utilities

Miscellaneous utility functions and classes which do not belong to any of the other modules. More...

Classes

class  llfio_v2_xxx::utils::page_allocator< T >
 An STL allocator which allocates large TLB page memory. More...

Functions

size_t llfio_v2_xxx::utils::page_size () noexcept
 Returns the smallest page size of this architecture which is useful for calculating direct i/o multiples.
const std::vector< size_t > & llfio_v2_xxx::utils::page_sizes (bool only_actually_available=true)
 Returns the page sizes of this architecture which is useful for calculating direct i/o multiples.
size_t llfio_v2_xxx::utils::file_buffer_default_size ()
 Returns a reasonable default size for page_allocator, typically the closest page size from page_sizes() to 1Mb.
void llfio_v2_xxx::utils::random_fill (char *buffer, size_t bytes) noexcept
 Fills the buffer supplied with cryptographically strong randomness. Uses the OS kernel API.
std::string llfio_v2_xxx::utils::random_string (size_t randomlen)
 Returns a cryptographically random string capable of being used as a filename. Essentially random_fill() + to_hex_string().

Detailed Description

Miscellaneous utility functions and classes which do not belong to any of the other modules.

The members of this group are declared in namespace utils, but they are grouped here so that the reference documentation lists them together rather than burying them in the namespace listing.

Function Documentation

◆ file_buffer_default_size()

size_t llfio_v2_xxx::utils::file_buffer_default_size ( )
inline

Returns a reasonable default size for page_allocator, typically the closest page size from page_sizes() to 1Mb.

Returns
A value of a TLB large page size close to 1Mb.
Complexity
Whatever the system API takes (one would hope constant time).
Errors returnable
Throws any error from the operating system or std::bad_alloc.
139 {
140 static size_t size;
141 if(size == 0u)
142 {
143 const std::vector<size_t> &sizes = page_sizes(true);
144 for(auto &i : sizes)
145 {
146 if(i >= 1024 * 1024)
147 {
148 size = i;
149 break;
150 }
151 }
152 if(size == 0u)
153 {
154 size = 1024 * 1024;
155 }
156 }
157 return size;
158 }
const std::vector< size_t > & page_sizes(bool only_actually_available=true)
Returns the page sizes of this architecture which is useful for calculating direct i/o multiples.

◆ page_size()

size_t llfio_v2_xxx::utils::page_size ( )
externnoexcept

Returns the smallest page size of this architecture which is useful for calculating direct i/o multiples.

Returns
The page size of this architecture.
Complexity
Whatever the system API takes (one would hope constant time).

◆ page_sizes()

const std::vector< size_t > & llfio_v2_xxx::utils::page_sizes ( bool only_actually_available = true)
extern

Returns the page sizes of this architecture which is useful for calculating direct i/o multiples.

Parameters
only_actually_availableOnly return page sizes actually available to the user running this process
Returns
The page sizes of this architecture.
Complexity
First call performs multiple memory allocations, mutex locks and system calls. Subsequent calls lock mutexes.
Errors returnable
Throws any error from the operating system or std::bad_alloc.

◆ random_fill()

void llfio_v2_xxx::utils::random_fill ( char * buffer,
size_t bytes )
externnoexcept

Fills the buffer supplied with cryptographically strong randomness. Uses the OS kernel API.

Parameters
bufferA buffer to fill
bytesHow many bytes to fill
Complexity
Whatever the system API takes.
Errors returnable
Any error from the operating system.

◆ random_string()

std::string llfio_v2_xxx::utils::random_string ( size_t randomlen)
inline

Returns a cryptographically random string capable of being used as a filename. Essentially random_fill() + to_hex_string().

Parameters
randomlenThe number of bytes of randomness to use for the string.
Returns
A string representing the randomness at a 2x ratio, so if 32 bytes were requested, this string would be 64 bytes long.
Complexity
Whatever the system API takes.
Errors returnable
Any error from the operating system.
179 {
180 size_t outlen = randomlen * 2;
181 std::string ret(outlen, 0);
182 random_fill(const_cast<char *>(ret.data()), randomlen);
183 QUICKCPPLIB_NAMESPACE::algorithm::string::to_hex_string(const_cast<char *>(ret.data()), outlen, ret.data(), randomlen);
184 return ret;
185 }
void random_fill(char *buffer, size_t bytes) noexcept
Fills the buffer supplied with cryptographically strong randomness. Uses the OS kernel API.