12#include "vecmem/memory/memory_resource.hpp"
13#include "vecmem/memory/unique_ptr.hpp"
69 enum class page_state { OCCUPIED, VACANT, SPLIT, NON_EXTANT };
82 superpage(std::size_t, memory_resource &, std::size_t);
198 std::optional<page_ref>
parent()
const;
204 std::optional<page_ref>
sibling()
const;
253 std::reference_wrapper<superpage> m_superpage;
261 void *
allocate(std::size_t size, std::size_t align);
263 void deallocate(
void *p, std::size_t size, std::size_t align);
287 memory_resource &m_upstream;
288 std::vector<superpage> m_superpages;
Namespace for types that should not be used directly by clients.
Definition array.hpp:23
std::unique_ptr< T, details::unique_alloc_deleter< T > > unique_alloc_ptr
A unique pointer type for trivial types.
Definition unique_ptr.hpp:72
page_ref(page_ref &&)=default
Default implementation of move constructor.
void change_state_split_to_vacant()
Change page state from split to vacant.
Definition binary_page_memory_resource_impl.cpp:339
void change_state_occupied_to_vacant()
Change page state from occupied to vacant.
Definition binary_page_memory_resource_impl.cpp:315
page_ref(const page_ref &)=default
Default implementation of copy constructor.
bool operator==(const page_ref &) const
Equality operator of pages.
Definition binary_page_memory_resource_impl.cpp:368
page_ref left_child() const
Obtain a reference to this page's left child.
Definition binary_page_memory_resource_impl.cpp:379
void change_state_vacant_to_occupied()
Change page state from vacant to occupied.
Definition binary_page_memory_resource_impl.cpp:309
page_state get_state() const
Return the state of the page referenced.
Definition binary_page_memory_resource_impl.cpp:355
std::size_t get_index()
Get the page index in the superpage.
Definition binary_page_memory_resource_impl.cpp:344
void change_state_non_extant_to_vacant()
Change page state from non-extant to vacant.
Definition binary_page_memory_resource_impl.cpp:321
page_ref()=delete
Delete the meaningless default constructor.
std::optional< page_ref > sibling() const
Obtain a reference to this page's sibling, if such a node exists.
Definition binary_page_memory_resource_impl.cpp:400
page_ref right_child() const
Obtain a reference to this page's left child.
Definition binary_page_memory_resource_impl.cpp:384
page_ref & operator=(page_ref &&)=default
Default implementation of move assignment.
void split()
Split the current page.
Definition binary_page_memory_resource_impl.cpp:429
void change_state_vacant_to_split()
Change page state from vacant to split.
Definition binary_page_memory_resource_impl.cpp:333
std::optional< page_ref > parent() const
Obtain a reference to this page's parent, if such a node exists.
Definition binary_page_memory_resource_impl.cpp:389
page_ref & operator=(const page_ref &)=default
Default implementation of copy assignment.
std::size_t get_size() const
Return the size (log_2) of the page referenced.
Definition binary_page_memory_resource_impl.cpp:300
void change_state_vacant_to_non_extant()
Change page state from vacant to non-extant.
Definition binary_page_memory_resource_impl.cpp:327
bool operator!=(const page_ref &) const
Inquality operator of pages.
Definition binary_page_memory_resource_impl.cpp:373
void * get_addr() const
Return the beginning of the address space represented by this page.
Definition binary_page_memory_resource_impl.cpp:359
void unsplit()
Unsplit the current page, potentially unsplitting its children, too.
Definition binary_page_memory_resource_impl.cpp:410
Container for superpages in our buddy allocator.
Definition binary_page_memory_resource_impl.hpp:77
superpage(std::size_t, memory_resource &, std::size_t)
Construct a superpage with a given size, upstream resource, and minimum alignment of its memory.
Definition binary_page_memory_resource_impl.cpp:271
std::size_t total_pages() const
Return the total number of pages in the superpage.
Definition binary_page_memory_resource_impl.cpp:296
std::unique_ptr< page_state[]> m_pages
Array of pages, remembering that this always resides in host-accessible memory.
Definition binary_page_memory_resource_impl.hpp:109
unique_alloc_ptr< std::byte[]> m_memory
The actual allocation, which is just a byte pointer.
Definition binary_page_memory_resource_impl.hpp:115
std::size_t m_size
Size (log_2) of the entire allocation represented by this superpage.
Definition binary_page_memory_resource_impl.hpp:93
std::size_t m_min_page_size
The size of the smallest page in this superpage.
Definition binary_page_memory_resource_impl.hpp:98
std::size_t m_num_pages
Total number of pages in this superpage.
Definition binary_page_memory_resource_impl.hpp:103
void allocate_upstream(std::size_t, std::size_t)
Perform an upstream allocation.
Definition binary_page_memory_resource_impl.cpp:257
static constexpr std::size_t delta_superpage_size
The maximum difference (log_2) between the size of the superpage and its smallest page.
Definition binary_page_memory_resource_impl.hpp:48
static constexpr std::size_t min_superpage_size
The minimum size (log_2) of superpages in our buddy allocator.
Definition binary_page_memory_resource_impl.hpp:38
void deallocate(void *p, std::size_t size, std::size_t align)
De-allocate a previously allocated memory blob.
Definition binary_page_memory_resource_impl.cpp:106
binary_page_memory_resource_impl(memory_resource &upstream)
Constructor, on top of another memory resource.
Definition binary_page_memory_resource_impl.cpp:26
static constexpr std::size_t min_page_size
The minimum size (log_2) of pages in our buddy allocator.
Definition binary_page_memory_resource_impl.hpp:56
page_state
The different possible states a page can be in.
Definition binary_page_memory_resource_impl.hpp:69
void * allocate(std::size_t size, std::size_t align)
Allocate a blob of memory.
Definition binary_page_memory_resource_impl.cpp:30
std::optional< page_ref > find_free_page(std::size_t, std::size_t)
Find the smallest free page that could fit the requested size.
Definition binary_page_memory_resource_impl.cpp:188