Skip to content

Commit

Permalink
Don't forget the free page counter when switching to free page list
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed May 26, 2017
1 parent 0574925 commit 02eb8e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Expand Up @@ -19,6 +19,8 @@
*/ */
package org.neo4j.io.pagecache.impl.muninn; package org.neo4j.io.pagecache.impl.muninn;


import java.util.concurrent.atomic.AtomicInteger;

/** /**
* A free page in the MuninnPageCache.freelist. * A free page in the MuninnPageCache.freelist.
* *
Expand All @@ -28,16 +30,27 @@ final class FreePage
{ {
final long pageRef; final long pageRef;
int count; int count;
FreePage next; Object next;


FreePage( long pageRef ) FreePage( long pageRef )
{ {
this.pageRef = pageRef; this.pageRef = pageRef;
} }


void setNext( FreePage next ) void setNext( Object next )
{ {
this.next = next; this.next = next;
this.count = next == null ? 1 : 1 + next.count; if ( next == null )
{
count = 1;
}
else if ( next.getClass() == AtomicInteger.class )
{
count = 1 + ((AtomicInteger) next).get();
}
else
{
this.count = 1 + ((FreePage) next).count;
}
} }
} }
Expand Up @@ -225,7 +225,7 @@ public MuninnPageCache(


this.pages = new PageList( maxPages, cachePageSize, memoryManager, new SwapperSet(), victimPage ); this.pages = new PageList( maxPages, cachePageSize, memoryManager, new SwapperSet(), victimPage );


UnsafeUtil.putObjectVolatile( this, freelistOffset, new AtomicInteger() ); setFreelistHead( new AtomicInteger() );
} }


private static void verifyHacks() private static void verifyHacks()
Expand Down Expand Up @@ -760,10 +760,9 @@ private boolean compareAndSetFreelistHead( Object expected, Object update )
this, freelistOffset, expected, update ); this, freelistOffset, expected, update );
} }


private Object getAndSetFreelistHead( Object newFreelistHead ) private void setFreelistHead( Object newFreelistHead )
{ {
return UnsafeUtil.getAndSetObject( UnsafeUtil.putObjectVolatile( this, freelistOffset, newFreelistHead );
this, freelistOffset, newFreelistHead );
} }


/** /**
Expand All @@ -789,7 +788,7 @@ void continuouslySweepPages()


// The last thing we do, is signalling the shutdown of the cache via // The last thing we do, is signalling the shutdown of the cache via
// the freelist. This signal is looked out for in grabFreePage. // the freelist. This signal is looked out for in grabFreePage.
getAndSetFreelistHead( shutdownSignal ); setFreelistHead( shutdownSignal );
} }


private int parkUntilEvictionRequired( int keepFree ) private int parkUntilEvictionRequired( int keepFree )
Expand Down Expand Up @@ -886,7 +885,11 @@ private void addFreePageToFreelist( long pageRef )
do do
{ {
current = getFreelistHead(); current = getFreelistHead();
freePage.setNext( current instanceof FreePage ? (FreePage) current : null ); if ( current instanceof AtomicInteger && ((AtomicInteger) current).get() >= pages.getPageCount() )
{
current = null;
}
freePage.setNext( current );
} }
while ( !compareAndSetFreelistHead( current, freePage ) ); while ( !compareAndSetFreelistHead( current, freePage ) );
} }
Expand Down

0 comments on commit 02eb8e7

Please sign in to comment.