Skip to content

Commit cbaf6d2

Browse files
committed
Bypass MMap arena grouping as this has caused issues with too many regions being mapped (elastic#135012)
There is a JDK issue where closing sharedArenas from many threads can significantly harm performance. This ref-counting of shared arenas was designed as a way to get around this performance issue. However, we have noticed a significant increase in leaks and issues with mmap regions since this change. https://bugs.openjdk.org/browse/JDK-8335480 should have helped the performance impact of closing shared arenas (though possibly not fully mitigated it). I am proposing we turn off the grouping as it appears (at least to me), not worth it. I am willing to backdown if we thing other fixes should be done. I also suggest this gets backported to 9.1, 8.19, and is merged into 9.2 (cherry picked from commit 2672cd0)
1 parent 30c1f90 commit cbaf6d2

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

distribution/src/config/jvm.options

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
23:-XX:CompileCommand=dontinline,java/lang/invoke/MethodHandle.setAsTypeCache
6363
23:-XX:CompileCommand=dontinline,java/lang/invoke/MethodHandle.asTypeUncached
6464

65+
# Lucene 10: apply MADV_NORMAL advice to enable more aggressive readahead
66+
-Dorg.apache.lucene.store.defaultReadAdvice=normal
67+
6568
## heap dumps
6669

6770
# generate a heap dump when an allocation from the Java heap fails; heap dumps

docs/changelog/135012.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 135012
2+
summary: Bypass MMap arena grouping as this has caused issues with too many regions
3+
being mapped
4+
area: "Engine"
5+
type: bug
6+
issues: []

plugins/store-smb/src/main/java/org/elasticsearch/index/store/smb/SmbMmapFsDirectoryFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ public final class SmbMmapFsDirectoryFactory extends FsDirectoryFactory {
2424

2525
@Override
2626
protected Directory newFSDirectory(Path location, LockFactory lockFactory, IndexSettings indexSettings) throws IOException {
27+
MMapDirectory mMapDirectory = adjustSharedArenaGrouping(new MMapDirectory(location, lockFactory));
2728
return new SmbDirectoryWrapper(
28-
setPreload(
29-
new MMapDirectory(location, lockFactory),
30-
lockFactory,
31-
new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING))
32-
)
29+
setPreload(mMapDirectory, lockFactory, new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING)))
3330
);
3431
}
3532
}

server/src/main/java/org/elasticsearch/index/store/FsDirectoryFactory.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,28 @@
3535
import java.util.HashSet;
3636
import java.util.Set;
3737

38+
import static org.apache.lucene.store.MMapDirectory.SHARED_ARENA_MAX_PERMITS_SYSPROP;
39+
3840
public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
3941

42+
private static final Logger Log = LogManager.getLogger(FsDirectoryFactory.class);
43+
private static final int sharedArenaMaxPermits;
44+
static {
45+
String prop = System.getProperty(SHARED_ARENA_MAX_PERMITS_SYSPROP);
46+
int value = 1;
47+
if (prop != null) {
48+
try {
49+
value = Integer.parseInt(prop); // ensure it's a valid integer
50+
} catch (NumberFormatException e) {
51+
Log.warn(
52+
() -> "unable to parse system property [" + SHARED_ARENA_MAX_PERMITS_SYSPROP + "] with value [" + prop + "]",
53+
e
54+
);
55+
}
56+
}
57+
sharedArenaMaxPermits = value; // default to 1
58+
}
59+
4060
private static final FeatureFlag MADV_RANDOM_FEATURE_FLAG = new FeatureFlag("madv_random");
4161

4262
public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> {
@@ -70,6 +90,7 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
7090
// Use Lucene defaults
7191
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
7292
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
93+
mMapDirectory = adjustSharedArenaGrouping(mMapDirectory);
7394
Directory dir = new HybridDirectory(lockFactory, setPreload(mMapDirectory, lockFactory, preLoadExtensions));
7495
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
7596
dir = disableRandomAdvice(dir);
@@ -79,7 +100,8 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
79100
return primaryDirectory;
80101
}
81102
case MMAPFS:
82-
Directory dir = setPreload(new MMapDirectory(location, lockFactory), lockFactory, preLoadExtensions);
103+
MMapDirectory mMapDirectory = adjustSharedArenaGrouping(new MMapDirectory(location, lockFactory));
104+
Directory dir = setPreload(mMapDirectory, lockFactory, preLoadExtensions);
83105
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
84106
dir = disableRandomAdvice(dir);
85107
}
@@ -105,6 +127,13 @@ public static MMapDirectory setPreload(MMapDirectory mMapDirectory, LockFactory
105127
return mMapDirectory;
106128
}
107129

130+
public MMapDirectory adjustSharedArenaGrouping(MMapDirectory mMapDirectory) {
131+
if (sharedArenaMaxPermits <= 1) {
132+
mMapDirectory.setGroupingFunction(MMapDirectory.NO_GROUPING);
133+
}
134+
return mMapDirectory;
135+
}
136+
108137
/**
109138
* Return a {@link FilterDirectory} around the provided {@link Directory} that forcefully disables {@link IOContext#RANDOM random
110139
* access}.

0 commit comments

Comments
 (0)