LLFIO v2.00
Loading...
Searching...
No Matches
map_handle.hpp File Reference

Provides `map_handle`. More...

#include "file_handle.hpp"

Classes

class  llfio_v2_xxx::section_handle
 A handle to a source of mapped memory. More...
 
struct  llfio_v2_xxx::construct< section_handle >
 Constructor for section_handle More...
 
class  llfio_v2_xxx::map_handle
 A handle to a memory mapped region of memory, either backed by the system page file or by a section. More...
 
struct  llfio_v2_xxx::map_handle::cache_statistics
 Statistics about the map handle cache. More...
 
struct  llfio_v2_xxx::construct< map_handle >
 Constructor for map_handle More...
 
struct  in_place_attach_detach::traits::disable_attached_for< llfio_v2_xxx ::map_handle >
 

Namespaces

namespace  llfio_v2_xxx
 The LLFIO namespace.
 

Functions

std::ostream & llfio_v2_xxx::operator<< (std::ostream &s, const section_handle::flag &v)
 
byte_io_handle::const_buffer_type llfio_v2_xxx::nvram_barrier (byte_io_handle::const_buffer_type req, bool evict=false) noexcept
 
template<class T >
constexpr span< T > llfio_v2_xxx::in_place_attach (map_handle &mh) noexcept
 Declare map_handle as a suitable source for P1631 attached<T>.
 
result< byte_io_handle::registered_buffer_type > llfio_v2_xxx::detail::map_handle_allocate_registered_buffer (size_t &bytes) noexcept
 
void llfio_v2_xxx::swap (section_handle &self, section_handle &o) noexcept
 Swap with another instance.
 
result< section_handlellfio_v2_xxx::section (file_handle &backing, section_handle::extent_type maximum_size, section_handle::flag _flag) noexcept
 Create a memory section backed by a file.
 
result< section_handlellfio_v2_xxx::section (file_handle &backing, section_handle::extent_type bytes=0) noexcept
 Create a memory section backed by a file.
 
result< section_handlellfio_v2_xxx::section (section_handle::extent_type bytes, const path_handle &dirh=path_discovery::storage_backed_temporary_files_directory(), section_handle::flag _flag=section_handle::flag::read|section_handle::flag::write) noexcept
 Create a memory section backed by an anonymous, managed file.
 
result< section_handle::extent_type > llfio_v2_xxx::length (const section_handle &self) noexcept
 Return the current maximum permitted extent of the memory section.
 
result< section_handle::extent_type > llfio_v2_xxx::truncate (section_handle &self, section_handle::extent_type newsize=0) noexcept
 
void llfio_v2_xxx::swap (map_handle &self, map_handle &o) noexcept
 Swap with another instance.
 
result< void > llfio_v2_xxx::close (map_handle &self) noexcept
 Unmap the mapped view.
 
result< map_handlellfio_v2_xxx::map (map_handle::size_type bytes, bool zeroed=false, section_handle::flag _flag=section_handle::flag::readwrite) noexcept
 
result< map_handlellfio_v2_xxx::map (section_handle &section, map_handle::size_type bytes=0, map_handle::extent_type offset=0, section_handle::flag _flag=section_handle::flag::readwrite) noexcept
 
map_handle::size_type llfio_v2_xxx::length (const map_handle &self) noexcept
 The size of the memory map. This is the accessible size, NOT the reservation size.
 
result< map_handle::size_type > llfio_v2_xxx::truncate (map_handle &self, map_handle::size_type newsize, bool permit_relocation=false) noexcept
 
map_handle::io_result< map_handle::buffers_type > llfio_v2_xxx::read (map_handle &self, map_handle::io_request< map_handle::buffers_type > reqs, deadline d=deadline()) noexcept
 Read data from the mapped view.
 
map_handle::io_result< map_handle::const_buffers_type > llfio_v2_xxx::write (map_handle &self, map_handle::io_request< map_handle::const_buffers_type > reqs, deadline d=deadline()) noexcept
 Write data to the mapped view.
 
result< size_t > llfio_v2_xxx::detail::pagesize_from_flags (section_handle::flag _flag) noexcept
 

Detailed Description

Provides `map_handle`.

Function Documentation

◆ map_handle_allocate_registered_buffer()

result< byte_io_handle::registered_buffer_type > llfio_v2_xxx::detail::map_handle_allocate_registered_buffer ( size_t &  bytes)
inlinenoexcept
954 {
955 LLFIO_EXCEPTION_TRY
956 {
957 auto make_shared = [](map_handle h) -> byte_io_handle::registered_buffer_type
958 {
959 struct registered_buffer_type_indirect : byte_io_multiplexer::_registered_buffer_type
960 {
961 map_handle h;
962 registered_buffer_type_indirect(map_handle _h)
963 : byte_io_multiplexer::_registered_buffer_type(_h.as_span())
964 , h(std::move(_h))
965 {
966 }
967 };
968 return byte_io_handle::registered_buffer_type(std::make_shared<registered_buffer_type_indirect>(std::move(h)));
969 };
970 const auto &page_sizes = utils::page_sizes(true);
971 size_t idx = 0;
972 for(size_t n = 0; n < page_sizes.size(); ++n)
973 {
974 if(page_sizes[n] > bytes)
975 {
976 break;
977 }
978 if((bytes & (page_sizes[n] - 1)) == 0)
979 {
980 idx = n;
981 }
982 }
983 section_handle::flag flags = section_handle::flag::readwrite;
984 if(idx > 0)
985 {
986 switch(idx)
987 {
988 case 1:
989 flags |= section_handle::flag::page_sizes_1;
990 break;
991 case 2:
992 flags |= section_handle::flag::page_sizes_2;
993 break;
994 case 3:
995 flags |= section_handle::flag::page_sizes_3;
996 break;
997 default:
998 break;
999 }
1000 auto r = map_handle::map(bytes, false, flags);
1001 if(r)
1002 {
1003 bytes = (bytes + page_sizes[idx] - 1) & ~(page_sizes[idx] - 1);
1004 return make_shared(std::move(r).value());
1005 }
1006 }
1007 auto r = map_handle::map(bytes, false);
1008 if(r)
1009 {
1010 bytes = (bytes + page_sizes[0] - 1) & ~(page_sizes[0] - 1);
1011 return make_shared(std::move(r).value());
1012 }
1013 return errc::not_enough_memory;
1014 }
1015 LLFIO_EXCEPTION_CATCH_ALL
1016 {
1017 return error_from_exception();
1018 }
1019 }
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.

◆ pagesize_from_flags()

result< size_t > llfio_v2_xxx::detail::pagesize_from_flags ( section_handle::flag  _flag)
inlinenoexcept
1201 {
1202 LLFIO_EXCEPTION_TRY
1203 {
1204 const auto &pagesizes = utils::page_sizes();
1205 if((_flag & section_handle::flag::page_sizes_3) == section_handle::flag::page_sizes_3)
1206 {
1207 if(pagesizes.size() < 4)
1208 {
1209 return errc::invalid_argument;
1210 }
1211 return pagesizes[3];
1212 }
1213 else if((_flag & section_handle::flag::page_sizes_2) == section_handle::flag::page_sizes_2)
1214 {
1215 if(pagesizes.size() < 3)
1216 {
1217 return errc::invalid_argument;
1218 }
1219 return pagesizes[2];
1220 }
1221 else if((_flag & section_handle::flag::page_sizes_1) == section_handle::flag::page_sizes_1)
1222 {
1223 if(pagesizes.size() < 2)
1224 {
1225 return errc::invalid_argument;
1226 }
1227 return pagesizes[1];
1228 }
1229 return pagesizes[0];
1230 }
1231 LLFIO_EXCEPTION_CATCH_ALL
1232 {
1233 return error_from_exception();
1234 }
1235 }