00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Fennel_RandomAllocationSegmentBase_Included
00025 #define Fennel_RandomAllocationSegmentBase_Included
00026
00027 #include "fennel/synch/SynchObj.h"
00028 #include "fennel/segment/DelegatingSegment.h"
00029
00030 FENNEL_BEGIN_NAMESPACE
00031
00032 struct SegmentAllocationNode;
00033
00037 struct FENNEL_SEGMENT_EXPORT PageEntry
00038 {
00044 PageOwnerId ownerId;
00045
00050 PageId successorId;
00051 };
00052
00068 class FENNEL_SEGMENT_EXPORT RandomAllocationSegmentBase
00069 : public DelegatingSegment
00070 {
00074 BlockNum nPagesOccupiedHighWater;
00075
00079 BlockNum nPagesAllocated;
00080
00085 BlockNum netDeallocations;
00086
00091 StrictMutex pageCounterMutex;
00092
00098 void incrementPageCounters();
00099
00103 void incrementPagesOccupiedCounter();
00104
00109 void decrementPageCounters();
00110
00115 void countAllocatedPages();
00116
00127 void tallySegAllocNodePages(
00128 PageId segAllocPageId,
00129 SharedSegment allocNodeSegment,
00130 PageId &nextSegAllocPageId);
00131
00137 void deallocatePageId(PageId pageId);
00138
00139 protected:
00140 friend class SegmentFactory;
00141
00147 BlockNum nPagesPerExtent;
00148
00153 BlockNum nPagesPerSegAlloc;
00154
00159 ExtentNum nExtentsPerSegAlloc;
00160
00161 explicit RandomAllocationSegmentBase(
00162 SharedSegment delegateSegment);
00163
00171 inline PageId getSegAllocPageId(uint iSegPage) const;
00172
00181 virtual PageId getSegAllocPageIdForWrite(PageId origSegAllocPageId) = 0;
00182
00189 virtual void undoSegAllocPageWrite(PageId segAllocPageId) = 0;
00190
00198 inline PageId getExtentAllocPageId(ExtentNum extentNum) const;
00199
00208 virtual PageId getExtAllocPageIdForWrite(ExtentNum extentNum) = 0;
00209
00220 inline BlockNum makePageNum(
00221 ExtentNum extentNum,BlockNum iPageInExtent) const;
00222
00237 void splitPageId(
00238 PageId pageId,uint &iSegAlloc,
00239 ExtentNum &extentNum,BlockNum &iPageInExtent) const;
00240
00249 virtual bool isPageIdValid(PageId pageId);
00250
00254 bool testPageId(PageId pageId,bool testAllocation,bool thisSegment);
00255
00268 virtual PageOwnerId getPageOwnerId(PageId pageId, bool thisSegment) = 0;
00269
00283 template <class PageEntryT>
00284 PageOwnerId getPageOwnerIdTemplate(PageId pageId, bool thisSegment);
00285
00295 virtual void freePageEntry(
00296 ExtentNum extentNum,
00297 BlockNum iPageInExtent) = 0;
00298
00312 template <
00313 class ExtentAllocationNodeT,
00314 class ExtentAllocLockT,
00315 class PageEntryT>
00316 void freePageEntryTemplate(ExtentNum extentNum, BlockNum iPageInExtent);
00317
00323 virtual void markPageEntryUnused(PageEntry &pageEntry);
00324
00328 inline PageId getFirstSegAllocPageId() const;
00329
00334 uint inferSegAllocCount();
00335
00340 void format();
00341
00353 virtual void formatPageExtents(
00354 SegmentAllocationNode &segAllocNode,
00355 ExtentNum &extentNum) = 0;
00356
00369 template <
00370 class ExtentAllocationNodeT,
00371 class ExtentAllocLockT,
00372 class PageEntryT>
00373 void formatPageExtentsTemplate(
00374 SegmentAllocationNode &segAllocNode,
00375 ExtentNum &extentNum);
00376
00385 template <
00386 class ExtentAllocationNodeT,
00387 class ExtentAllocLockT,
00388 class PageEntryT>
00389 void formatExtentTemplate(ExtentAllocationNodeT &extentNode);
00390
00404 PageId allocatePageIdFromSegment(
00405 PageOwnerId ownerId,
00406 SharedSegment allocNodeSegment);
00407
00419 virtual PageId allocateFromExtent(
00420 ExtentNum extentNum,
00421 PageOwnerId ownerId) = 0;
00422
00440 template <
00441 class ExtentAllocationNodeT,
00442 class ExtentAllocLockT,
00443 class PageEntryT>
00444 PageId allocateFromExtentTemplate(
00445 ExtentNum extentNum,
00446 PageOwnerId ownerId,
00447 SharedSegment allocNodeSegment);
00448
00460 virtual PageId allocateFromNewExtent(
00461 ExtentNum extentNum,
00462 PageOwnerId ownerId) = 0;
00463
00481 template <
00482 class ExtentAllocationNodeT,
00483 class ExtentAllocLockT,
00484 class PageEntryT>
00485 PageId allocateFromNewExtentTemplate(
00486 ExtentNum extentNum,
00487 PageOwnerId ownerId,
00488 SharedSegment allocNodeSegment);
00489
00506 template <class ExtentAllocationNodeT, class PageEntryT>
00507 PageId allocateFromLockedExtentTemplate(
00508 ExtentAllocationNodeT &extentNode,
00509 ExtentNum extentNum,
00510 PageOwnerId ownerId);
00511
00525 template <class ExtentAllocationNodeT, class ExtentAllocLockT>
00526 void setPageSuccessorTemplate(
00527 PageId pageId,
00528 PageId successorId,
00529 SharedSegment allocNodeSegment);
00530
00542 virtual PageId getSegAllocPageIdForRead(
00543 PageId origSegAllocPageId,
00544 SharedSegment &allocNodeSegment) = 0;
00545
00557 virtual PageId getExtAllocPageIdForRead(
00558 ExtentNum extentNum,
00559 SharedSegment &allocNodeSegment) = 0;
00560
00575 virtual void getPageEntryCopy(
00576 PageId pageId,
00577 PageEntry &pageEntryCopy,
00578 bool isAllocated,
00579 bool thisSegment) = 0;
00580
00596 template <
00597 class ExtentAllocationNodeT,
00598 class ExtentAllocLockT,
00599 class PageEntryT>
00600 void getPageEntryCopyTemplate(
00601 PageId pageId,
00602 PageEntryT &pageEntryCopy,
00603 bool isAllocated,
00604 bool thisSegment);
00605
00606 public:
00607 virtual ~RandomAllocationSegmentBase();
00608
00609
00610 virtual BlockId translatePageId(PageId);
00611 virtual bool isPageIdAllocated(PageId pageId);
00612 virtual AllocationOrder getAllocationOrder() const;
00613 virtual BlockNum getAllocatedSizeInPages();
00614 virtual BlockNum getNumPagesOccupiedHighWater();
00615 virtual void deallocatePageRange(PageId startPageId, PageId endPageId);
00616 virtual void initForUse();
00617 };
00618
00619 FENNEL_END_NAMESPACE
00620
00621 #endif
00622
00623