From b5101f4f9782ef8b95819c77ca3d2f540aaf5d8a Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 4 May 2020 01:03:57 -0400 Subject: [PATCH] Cleanup Region Files Direct Memory on close Mojang was semi leaking native memory here by relying on finalizers to clean up the direct memory. Finalizers have no guarantee on when they will be ran, and since this is old generation memory, it might be a while before its called. --- ...-Region-Files-Direct-Memory-on-close.patch | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Spigot-Server-Patches/0500-Cleanup-Region-Files-Direct-Memory-on-close.patch diff --git a/Spigot-Server-Patches/0500-Cleanup-Region-Files-Direct-Memory-on-close.patch b/Spigot-Server-Patches/0500-Cleanup-Region-Files-Direct-Memory-on-close.patch new file mode 100644 index 000000000..9a5e48525 --- /dev/null +++ b/Spigot-Server-Patches/0500-Cleanup-Region-Files-Direct-Memory-on-close.patch @@ -0,0 +1,35 @@ +From b649a81d4edeb173e725b72ad931a7f0a81b6714 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Mon, 4 May 2020 00:38:13 -0400 +Subject: [PATCH] Cleanup Region Files Direct Memory on close + +Mojang was semi leaking native memory here by relying on finalizers +to clean up the direct memory. + +Finalizers have no guarantee on when they will be ran, and since this is +old generation memory, it might be a while before its called. + +diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java +index df728e2c0a..c565307a58 100644 +--- a/src/main/java/net/minecraft/server/RegionFile.java ++++ b/src/main/java/net/minecraft/server/RegionFile.java +@@ -30,7 +30,7 @@ public class RegionFile implements AutoCloseable { + private final FileChannel dataFile; + private final java.nio.file.Path d; + private final RegionFileCompression e; +- private final ByteBuffer f; ++ private final ByteBuffer f; private ByteBuffer getFileBuffer() { return f; } // Paper - clean up direct buffers on close + private final IntBuffer g; + private final IntBuffer h; + private final RegionFileBitSet freeSectors; +@@ -403,6 +403,7 @@ public class RegionFile implements AutoCloseable { + } + } finally { // Paper start - Prevent regionfiles from being closed during use + this.fileLock.unlock(); ++ if (getFileBuffer() instanceof sun.nio.ch.DirectBuffer) ((sun.nio.ch.DirectBuffer) getFileBuffer()).cleaner().clean(); // Paper - clean up direct buffers on close + } + } // Paper end + +-- +2.26.2 +