Skip to content

Commit 4e8725c

Browse files
benwtrentelasticsearchmachine
andauthored
[8.18] Bypass MMap arena grouping as this has caused issues with too many regions being mapped (elastic#135012) (elastic#135133)
* 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) * [CI] Auto commit changes from spotless * fixing compilation --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 30c1f90 commit 4e8725c

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-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: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.elasticsearch.index.IndexModule;
2828
import org.elasticsearch.index.IndexSettings;
2929
import org.elasticsearch.index.shard.ShardPath;
30+
import org.elasticsearch.logging.LogManager;
31+
import org.elasticsearch.logging.Logger;
3032
import org.elasticsearch.plugins.IndexStorePlugin;
3133

3234
import java.io.IOException;
@@ -35,8 +37,25 @@
3537
import java.util.HashSet;
3638
import java.util.Set;
3739

40+
import static org.apache.lucene.store.MMapDirectory.SHARED_ARENA_MAX_PERMITS_SYSPROP;
41+
3842
public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
3943

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

4261
public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> {
@@ -70,6 +89,7 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
7089
// Use Lucene defaults
7190
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
7291
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
92+
mMapDirectory = adjustSharedArenaGrouping(mMapDirectory);
7393
Directory dir = new HybridDirectory(lockFactory, setPreload(mMapDirectory, lockFactory, preLoadExtensions));
7494
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
7595
dir = disableRandomAdvice(dir);
@@ -79,7 +99,8 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
7999
return primaryDirectory;
80100
}
81101
case MMAPFS:
82-
Directory dir = setPreload(new MMapDirectory(location, lockFactory), lockFactory, preLoadExtensions);
102+
MMapDirectory mMapDirectory = adjustSharedArenaGrouping(new MMapDirectory(location, lockFactory));
103+
Directory dir = setPreload(mMapDirectory, lockFactory, preLoadExtensions);
83104
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
84105
dir = disableRandomAdvice(dir);
85106
}
@@ -105,6 +126,13 @@ public static MMapDirectory setPreload(MMapDirectory mMapDirectory, LockFactory
105126
return mMapDirectory;
106127
}
107128

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

0 commit comments

Comments
 (0)