-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
LargePageListIT.java
78 lines (67 loc) · 3.02 KB
/
LargePageListIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.io.pagecache.impl.muninn;
import org.junit.Test;
import java.util.stream.IntStream;
import org.neo4j.io.ByteUnit;
import org.neo4j.io.mem.MemoryAllocator;
import org.neo4j.memory.GlobalMemoryTracker;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class LargePageListIT
{
@Test
public void veryLargePageListsMustBeFullyAccessible() throws Exception
{
// We need roughly 2 GiBs of memory for the meta-data here, which is why this is an IT and not a Test.
// We add one extra page worth of data to the size here, to avoid ending up on a "convenient" boundary.
int pageSize = (int) ByteUnit.kibiBytes( 8 );
long pageCacheSize = ByteUnit.gibiBytes( 513 ) + pageSize;
int pages = Math.toIntExact( pageCacheSize / pageSize );
MemoryAllocator mman = MemoryAllocator.createAllocator( "2 GiB", GlobalMemoryTracker.INSTANCE );
SwapperSet swappers = new SwapperSet();
long victimPage = VictimPageReference.getVictimPage( pageSize, GlobalMemoryTracker.INSTANCE );
PageList pageList = new PageList( pages, pageSize, mman, swappers, victimPage, Long.BYTES );
// Verify we end up with the correct number of pages.
assertThat( pageList.getPageCount(), is( pages ) );
// Spot-check the accessibility in the bulk of the pages.
IntStream.range( 0, pages / 32 ).parallel().forEach( id ->
{
verifyPageMetaDataIsAccessible( pageList, id * 32 );
} );
// Thoroughly check the accessibility around the tail end of the page list.
IntStream.range( pages - 2000, pages ).parallel().forEach( id ->
{
verifyPageMetaDataIsAccessible( pageList, id );
} );
}
private void verifyPageMetaDataIsAccessible( PageList pageList, int id )
{
long ref = pageList.deref( id );
pageList.incrementUsage( ref );
pageList.incrementUsage( ref );
assertFalse( pageList.decrementUsage( ref ) );
assertTrue( pageList.decrementUsage( ref ) );
assertEquals( id, pageList.toId( ref ) );
}
}