From 6719e6170472d7b8e95360ca653ad82003a76c77 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sat, 6 Apr 2019 02:59:42 -0700 Subject: [PATCH] Only flush to disk on chunk saves if paper.flush-on-save is true (#1942) The cost of a call to sync() adds up quickly and especially for HDDs. Playing around generating chunks for a while warranted a 3 min save time on a HDD. This is unacceptable default behaviour and now the behaviour is hidden behind a flag for server owners who are OK with taking a hit on saves (although SSDs will not have this issue remotely as bad, since most of the time was spent seeking). --- ...region-files-more-reliable-to-write-to.patch | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch b/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch index a96a272b27..5cc9febf1c 100644 --- a/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch +++ b/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch @@ -11,9 +11,9 @@ Now the saving process has been changed to follow this chain of events: overwrite and corrupt the current data 2. Write the chunk data first (the order of the fields in the chunk data isn't relevant though) -3. Flush to disk +3. Flush to disk (if the launch flag is used) 4. Write to the region header last -5. Flush to disk +5. Flush to disk (if the launch flag is used) 6. Then we free the previous space allocated With this chain of events it is impossible for a chunk write to corrupt @@ -27,12 +27,17 @@ Note that when Mojang finally decides to change their region format to deal with oversized chunks this patch must be changed to deal with whatever system they decide to impose. +If the paper.flush-on-save startup flag is set to true, then the +steps 3 and 5 will make a call to sync() on the region file's fd, +effectively flushing to disk. + We also make use of two flushes to disk per chunk save (to ensure ordering and ensure data has gone to disk), so this will negatively -affect save performance. +affect save performance if the startup flag is used (especially on +HDDs). diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java -index 82f7af46f..2e2844133 100644 +index 82f7af46f..e5659980b 100644 --- a/src/main/java/net/minecraft/server/RegionFile.java +++ b/src/main/java/net/minecraft/server/RegionFile.java @@ -0,0 +0,0 @@ public class RegionFile { @@ -149,7 +154,11 @@ index 82f7af46f..2e2844133 100644 } // Paper start ++ private static final boolean FLUSH_ON_SAVE = Boolean.getBoolean("paper.flush-on-save"); + private void syncRegionFile() throws IOException { ++ if (!FLUSH_ON_SAVE) { ++ return; ++ } + this.getDataFile().getFD().sync(); // rethrow exception as we want to avoid corrupting a regionfile + } +