|
35 | 35 | #include <cstddef> |
36 | 36 | #include <vector> |
37 | 37 |
|
| 38 | +#include <sys/mman.h> |
| 39 | + |
38 | 40 | /* |
39 | 41 | * BWTREE_PELOTON - Specifies whether Peloton-specific features are |
40 | 42 | * Compiled or not |
@@ -2864,6 +2866,21 @@ class BwTree : public BwTreeBase { |
2864 | 2866 | * the mapping table rather than CAS with nullptr |
2865 | 2867 | */ |
2866 | 2868 | void InitMappingTable() { |
| 2869 | + mapping_table = (std::atomic<const BaseNode *> *) \ |
| 2870 | + mmap(NULL, 1024 * 1024 * 1024, |
| 2871 | + PROT_READ | PROT_WRITE, |
| 2872 | + MAP_ANONYMOUS | MAP_PRIVATE, |
| 2873 | + -1, 0); |
| 2874 | + // If allocation fails, we throw an error because this is uncoverable |
| 2875 | + // The upper level functions should either catch this exception |
| 2876 | + // and then use another index instead, or simply kill the system |
| 2877 | + if(mapping_table == (void *)-1) { |
| 2878 | + LOG_ERROR("Failed to initialize mapping table"); |
| 2879 | + throw IndexException("mmap() failed to initialize mapping table for Bw-Tree"); |
| 2880 | + } |
| 2881 | + |
| 2882 | + LOG_TRACE("Mapping table allocated via mmap()"); |
| 2883 | + |
2867 | 2884 | LOG_TRACE("Initializing mapping table.... size = %lu", MAPPING_TABLE_SIZE); |
2868 | 2885 | LOG_TRACE("Fast initialization: Do not set to zero"); |
2869 | 2886 |
|
@@ -7379,7 +7396,7 @@ class BwTree : public BwTreeBase { |
7379 | 7396 | NodeID first_leaf_id; |
7380 | 7397 |
|
7381 | 7398 | std::atomic<NodeID> next_unused_node_id; |
7382 | | - std::array<std::atomic<const BaseNode *>, MAPPING_TABLE_SIZE> mapping_table; |
| 7399 | + std::atomic<const BaseNode *> *mapping_table; |
7383 | 7400 |
|
7384 | 7401 | // This list holds free NodeID which was removed by remove delta |
7385 | 7402 | // We recycle NodeID in epoch manager |
@@ -7568,6 +7585,8 @@ class BwTree : public BwTreeBase { |
7568 | 7585 | // would always fail, until we have cleaned all epoch nodes |
7569 | 7586 | current_epoch_p = nullptr; |
7570 | 7587 |
|
| 7588 | + LOG_DEBUG("Clearing the epoch in ~EpochManager()..."); |
| 7589 | + |
7571 | 7590 | // If all threads has exited then all thread counts are |
7572 | 7591 | // 0, and therefore this should proceed way to the end |
7573 | 7592 | ClearEpoch(); |
@@ -7605,6 +7624,20 @@ class BwTree : public BwTreeBase { |
7605 | 7624 | epoch_leave.load()); |
7606 | 7625 | #endif |
7607 | 7626 |
|
| 7627 | + // NOTE: Only unmap memory here because we need to access the mapping |
| 7628 | + // table in the above routine. If it was unmapped in ~BwTree() then this |
| 7629 | + // function will invoke illegal memory access |
| 7630 | + int munmap_ret = munmap(tree_p->mapping_table, 1024 * 1024 * 1024); |
| 7631 | + |
| 7632 | + // Although failure of munmap is not fatal, we still print out |
| 7633 | + // an error log entry |
| 7634 | + // Otherwise just trace log |
| 7635 | + if(munmap_ret != 0) { |
| 7636 | + LOG_ERROR("munmap() returns with %d", munmap_ret); |
| 7637 | + } else { |
| 7638 | + LOG_TRACE("Mapping table is unmapped for Bw-Tree"); |
| 7639 | + } |
| 7640 | + |
7608 | 7641 | return; |
7609 | 7642 | } |
7610 | 7643 |
|
|
0 commit comments