19 #include <ndb_global.h>
20 #include "SuperPool.hpp"
21 #include "ndbd_malloc_impl.hpp"
22 #include "NdbdSuperPool.hpp"
24 #define PSI (1 << (BMW_2LOG + 2))
32 SuperPool::PtrI m_firstPageI;
42 m_currPage = m_numPages = 0;
47 Uint32 pageSize, Uint32 pageBits) :
50 m_currArea(0), m_firstArea(0)
52 m_memRoot = m_mm.get_memroot();
55 m_add = (1 << m_shift) - 1;
58 NdbdSuperPool::~NdbdSuperPool()
65 for(Uint32
i = 0;
i<cnt;
i++)
69 m_mm.release(ap->m_memory, ap->m_numPages >> m_shift);
73 m_mm.release((
void*)first, 1);
78 NdbdSuperPool::init_1()
80 Uint32 pageCount = (1 << m_pageBits);
83 Uint32 bytes = pageCount *
sizeof(PageEnt);
84 m_pageEnt =
static_cast<PageEnt*
>(malloc(bytes));
87 for (Uint32
i = 0;
i < pageCount;
i++)
88 new (&m_pageEnt[
i]) PageEnt();
90 if (m_pageType == 0) {
92 Uint32 bytes = pageCount;
93 m_pageType =
static_cast<Uint8*
>(malloc(bytes));
96 memset(m_pageType, 0, bytes);
108 for(Uint32
i = 0;
i<cnt;
i++, ap++)
113 (p1 + cnt - 1)->m_nextArea = 0;
117 NdbdSuperPool::init_2()
119 m_memRoot = m_mm.get_memroot();
126 initAllocAreaPage(p1);
133 NdbdSuperPool::getNewPage()
136 Uint32 curr = ap->m_currPage;
137 Uint32 cnt = ap->m_numPages;
141 if (! (ap = allocMem()))
146 curr = ap->m_currPage;
147 cnt = ap->m_numPages;
151 PtrI pageI = ap->m_firstPageI;
152 Uint32 recBits = m_recBits;
153 Int32 ip = ((Int32)pageI >> recBits) + curr;
154 pageI = ip << recBits;
155 ap->m_currPage = curr + 1;
160 NdbdSuperPool::allocAreaMemory(
AllocArea* ap, Uint32 tryPages)
162 Uint32 cnt = (tryPages + m_add) >> m_shift;
163 void* p1 = m_mm.alloc(&cnt, 1);
169 Uint32 pageI = getPageI(p1);
170 ap->m_firstPageI = pageI;
173 ap->m_numPages = cnt << m_shift;
178 NdbdSuperPool::allocArea()
189 initAllocAreaPage(p1);
191 m_currArea->m_nextArea = p1;
192 return m_currArea = p1;
196 m_currArea = m_currArea->m_nextArea;
202 NdbdSuperPool::allocMem()
205 if (m_totPages >= m_maxPages)
210 Uint32 needPages = (m_totPages == 0 ? m_initPages : m_incrPages);
221 if (!(numPages = allocAreaMemory(ap, needPages)))
228 m_totPages += numPages;