16 #include "ArenaPool.hpp"
17 #include <ndbd_exit_codes.h>
22 computeBlockSize(Uint32 blockSz, Uint32 wpp)
24 Uint32 minspill = wpp % blockSz;
25 Uint32 minspill_bs = blockSz;
27 for (Uint32
i = 16;
i<blockSz/4;
i += 16)
29 Uint32 spillsz = wpp % (blockSz -
i);
34 else if (spillsz < minspill)
37 minspill_bs = blockSz -
i;
40 ndbout_c(
"blockSz: %u, wpp: %u -> %u (%u)",
41 blockSz, wpp, minspill_bs, minspill);
46 ArenaAllocator::init(Uint32 sz, Uint32 type_id,
const Pool_context& pc)
48 Uint32 blocksz = ArenaBlock::computeBlockSizeInWords(sz);
49 Uint32 wpp = m_pool.WORDS_PER_PAGE;
51 Uint32 bs = computeBlockSize(blocksz, wpp);
56 const char * off_base = (
char*)&tmp;
57 const char * off_next = (
char*)&tmp.nextPool;
58 const char * off_magic = (
char*)&tmp.m_magic;
60 ri.m_offset_next_pool = Uint32(off_next - off_base);
61 ri.m_offset_magic = Uint32(off_magic - off_base);
63 ri.m_type_id = type_id;
65 m_block_size = bs - ArenaBlock::HeaderSize;
72 if (m_pool.seize(tmp))
74 ah.m_first_block = tmp.i;
75 ah.m_current_block = tmp.i;
76 ah.m_block_size = m_block_size;
77 ah.m_current_block_ptr =
static_cast<ArenaBlock*
>(tmp.p);
78 ah.m_current_block_ptr->m_next_block = RNIL;
88 curr.i = ah.m_first_block;
89 while (curr.i != RNIL)
91 curr.p = m_pool.getPtr(curr.i);
92 Uint32 next =
static_cast<ArenaBlock*
>(curr.p)->m_next_block;
105 #if SIZEOF_CHARP == 4
106 m_record_info.m_size = ((ri.m_size + 3) >> 2);
108 m_record_info.m_size = ((ri.m_size + 7) >> 3) << 1;
110 m_record_info.m_offset_magic = ((ri.m_offset_magic + 3) >> 2);
111 m_record_info.m_offset_next_pool = ((ri.m_offset_next_pool + 3) >> 2);
118 Uint32 pos = ah.m_first_free;
119 Uint32 bs = ah.m_block_size;
120 Uint32 ptrI = ah.m_current_block;
123 Uint32 sz = m_record_info.m_size;
124 Uint32 off = m_record_info.m_offset_magic;
127 ndbout_c(
"pos: %u sz: %u (sum: %u) bs: %u",
128 pos, sz, (pos + sz), bs);
136 ((ptrI >> POOL_RECORD_BITS) << POOL_RECORD_BITS) +
137 (ptrI & POOL_RECORD_MASK) + pos + ArenaBlock::HeaderSize;
138 ptr.p = block->m_data + pos;
139 block->m_data[pos+off] = ~(Uint32)m_record_info.m_type_id;
141 ah.m_first_free = pos + sz;
147 if (m_allocator->m_pool.seize(tmp))
150 ah.m_current_block = tmp.i;
151 ah.m_current_block_ptr->m_next_block = tmp.i;
152 ah.m_current_block_ptr =
static_cast<ArenaBlock*
>(tmp.p);
153 ah.m_current_block_ptr->m_next_block = RNIL;
154 bool ret = seize(ah, ptr);
164 ArenaPool::handle_invalid_release(
Ptr<void> ptr)
170 Uint32 * record_ptr_p = (Uint32*)ptr.p;
172 Uint32 magic = * (record_ptr_p + m_record_info.m_offset_magic);
174 "Invalid memory release: ptr (%x %p) magic: (%.8x %.8x)",
175 ptr.i, ptr.p, magic, m_record_info.m_type_id);
177 m_allocator->m_pool.m_ctx.
handleAbort(NDBD_EXIT_PRGERR, buf);