mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-04-27 08:43:40 -07:00
Better names for poolgen functions.
Accounting for segment splitting and merging. Accounting for allocation and freeing in segsmss. Copied from Perforce Change: 185894 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
a0e943d74e
commit
32416cc272
9 changed files with 74 additions and 42 deletions
|
|
@ -98,12 +98,14 @@ extern Res PoolGenInit(PoolGen pgen, GenDesc gen, Pool pool);
|
|||
extern void PoolGenFinish(PoolGen pgen);
|
||||
extern Res PoolGenAlloc(Seg *segReturn, PoolGen pgen, SegClass class,
|
||||
Size size, Bool withReservoirPermit, ArgList args);
|
||||
extern void PoolGenBufferFill(PoolGen pgen, Size size, Bool deferred);
|
||||
extern void PoolGenFree(PoolGen pgen, Seg seg);
|
||||
extern void PoolGenFill(PoolGen pgen, Size size, Bool deferred);
|
||||
extern void PoolGenEmpty(PoolGen pgen, Size unused, Bool deferred);
|
||||
extern void PoolGenAge(PoolGen pgen, Size aged, Bool deferred);
|
||||
extern void PoolGenReclaim(PoolGen pgen, Size reclaimed, Bool deferred);
|
||||
extern void PoolGenBufferEmpty(PoolGen pgen, Size unused, Bool deferred);
|
||||
extern void PoolGenUndefer(PoolGen pgen, Size oldSize, Size newSize);
|
||||
extern void PoolGenFree(PoolGen pgen, Seg seg);
|
||||
extern void PoolGenSegSplit(PoolGen pgen);
|
||||
extern void PoolGenSegMerge(PoolGen pgen);
|
||||
|
||||
#endif /* chain_h */
|
||||
|
||||
|
|
|
|||
|
|
@ -465,12 +465,12 @@ Bool PoolGenCheck(PoolGen pgen)
|
|||
}
|
||||
|
||||
|
||||
/* PoolGenBufferFill -- accounting for buffer fill
|
||||
/* PoolGenFill -- accounting for allocation
|
||||
*
|
||||
* The buffer was free, is now new (or newDeferred).
|
||||
* The memory was free, is now new (or newDeferred).
|
||||
*/
|
||||
|
||||
void PoolGenBufferFill(PoolGen pgen, Size size, Bool ramping)
|
||||
void PoolGenFill(PoolGen pgen, Size size, Bool ramping)
|
||||
{
|
||||
AVERT(PoolGen, pgen);
|
||||
AVERT(Bool, ramping);
|
||||
|
|
@ -484,6 +484,27 @@ void PoolGenBufferFill(PoolGen pgen, Size size, Bool ramping)
|
|||
}
|
||||
|
||||
|
||||
/* PoolGenEmpty -- accounting for emptying a buffer
|
||||
*
|
||||
* The unused part of the buffer was new (or newDeferred) and is now free.
|
||||
*/
|
||||
|
||||
void PoolGenEmpty(PoolGen pgen, Size unused, Bool ramping)
|
||||
{
|
||||
AVERT(PoolGen, pgen);
|
||||
AVERT(Bool, ramping);
|
||||
|
||||
if (ramping) {
|
||||
AVER(pgen->newDeferredSize >= unused);
|
||||
pgen->newDeferredSize -= unused;
|
||||
} else {
|
||||
AVER(pgen->newSize >= unused);
|
||||
pgen->newSize -= unused;
|
||||
}
|
||||
pgen->freeSize += unused;
|
||||
}
|
||||
|
||||
|
||||
/* PoolGenAge -- accounting for condemning a segment
|
||||
*
|
||||
* The memory was new (or newDeferred), is now old (or oldDeferred)
|
||||
|
|
@ -526,27 +547,6 @@ void PoolGenReclaim(PoolGen pgen, Size reclaimed, Bool ramping)
|
|||
}
|
||||
|
||||
|
||||
/* PoolGenBufferEmpty -- accounting for emptying a buffer
|
||||
*
|
||||
* The unused part of the buffer was new (or newDeferred) and is now free.
|
||||
*/
|
||||
|
||||
void PoolGenBufferEmpty(PoolGen pgen, Size unused, Bool ramping)
|
||||
{
|
||||
AVERT(PoolGen, pgen);
|
||||
AVERT(Bool, ramping);
|
||||
|
||||
if (ramping) {
|
||||
AVER(pgen->newDeferredSize >= unused);
|
||||
pgen->newDeferredSize -= unused;
|
||||
} else {
|
||||
AVER(pgen->newSize >= unused);
|
||||
pgen->newSize -= unused;
|
||||
}
|
||||
pgen->freeSize += unused;
|
||||
}
|
||||
|
||||
|
||||
/* PoolGenUndefer -- accounting for end of ramp mode
|
||||
*
|
||||
* The memory was oldDeferred or newDeferred, is now old or new.
|
||||
|
|
@ -564,6 +564,25 @@ void PoolGenUndefer(PoolGen pgen, Size oldSize, Size newSize)
|
|||
}
|
||||
|
||||
|
||||
/* PoolGenSegSplit -- accounting for splitting a segment */
|
||||
|
||||
void PoolGenSegSplit(PoolGen pgen)
|
||||
{
|
||||
AVERT(PoolGen, pgen);
|
||||
++ pgen->segs;
|
||||
}
|
||||
|
||||
|
||||
/* PoolGenSegMerge -- accounting for merging a segment */
|
||||
|
||||
void PoolGenSegMerge(PoolGen pgen)
|
||||
{
|
||||
AVERT(PoolGen, pgen);
|
||||
AVER(pgen->segs > 0);
|
||||
-- pgen->segs;
|
||||
}
|
||||
|
||||
|
||||
/* PoolGenFree -- free a segment and update accounting
|
||||
*
|
||||
* The segment is assumed to finish free.
|
||||
|
|
|
|||
|
|
@ -708,6 +708,7 @@ extern Addr (SegLimit)(Seg seg);
|
|||
#define SegOfPoolRing(node) (RING_ELT(Seg, poolRing, (node)))
|
||||
#define SegOfGreyRing(node) (&(RING_ELT(GCSeg, greyRing, (node)) \
|
||||
->segStruct))
|
||||
|
||||
#define SegSummary(seg) (((GCSeg)(seg))->summary)
|
||||
|
||||
#define SegSetPM(seg, mode) ((void)((seg)->pm = BS_BITFIELD(Access, (mode))))
|
||||
|
|
|
|||
|
|
@ -1062,7 +1062,7 @@ static Res AMCBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
}
|
||||
}
|
||||
|
||||
PoolGenBufferFill(pgen, SegSize(seg), Seg2amcSeg(seg)->deferred);
|
||||
PoolGenFill(pgen, SegSize(seg), Seg2amcSeg(seg)->deferred);
|
||||
*baseReturn = base;
|
||||
*limitReturn = limit;
|
||||
return ResOK;
|
||||
|
|
@ -1107,7 +1107,7 @@ static void AMCBufferEmpty(Pool pool, Buffer buffer,
|
|||
ShieldCover(arena, seg);
|
||||
}
|
||||
|
||||
PoolGenBufferEmpty(&amcSegGen(seg)->pgen, 0, Seg2amcSeg(seg)->deferred);
|
||||
PoolGenEmpty(&amcSegGen(seg)->pgen, 0, Seg2amcSeg(seg)->deferred);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -399,6 +399,7 @@ static Res AMSSegMerge(Seg seg, Seg segHi,
|
|||
amssegHi->sig = SigInvalid;
|
||||
|
||||
AVERT(AMSSeg, amsseg);
|
||||
PoolGenSegMerge(&ams->pgen);
|
||||
return ResOK;
|
||||
|
||||
failSuper:
|
||||
|
|
@ -504,6 +505,7 @@ static Res AMSSegSplit(Seg seg, Seg segHi,
|
|||
amssegHi->sig = AMSSegSig;
|
||||
AVERT(AMSSeg, amsseg);
|
||||
AVERT(AMSSeg, amssegHi);
|
||||
PoolGenSegSplit(&ams->pgen);
|
||||
return ResOK;
|
||||
|
||||
failSuper:
|
||||
|
|
@ -997,7 +999,7 @@ found:
|
|||
DebugPoolFreeCheck(pool, baseAddr, limitAddr);
|
||||
allocatedSize = AddrOffset(baseAddr, limitAddr);
|
||||
|
||||
PoolGenBufferFill(&ams->pgen, allocatedSize, FALSE);
|
||||
PoolGenFill(&ams->pgen, allocatedSize, FALSE);
|
||||
*baseReturn = baseAddr;
|
||||
*limitReturn = limitAddr;
|
||||
return ResOK;
|
||||
|
|
@ -1079,7 +1081,7 @@ static void AMSBufferEmpty(Pool pool, Buffer buffer, Addr init, Addr limit)
|
|||
AVER(amsseg->newGrains >= limitIndex - initIndex);
|
||||
amsseg->newGrains -= limitIndex - initIndex;
|
||||
size = AddrOffset(init, limit);
|
||||
PoolGenBufferEmpty(&ams->pgen, size, FALSE);
|
||||
PoolGenEmpty(&ams->pgen, size, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -685,7 +685,7 @@ found:
|
|||
AVER(awlseg->freeGrains >= j - i);
|
||||
awlseg->freeGrains -= j - i;
|
||||
awlseg->newGrains += j - i;
|
||||
PoolGenBufferFill(&awl->pgen, AddrOffset(base, limit), FALSE);
|
||||
PoolGenFill(&awl->pgen, AddrOffset(base, limit), FALSE);
|
||||
}
|
||||
*baseReturn = base;
|
||||
*limitReturn = limit;
|
||||
|
|
@ -724,7 +724,7 @@ static void AWLBufferEmpty(Pool pool, Buffer buffer, Addr init, Addr limit)
|
|||
AVER(awlseg->newGrains >= j - i);
|
||||
awlseg->newGrains -= j - i;
|
||||
awlseg->freeGrains += j - i;
|
||||
PoolGenBufferEmpty(&awl->pgen, AddrOffset(init, limit), FALSE);
|
||||
PoolGenEmpty(&awl->pgen, AddrOffset(init, limit), FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -610,7 +610,7 @@ found:
|
|||
loseg->newGrains += limitIndex - baseIndex;
|
||||
}
|
||||
|
||||
PoolGenBufferFill(&lo->pgen, AddrOffset(base, limit), FALSE);
|
||||
PoolGenFill(&lo->pgen, AddrOffset(base, limit), FALSE);
|
||||
|
||||
*baseReturn = base;
|
||||
*limitReturn = limit;
|
||||
|
|
@ -665,7 +665,7 @@ static void LOBufferEmpty(Pool pool, Buffer buffer, Addr init, Addr limit)
|
|||
AVER(loseg->newGrains >= limitIndex - initIndex);
|
||||
loseg->newGrains -= limitIndex - initIndex;
|
||||
loseg->freeGrains += limitIndex - initIndex;
|
||||
PoolGenBufferEmpty(&lo->pgen, AddrOffset(init, limit), FALSE);
|
||||
PoolGenEmpty(&lo->pgen, AddrOffset(init, limit), FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -636,6 +636,10 @@ Res SegSplit(Seg *segLoReturn, Seg *segHiReturn, Seg seg, Addr at,
|
|||
AVER(at < limit);
|
||||
AVERT(Bool, withReservoirPermit);
|
||||
|
||||
/* Can only split a buffered segment if the entire buffer is below
|
||||
* the split point. */
|
||||
AVER(SegBuffer(seg) == NULL || BufferLimit(SegBuffer(seg)) <= at);
|
||||
|
||||
ShieldFlush(arena); /* see <design/seg/#split-merge.shield> */
|
||||
|
||||
/* Allocate the new segment object from the control pool */
|
||||
|
|
|
|||
|
|
@ -434,7 +434,7 @@ static Bool AMSSegRegionIsFree(Seg seg, Addr base, Addr limit)
|
|||
* Used as a means of overriding the behaviour of AMSBufferFill.
|
||||
* The code is similar to AMSBufferEmpty.
|
||||
*/
|
||||
static void AMSUnallocateRange(Seg seg, Addr base, Addr limit)
|
||||
static void AMSUnallocateRange(AMS ams, Seg seg, Addr base, Addr limit)
|
||||
{
|
||||
AMSSeg amsseg;
|
||||
Index baseIndex, limitIndex;
|
||||
|
|
@ -465,6 +465,7 @@ static void AMSUnallocateRange(Seg seg, Addr base, Addr limit)
|
|||
amsseg->freeGrains += limitIndex - baseIndex;
|
||||
AVER(amsseg->newGrains >= limitIndex - baseIndex);
|
||||
amsseg->newGrains -= limitIndex - baseIndex;
|
||||
PoolGenEmpty(&ams->pgen, AddrOffset(base, limit), FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -473,7 +474,7 @@ static void AMSUnallocateRange(Seg seg, Addr base, Addr limit)
|
|||
* Used as a means of overriding the behaviour of AMSBufferFill.
|
||||
* The code is similar to AMSUnallocateRange.
|
||||
*/
|
||||
static void AMSAllocateRange(Seg seg, Addr base, Addr limit)
|
||||
static void AMSAllocateRange(AMS ams, Seg seg, Addr base, Addr limit)
|
||||
{
|
||||
AMSSeg amsseg;
|
||||
Index baseIndex, limitIndex;
|
||||
|
|
@ -504,6 +505,7 @@ static void AMSAllocateRange(Seg seg, Addr base, Addr limit)
|
|||
AVER(amsseg->freeGrains >= limitIndex - baseIndex);
|
||||
amsseg->freeGrains -= limitIndex - baseIndex;
|
||||
amsseg->newGrains += limitIndex - baseIndex;
|
||||
PoolGenFill(&ams->pgen, AddrOffset(base, limit), FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -528,6 +530,7 @@ static Res AMSTBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
PoolClass super;
|
||||
Addr base, limit;
|
||||
Arena arena;
|
||||
AMS ams;
|
||||
AMST amst;
|
||||
Bool b;
|
||||
Seg seg;
|
||||
|
|
@ -539,6 +542,7 @@ static Res AMSTBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
AVER(limitReturn != NULL);
|
||||
/* other parameters are checked by next method */
|
||||
arena = PoolArena(pool);
|
||||
ams = Pool2AMS(pool);
|
||||
amst = Pool2AMST(pool);
|
||||
|
||||
/* call next method */
|
||||
|
|
@ -560,14 +564,14 @@ static Res AMSTBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
Seg mergedSeg;
|
||||
Res mres;
|
||||
|
||||
AMSUnallocateRange(seg, base, limit);
|
||||
AMSUnallocateRange(ams, seg, base, limit);
|
||||
mres = SegMerge(&mergedSeg, segLo, seg, withReservoirPermit);
|
||||
if (ResOK == mres) { /* successful merge */
|
||||
AMSAllocateRange(mergedSeg, base, limit);
|
||||
AMSAllocateRange(ams, mergedSeg, base, limit);
|
||||
/* leave range as-is */
|
||||
} else { /* failed to merge */
|
||||
AVER(amst->failSegs); /* deliberate fails only */
|
||||
AMSAllocateRange(seg, base, limit);
|
||||
AMSAllocateRange(ams, seg, base, limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -578,13 +582,13 @@ static Res AMSTBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
Addr mid = AddrAdd(base, half);
|
||||
Seg segLo, segHi;
|
||||
Res sres;
|
||||
AMSUnallocateRange(seg, mid, limit);
|
||||
AMSUnallocateRange(ams, seg, mid, limit);
|
||||
sres = SegSplit(&segLo, &segHi, seg, mid, withReservoirPermit);
|
||||
if (ResOK == sres) { /* successful split */
|
||||
limit = mid; /* range is lower segment */
|
||||
} else { /* failed to split */
|
||||
AVER(amst->failSegs); /* deliberate fails only */
|
||||
AMSAllocateRange(seg, mid, limit);
|
||||
AMSAllocateRange(ams, seg, mid, limit);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue