From db2502d732fe04e4e8825fd6cfa67388d7e2265d Mon Sep 17 00:00:00 2001 From: Antony Riley 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. --- .../level/chunk/storage/RegionFileStorage.java.patch | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileStorage.java.patch b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileStorage.java.patch index 7f38ae92a..4e4fd07bd 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileStorage.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileStorage.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/chunk/storage/RegionFileStorage.java +++ b/net/minecraft/world/level/chunk/storage/RegionFileStorage.java -@@ -32,8 +32,8 @@ +@@ -32,21 +32,22 @@ this.info = storageKey; } @@ -11,7 +11,12 @@ RegionFile regionfile = (RegionFile) this.regionCache.getAndMoveToFirst(i); if (regionfile != null) { -@@ -45,8 +45,9 @@ + return regionfile; + } else { +- if (this.regionCache.size() >= 256) { ++ if (this.regionCache.size() >= io.papermc.paper.configuration.GlobalConfiguration.get().misc.regionFileCacheSize) { // Paper - Sanitise RegionFileCache and make configurable + ((RegionFile) this.regionCache.removeLast()).close(); + } FileUtil.createDirectoriesSafe(this.folder); Path path = this.folder;