77
88#include " table.hpp"
99#include " page.hpp"
10+ #include " page.hpp"
1011#include " ../Util/assert.hpp"
1112#include < sys/mman.h>
1213#include < malloc/malloc.h>
@@ -21,40 +22,34 @@ uint8_t _shared_table_bytes[sizeof(table) / sizeof(uint8_t)] = {};
2122
2223malloc_zone_t *_Nullable _malloc_zone;
2324
24- void table::print () const OG_NOEXCEPT {
25- os_unfair_lock_lock (&_lock);
26- fprintf (stderr, " data::table %p:\n %.2fKB allocated, %.2fKB used, %.2fKB reusable.\n " ,
27- this ,
28- double (_region_capacity - page_size) / 1024.0 ,
29- double (this ->used_pages_num ()) / 1024.0 ,
30- double (_reusable_pages_num) / 1024.0 );
31- os_unfair_lock_unlock (&_lock);
25+ table &table::ensure_shared () {
26+ static dispatch_once_t once;
27+ dispatch_once_f (&once, nullptr , [](void *_Nullable context){
28+ new (_shared_table_bytes) table ();
29+ });
30+ return shared ();
3231}
3332
34- // uint64_t table::raw_page_seed(ptr<page> page) {
35- // page.assert_valid();
36- //
37- // lock();
38- //
39- // uint32_t page_index = (page / page_size) - 1;
40- // uint32_t map_index = page_index / pages_per_map;
41- //
42- // uint64_t result = 0;
43- // if (map_index < _page_metadata_maps.size() && _page_metadata_maps[map_index].test(page_index % page_size)) {
44- // auto raw_zone_info = page->zone->info().to_raw_value();
45- // result = raw_zone_info | (1 < 8);
46- // }
47- //
48- // unlock();
49- //
50- // return result;
51- // }
52-
53- // dealloc_page_locked(OG::data::ptr<OG::data::page>
54-
55- // alloc_page(OG::data::zone&, unsigned int)
33+ table &table::shared () { return *reinterpret_cast <data::table *>(&_shared_table_bytes); }
5634
57- // make_pages_reusable(unsigned int, bool)
35+ // FIXME
36+ table::table () {
37+ constexpr vm_size_t initial_size = 32 * pages_per_map * page_size;
38+ _region_capacity = initial_size;
39+ void *region = mmap (nullptr , initial_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 , 0 );
40+ _region_base = reinterpret_cast <vm_address_t >(region);
41+ OGGraphVMRegionBaseAddress = region;
42+ if (region == MAP_FAILED) {
43+ OG::precondition_failure (" memory allocation failure (%u bytes, %u)" , _region_capacity, errno);
44+ }
45+ _data_base = reinterpret_cast <vm_address_t >(region) - page_size;
46+ _data_capacity = initial_size + page_size;
47+ if (_malloc_zone == nullptr ) {
48+ malloc_zone_t *zone = malloc_create_zone (0 , 0 );
49+ _malloc_zone = zone;
50+ malloc_set_zone_name (zone, " OpenGraph graph data" );
51+ }
52+ }
5853
5954void table::grow_region () OG_NOEXCEPT {
6055 uint32_t new_size = 4 * _region_capacity;
@@ -91,34 +86,47 @@ void table::grow_region() OG_NOEXCEPT {
9186 _data_capacity = new_size + page_size;
9287}
9388
94- // FIXME
95- table::table () {
96- constexpr vm_size_t initial_size = 32 * pages_per_map * page_size;
97- _region_capacity = initial_size;
98- void *region = mmap (nullptr , initial_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 , 0 );
99- _region_base = reinterpret_cast <vm_address_t >(region);
100- OGGraphVMRegionBaseAddress = region;
101- if (region == MAP_FAILED) {
102- OG::precondition_failure (" memory allocation failure (%u bytes, %u)" , _region_capacity, errno);
103- }
104- _data_base = reinterpret_cast <vm_address_t >(region) - page_size;
105- _data_capacity = initial_size + page_size;
106- if (_malloc_zone == nullptr ) {
107- malloc_zone_t *zone = malloc_create_zone (0 , 0 );
108- _malloc_zone = zone;
109- malloc_set_zone_name (zone, " OpenGraph graph data" );
110- }
89+ void table::make_pages_reusable (uint32_t page_index, bool flag) OG_NOEXCEPT {
90+ precondition_failure (" TODO" );
11191}
11292
113- table &table::ensure_shared () {
114- static dispatch_once_t once;
115- dispatch_once_f (&once, nullptr , [](void *_Nullable context){
116- new (_shared_table_bytes) table ();
117- });
118- return shared ();
93+ ptr<page> table::alloc_page (zone *zone, uint32_t size) OG_NOEXCEPT {
94+ precondition_failure (" TODO" );
11995}
12096
121- table &table::shared () { return *reinterpret_cast <data::table *>(&_shared_table_bytes); }
97+ void table::dealloc_page_locked (ptr<page> page) OG_NOEXCEPT {
98+ precondition_failure (" TODO" );
99+ }
100+
101+ uint64_t table::raw_page_seed (ptr<page> page) OG_NOEXCEPT {
102+ precondition_failure (" TODO" );
103+ // page.assert_valid();
104+ //
105+ // lock();
106+ //
107+ // uint32_t page_index = (page / page_size) - 1;
108+ // uint32_t map_index = page_index / pages_per_map;
109+ //
110+ // uint64_t result = 0;
111+ // if (map_index < _page_metadata_maps.size() && _page_metadata_maps[map_index].test(page_index % page_size)) {
112+ // auto raw_zone_info = page->zone->info().to_raw_value();
113+ // result = raw_zone_info | (1 < 8);
114+ // }
115+ //
116+ // unlock();
117+ //
118+ // return result;
119+ }
120+
121+ void table::print () const OG_NOEXCEPT {
122+ os_unfair_lock_lock (&_lock);
123+ fprintf (stderr, " data::table %p:\n %.2fKB allocated, %.2fKB used, %.2fKB reusable.\n " ,
124+ this ,
125+ double (_region_capacity - page_size) / 1024.0 ,
126+ double (this ->used_pages_num ()) / 1024.0 ,
127+ double (_reusable_pages_num) / 1024.0 );
128+ os_unfair_lock_unlock (&_lock);
129+ }
122130
123131} /* data */
124132} /* OG */
0 commit comments