testserver/patches/server/0074-Sanitise-RegionFileCac...

40 lines
2.1 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Antony Riley <antony@cyberiantiger.org>
Date: Tue, 29 Mar 2016 08:22:55 +0300
Subject: [PATCH] Sanitise RegionFileCache and make configurable.
RegionFileCache prior to this patch would close every single open region
file upon reaching a size of 256.
This patch modifies that behaviour so it closes the the least recently
used RegionFile.
The implementation uses a LinkedHashMap as an LRU cache (modified from HashMap).
The maximum size of the RegionFileCache is also made configurable.
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index e3ca633a99d30ebf9dc35fd9236836b577a2b598..78f3e00715a5d3a60c341461a7cd4fa52e2492f0 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -236,4 +236,9 @@ public class PaperConfig {
2021-06-11 12:02:28 +00:00
private static void loadPermsBeforePlugins() {
loadPermsBeforePlugins = getBoolean("settings.load-permissions-yml-before-plugins", true);
}
+
+ public static int regionFileCacheSize = 256;
+ private static void regionFileCacheSize() {
+ regionFileCacheSize = Math.max(getInt("settings.region-file-cache-size", 256), 4);
+ }
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
2021-06-15 22:24:12 +00:00
index e506fa1153cabfb93c7bece73e6fe0fafbb958c9..f973792c8ee4523eb4efdf31d0a97cb3358e1b3b 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
2021-06-15 22:24:12 +00:00
@@ -35,7 +35,7 @@ public class RegionFileStorage implements AutoCloseable {
2021-06-11 12:02:28 +00:00
if (regionfile != null) {
return regionfile;
} else {
- if (this.regionCache.size() >= 256) {
+ if (this.regionCache.size() >= com.destroystokyo.paper.PaperConfig.regionFileCacheSize) { // Paper - configurable
((RegionFile) this.regionCache.removeLast()).close();
}