mirror of
https://github.com/corda/corda.git
synced 2025-02-02 09:18:13 +00:00
maintain memory ceiling for tenured fixed objects and use it to trigger a major GC when appropriate
This commit is contained in:
parent
324744d525
commit
e3be0d197e
74
src/heap.cpp
74
src/heap.cpp
@ -15,6 +15,7 @@ const unsigned FixieTenureThreshold = TenureThreshold + 2;
|
|||||||
const unsigned Top = ~static_cast<unsigned>(0);
|
const unsigned Top = ~static_cast<unsigned>(0);
|
||||||
|
|
||||||
const unsigned InitialGen2CapacityInBytes = 4 * 1024 * 1024;
|
const unsigned InitialGen2CapacityInBytes = 4 * 1024 * 1024;
|
||||||
|
const unsigned InitialTenuredFixieCeilingInBytes = 4 * 1024 * 1024;
|
||||||
|
|
||||||
const bool Verbose = false;
|
const bool Verbose = false;
|
||||||
const bool Verbose2 = false;
|
const bool Verbose2 = false;
|
||||||
@ -474,6 +475,12 @@ class Context {
|
|||||||
tenureFootprint(0),
|
tenureFootprint(0),
|
||||||
gen1padding(0),
|
gen1padding(0),
|
||||||
gen2padding(0),
|
gen2padding(0),
|
||||||
|
|
||||||
|
fixieTenureFootprint(0),
|
||||||
|
untenuredFixieFootprint(0),
|
||||||
|
tenuredFixieFootprint(0),
|
||||||
|
tenuredFixieCeiling(InitialTenuredFixieCeilingInBytes),
|
||||||
|
|
||||||
mode(Heap::MinorCollection),
|
mode(Heap::MinorCollection),
|
||||||
|
|
||||||
fixies(0),
|
fixies(0),
|
||||||
@ -523,6 +530,11 @@ class Context {
|
|||||||
unsigned gen1padding;
|
unsigned gen1padding;
|
||||||
unsigned gen2padding;
|
unsigned gen2padding;
|
||||||
|
|
||||||
|
unsigned fixieTenureFootprint;
|
||||||
|
unsigned untenuredFixieFootprint;
|
||||||
|
unsigned tenuredFixieFootprint;
|
||||||
|
unsigned tenuredFixieCeiling;
|
||||||
|
|
||||||
Heap::CollectionType mode;
|
Heap::CollectionType mode;
|
||||||
|
|
||||||
Fixie* fixies;
|
Fixie* fixies;
|
||||||
@ -685,33 +697,52 @@ sweepFixies(Context* c)
|
|||||||
if (c->mode == Heap::MajorCollection) {
|
if (c->mode == Heap::MajorCollection) {
|
||||||
free(c, &(c->tenuredFixies));
|
free(c, &(c->tenuredFixies));
|
||||||
free(c, &(c->dirtyFixies));
|
free(c, &(c->dirtyFixies));
|
||||||
|
|
||||||
|
c->tenuredFixieFootprint = 0;
|
||||||
}
|
}
|
||||||
free(c, &(c->fixies));
|
free(c, &(c->fixies));
|
||||||
|
|
||||||
|
c->untenuredFixieFootprint = 0;
|
||||||
|
|
||||||
for (Fixie** p = &(c->visitedFixies); *p;) {
|
for (Fixie** p = &(c->visitedFixies); *p;) {
|
||||||
Fixie* f = *p;
|
Fixie* f = *p;
|
||||||
*p = f->next;
|
*p = f->next;
|
||||||
|
|
||||||
|
unsigned size = c->client->sizeInWords(f->body());
|
||||||
|
|
||||||
++ f->age;
|
++ f->age;
|
||||||
|
if (f->age > FixieTenureThreshold) {
|
||||||
if (f->age >= FixieTenureThreshold) {
|
|
||||||
f->age = FixieTenureThreshold;
|
f->age = FixieTenureThreshold;
|
||||||
|
} else if (static_cast<unsigned>(f->age + 1) == FixieTenureThreshold) {
|
||||||
|
c->fixieTenureFootprint += f->totalSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f->age == FixieTenureThreshold) {
|
||||||
if (DebugFixies) {
|
if (DebugFixies) {
|
||||||
fprintf(stderr, "tenure fixie %p (dirty: %d)\n", f, f->dirty);
|
fprintf(stderr, "tenure fixie %p (dirty: %d)\n", f, f->dirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c->tenuredFixieFootprint += size;
|
||||||
|
|
||||||
if (f->dirty) {
|
if (f->dirty) {
|
||||||
f->move(&(c->dirtyFixies));
|
f->move(&(c->dirtyFixies));
|
||||||
} else {
|
} else {
|
||||||
f->move(&(c->tenuredFixies));
|
f->move(&(c->tenuredFixies));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
c->untenuredFixieFootprint += size;
|
||||||
|
|
||||||
f->move(&(c->fixies));
|
f->move(&(c->fixies));
|
||||||
}
|
}
|
||||||
|
|
||||||
f->marked = false;
|
f->marked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c->tenuredFixieCeiling > c->tenuredFixieFootprint * 4) {
|
||||||
|
c->tenuredFixieCeiling = max
|
||||||
|
(c->tenuredFixieCeiling / 2,
|
||||||
|
InitialTenuredFixieCeilingInBytes / BytesPerWord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void*
|
inline void*
|
||||||
@ -1332,6 +1363,7 @@ collect2(Context* c)
|
|||||||
{
|
{
|
||||||
c->gen2Base = Top;
|
c->gen2Base = Top;
|
||||||
c->tenureFootprint = 0;
|
c->tenureFootprint = 0;
|
||||||
|
c->fixieTenureFootprint = 0;
|
||||||
c->gen1padding = 0;
|
c->gen1padding = 0;
|
||||||
c->gen2padding = 0;
|
c->gen2padding = 0;
|
||||||
|
|
||||||
@ -1364,11 +1396,22 @@ collect2(Context* c)
|
|||||||
void
|
void
|
||||||
collect(Context* c, unsigned footprint)
|
collect(Context* c, unsigned footprint)
|
||||||
{
|
{
|
||||||
// todo: tweak the calculation below to take memory footprint of
|
|
||||||
// tenured fixies into account.
|
|
||||||
if (oversizedGen2(c)
|
if (oversizedGen2(c)
|
||||||
or c->tenureFootprint + c->gen2padding > c->gen2.remaining())
|
or c->tenureFootprint + c->gen2padding > c->gen2.remaining()
|
||||||
|
or c->fixieTenureFootprint + c->tenuredFixieFootprint
|
||||||
|
> c->tenuredFixieCeiling)
|
||||||
{
|
{
|
||||||
|
if (Verbose) {
|
||||||
|
if (oversizedGen2(c)) {
|
||||||
|
fprintf(stderr, "oversized gen2 causes ");
|
||||||
|
} else if (c->tenureFootprint + c->gen2padding > c->gen2.remaining())
|
||||||
|
{
|
||||||
|
fprintf(stderr, "undersized gen2 causes ");
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "fixie ceiling causes ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c->mode = Heap::MajorCollection;
|
c->mode = Heap::MajorCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1384,7 +1427,12 @@ collect(Context* c, unsigned footprint)
|
|||||||
}
|
}
|
||||||
|
|
||||||
initNextGen1(c, footprint);
|
initNextGen1(c, footprint);
|
||||||
|
|
||||||
if (c->mode == Heap::MajorCollection) {
|
if (c->mode == Heap::MajorCollection) {
|
||||||
|
c->tenuredFixieCeiling = max
|
||||||
|
((c->fixieTenureFootprint + c->tenuredFixieFootprint) * 2,
|
||||||
|
InitialTenuredFixieCeilingInBytes / BytesPerWord);
|
||||||
|
|
||||||
initNextGen2(c);
|
initNextGen2(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1416,12 +1464,22 @@ collect(Context* c, unsigned footprint)
|
|||||||
c->totalTime - c->totalCollectionTime);
|
c->totalTime - c->totalCollectionTime);
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" - gen1: %8d/%8d bytes; "
|
" - gen1: %8d/%8d bytes\n",
|
||||||
"gen2: %8d/%8d bytes\n",
|
|
||||||
c->gen1.position() * BytesPerWord,
|
c->gen1.position() * BytesPerWord,
|
||||||
c->gen1.capacity() * BytesPerWord,
|
c->gen1.capacity() * BytesPerWord);
|
||||||
|
|
||||||
|
fprintf(stderr,
|
||||||
|
" - gen2: %8d/%8d bytes\n",
|
||||||
c->gen2.position() * BytesPerWord,
|
c->gen2.position() * BytesPerWord,
|
||||||
c->gen2.capacity() * BytesPerWord);
|
c->gen2.capacity() * BytesPerWord);
|
||||||
|
|
||||||
|
fprintf(stderr,
|
||||||
|
" - untenured fixies: %8d bytes\n",
|
||||||
|
c->untenuredFixieFootprint * BytesPerWord);
|
||||||
|
|
||||||
|
fprintf(stderr,
|
||||||
|
" - tenured fixies: %8d bytes\n",
|
||||||
|
c->tenuredFixieFootprint * BytesPerWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user