Skip to content

Commit 108fc9a

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 55305b3 commit 108fc9a

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

distribution/src/config/jvm.options

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
# Lucene 10: apply MADV_NORMAL advice to enable more aggressive readahead
6666
-Dorg.apache.lucene.store.defaultReadAdvice=normal
6767

68+
# Lucene provides a mechanism for shared mmapped arenas to be referenced between multiple threads
69+
# this is to get around potential performance issues when closing shared arenas on many threads
70+
# default to 1 to disable this feature
71+
-Dorg.apache.lucene.store.MMapDirectory.sharedArenaMaxPermits=1
72+
6873
## heap dumps
6974

7075
# 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +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-
new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING))
31-
)
29+
setPreload(mMapDirectory, new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING)))
3230
);
3331
}
3432
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,28 @@
3737
import java.util.Set;
3838
import java.util.function.BiPredicate;
3939

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

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(
54+
() -> "unable to parse system property [" + SHARED_ARENA_MAX_PERMITS_SYSPROP + "] with value [" + prop + "]",
55+
e
56+
);
57+
}
58+
}
59+
sharedArenaMaxPermits = value; // default to 1
60+
}
61+
4262
private static final FeatureFlag MADV_RANDOM_FEATURE_FLAG = new FeatureFlag("madv_random");
4363

4464
public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> {
@@ -72,6 +92,7 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
7292
// Use Lucene defaults
7393
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
7494
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
95+
mMapDirectory = adjustSharedArenaGrouping(mMapDirectory);
7596
Directory dir = new HybridDirectory(lockFactory, setPreload(mMapDirectory, preLoadExtensions));
7697
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
7798
dir = disableRandomAdvice(dir);
@@ -81,7 +102,8 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
81102
return primaryDirectory;
82103
}
83104
case MMAPFS:
84-
Directory dir = setPreload(new MMapDirectory(location, lockFactory), preLoadExtensions);
105+
MMapDirectory mMapDirectory = adjustSharedArenaGrouping(new MMapDirectory(location, lockFactory));
106+
Directory dir = setPreload(mMapDirectory, preLoadExtensions);
85107
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
86108
dir = disableRandomAdvice(dir);
87109
}
@@ -101,6 +123,13 @@ public MMapDirectory setPreload(MMapDirectory mMapDirectory, Set<String> preLoad
101123
return mMapDirectory;
102124
}
103125

126+
public MMapDirectory adjustSharedArenaGrouping(MMapDirectory mMapDirectory) {
127+
if (sharedArenaMaxPermits <= 1) {
128+
mMapDirectory.setGroupingFunction(MMapDirectory.NO_GROUPING);
129+
}
130+
return mMapDirectory;
131+
}
132+
104133
/** Gets a preload function based on the given preLoadExtensions. */
105134
static BiPredicate<String, IOContext> getPreloadFunc(Set<String> preLoadExtensions) {
106135
if (preLoadExtensions.isEmpty() == false) {

0 commit comments

Comments
 (0)