aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0786-Do-not-overload-I-O-threads-with-chunk-data-while-fl.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0786-Do-not-overload-I-O-threads-with-chunk-data-while-fl.patch')
-rw-r--r--patches/server/0786-Do-not-overload-I-O-threads-with-chunk-data-while-fl.patch42
1 files changed, 42 insertions, 0 deletions
diff --git a/patches/server/0786-Do-not-overload-I-O-threads-with-chunk-data-while-fl.patch b/patches/server/0786-Do-not-overload-I-O-threads-with-chunk-data-while-fl.patch
new file mode 100644
index 0000000000..dad671a3bd
--- /dev/null
+++ b/patches/server/0786-Do-not-overload-I-O-threads-with-chunk-data-while-fl.patch
@@ -0,0 +1,42 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Spottedleaf <[email protected]>
+Date: Sat, 16 Oct 2021 01:36:00 -0700
+Subject: [PATCH] Do not overload I/O threads with chunk data while flush
+ saving
+
+If the chunk count is high, then the memory used by the
+chunks adds up and could cause problems. By flushing
+every so many chunks, the server will not become
+stressed for memory. It will also not increase the total
+time to save, as flush saving performs a full flush at
+the end anyways.
+
+diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
+index 952286cca1ce9e893f4a9e5939c552efe975abb4..9ba13ee1df980b9bd5318cefeb3412a8923b66a3 100644
+--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
+@@ -928,6 +928,16 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
+ // Paper end
+
+ protected void saveAllChunks(boolean flush) {
++ // Paper start - do not overload I/O threads with too much work when saving
++ int[] saved = new int[1];
++ int maxAsyncSaves = 50;
++ Runnable onChunkSave = () -> {
++ if (++saved[0] >= maxAsyncSaves) {
++ saved[0] = 0;
++ com.destroystokyo.paper.io.PaperFileIOThread.Holder.INSTANCE.flush();
++ }
++ };
++ // Paper end - do not overload I/O threads with too much work when saving
+ if (flush) {
+ List<ChunkHolder> list = (List) this.updatingChunks.getVisibleValuesCopy().stream().filter(ChunkHolder::wasAccessibleSinceLastSave).peek(ChunkHolder::refreshAccessibility).collect(Collectors.toList()); // Paper
+ MutableBoolean mutableboolean = new MutableBoolean();
+@@ -950,6 +960,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
+ }).filter((ichunkaccess) -> {
+ return ichunkaccess instanceof ImposterProtoChunk || ichunkaccess instanceof LevelChunk;
+ }).filter(this::save).forEach((ichunkaccess) -> {
++ onChunkSave.run(); // Paper - do not overload I/O threads with too much work when saving
+ mutableboolean.setTrue();
+ });
+ } while (mutableboolean.isTrue());