Improve the utilization of subpage pools

.. by avoiding the overly frequent removal of a subpage from a pool

This change makes sure that the unused subpage is not removed when there's no subpage left in the pool.  If the last subpage is removed from the pool, it is very likely that the allocator will create a new subpage very soon again, so it's better not remove it.
This commit is contained in:
Trustin Lee 2013-06-21 11:15:24 +09:00
parent a6795d7780
commit dbab41cc50

View File

@ -108,6 +108,7 @@ final class PoolSubpage<T> {
* {@code false} if this subpage is not used by its chunk and thus it's OK to be released.
*/
boolean free(int bitmapIdx) {
if (elemSize == 0) {
return true;
}
@ -123,9 +124,16 @@ final class PoolSubpage<T> {
return true;
}
if (numAvail < maxNumElems) {
if (numAvail != maxNumElems) {
return true;
} else {
// Subpage not in use (numAvail == maxNumElems)
if (prev == next) {
// Do not remove if this subpage is the only one left in the pool.
return true;
}
// Remove this subpage from the pool if there are other subpages left in the pool.
doNotDestroy = false;
removeFromPool();
return false;