Skip to contentSkip to conversation

Speed up test suite by avoiding fsync

PATCH In review Colin Watson 2 participants 2 messages Nov 27, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Speed up test suite by avoiding fsync

Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls into no-ops, and use it in programs that copy files but do not need to take special care to sync writes (grub-mknetdir, grub-rescue, grub-mkstandalone).

On my laptop, this reduces partmap_test's runtime from 1236 seconds to 204 seconds.

---
 ChangeLog                          |  7 +++++++
 grub-core/osdep/aros/hostdisk.c    | 25 ++++++++++++++++++-------
 grub-core/osdep/unix/hostdisk.c    | 11 ++++++++++-
 grub-core/osdep/windows/hostdisk.c | 11 ++++++++++-
 include/grub/emu/hostfile.h        |  2 ++
 util/grub-install-common.c         |  2 +-
 util/grub-mknetdir.c               |  1 +
 util/grub-mkrescue.c               |  3 ++-
 util/grub-mkstandalone.c           |  1 +
 9 files changed, 52 insertions(+), 11 deletions(-)
ChangeLog +7 -0
index 2e0d96e..4bbec86 100644
@@ -1,3 +1,10 @@
+2013-11-27  Colin Watson  <[email protected]>
+
+	Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls
+	into no-ops, and use it in programs that copy files but do not need
+	to take special care to sync writes (grub-mknetdir, grub-rescue,
+	grub-mkstandalone).
+
 2013-11-26  Colin Watson  <[email protected]>
 
 	* tests/util/grub-fs-tester.in: Execute xorriso from $PATH rather
grub-core/osdep/aros/hostdisk.c +18 -7
index 9c0a6c8..b153907 100644
@@ -455,6 +455,8 @@ grub_util_fd_close (grub_util_fd_t fd)
     }
 }
 
+static int allow_fd_syncs = 1;
+
 static void
 grub_util_fd_sync_volume (grub_util_fd_t fd)
 {
@@ -469,18 +471,27 @@ grub_util_fd_sync_volume (grub_util_fd_t fd)
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  switch (fd->type)
+  if (allow_fd_syncs)
     {
-    case GRUB_UTIL_FD_FILE:
-      fsync (fd->fd);
-      return;
-    case GRUB_UTIL_FD_DISK:
-      grub_util_fd_sync_volume (fd);
-      return;
+      switch (fd->type)
+	{
+	case GRUB_UTIL_FD_FILE:
+	  fsync (fd->fd);
+	  return;
+	case GRUB_UTIL_FD_DISK:
+	  grub_util_fd_sync_volume (fd);
+	  return;
+	}
     }
 }
 
 void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
+}
+
+void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
 }
grub-core/osdep/unix/hostdisk.c +10 -1
index 78d4adb..fc88ed4 100644
@@ -191,10 +191,19 @@ grub_util_fd_strerror (void)
   return strerror (errno);
 }
 
+static int allow_fd_syncs = 1;
+
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  fsync (fd);
+  if (allow_fd_syncs)
+    fsync (fd);
+}
+
+void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
 }
 
 void
grub-core/osdep/windows/hostdisk.c +10 -1
index 6d7d120..4748a61 100644
@@ -240,10 +240,19 @@ grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len)
   return real_read;
 }
 
+static int allow_fd_syncs = 1;
+
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  FlushFileBuffers (fd);
+  if (allow_fd_syncs)
+    FlushFileBuffers (fd);
+}
+
+void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
 }
 
 void
include/grub/emu/hostfile.h +2 -0
index ab01fbc..8e37d5a 100644
@@ -50,6 +50,8 @@ EXPORT_FUNC(grub_util_fd_strerror) (void);
 void
 grub_util_fd_sync (grub_util_fd_t fd);
 void
+grub_util_disable_fd_syncs (void);
+void
 EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
 
 grub_uint64_t
util/grub-install-common.c +1 -1
index 7ecef3e..fcf994d 100644
@@ -492,7 +492,7 @@ grub_install_make_image_wrap (const char *dir, const char *prefix,
 				     memdisk_path, config_path,
 				     mkimage_target, note, comp);
   fflush (fp);
-  fsync (fileno (fp));
+  grub_util_fd_sync (fileno (fp));
   fclose (fp);
 }
 
util/grub-mknetdir.c +1 -0
index 3f91705..40ca724 100644
@@ -171,6 +171,7 @@ main (int argc, char *argv[])
   const char *pkglibdir;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
   rootdir = xstrdup ("/srv/tftp");
   pkglibdir = grub_util_get_pkglibdir ();
 
util/grub-mkrescue.c +2 -1
index 7a76bc3..b081b3b 100644
@@ -369,6 +369,7 @@ main (int argc, char *argv[])
   const char *pkgdatadir;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
 
   pkgdatadir = grub_util_get_pkgdatadir ();
 
@@ -529,7 +530,7 @@ main (int argc, char *argv[])
 					    GRUB_COMPRESSION_AUTO);
 	      sz = ftello (sa);
 	      fflush (sa);
-	      fsync (fileno (sa));
+	      grub_util_fd_sync (fileno (sa));
 	      fclose (sa);
 	      
 	      if (sz > 32768)
util/grub-mkstandalone.c +1 -0
index 774af2f..3097f70 100644
@@ -305,6 +305,7 @@ main (int argc, char *argv[])
   int i;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
 
   files = xmalloc ((argc + 1) * sizeof (files[0]));
 
Signature · 1 line
1.8.4.3
#1 lore raw
Quoted 5 lines · Colin Watson

Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls into no-ops, and use it in programs that copy files but do not need to take special care to sync writes (grub-mknetdir, grub-rescue, grub-mkstandalone).

Go ahead.

Quoted 199 lines

On my laptop, this reduces partmap_test's runtime from 1236 seconds to 204 seconds.

---
 ChangeLog                          |  7 +++++++
 grub-core/osdep/aros/hostdisk.c    | 25 ++++++++++++++++++-------
 grub-core/osdep/unix/hostdisk.c    | 11 ++++++++++-
 grub-core/osdep/windows/hostdisk.c | 11 ++++++++++-
 include/grub/emu/hostfile.h        |  2 ++
 util/grub-install-common.c         |  2 +-
 util/grub-mknetdir.c               |  1 +
 util/grub-mkrescue.c               |  3 ++-
 util/grub-mkstandalone.c           |  1 +
 9 files changed, 52 insertions(+), 11 deletions(-)
ChangeLog +7 -0
index 2e0d96e..4bbec86 100644
@@ -1,3 +1,10 @@
+2013-11-27  Colin Watson  <[email protected]>
+
+	Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls
+	into no-ops, and use it in programs that copy files but do not need
+	to take special care to sync writes (grub-mknetdir, grub-rescue,
+	grub-mkstandalone).
+
 2013-11-26  Colin Watson  <[email protected]>
 
 	* tests/util/grub-fs-tester.in: Execute xorriso from $PATH rather
grub-core/osdep/aros/hostdisk.c +18 -7
index 9c0a6c8..b153907 100644
@@ -455,6 +455,8 @@ grub_util_fd_close (grub_util_fd_t fd)
     }
 }
 
+static int allow_fd_syncs = 1;
+
 static void
 grub_util_fd_sync_volume (grub_util_fd_t fd)
 {
@@ -469,18 +471,27 @@ grub_util_fd_sync_volume (grub_util_fd_t fd)
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  switch (fd->type)
+  if (allow_fd_syncs)
     {
-    case GRUB_UTIL_FD_FILE:
-      fsync (fd->fd);
-      return;
-    case GRUB_UTIL_FD_DISK:
-      grub_util_fd_sync_volume (fd);
-      return;
+      switch (fd->type)
+	{
+	case GRUB_UTIL_FD_FILE:
+	  fsync (fd->fd);
+	  return;
+	case GRUB_UTIL_FD_DISK:
+	  grub_util_fd_sync_volume (fd);
+	  return;
+	}
     }
 }
 
 void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
+}
+
+void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
 }
grub-core/osdep/unix/hostdisk.c +10 -1
index 78d4adb..fc88ed4 100644
@@ -191,10 +191,19 @@ grub_util_fd_strerror (void)
   return strerror (errno);
 }
 
+static int allow_fd_syncs = 1;
+
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  fsync (fd);
+  if (allow_fd_syncs)
+    fsync (fd);
+}
+
+void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
 }
 
 void
grub-core/osdep/windows/hostdisk.c +10 -1
index 6d7d120..4748a61 100644
@@ -240,10 +240,19 @@ grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len)
   return real_read;
 }
 
+static int allow_fd_syncs = 1;
+
 void
 grub_util_fd_sync (grub_util_fd_t fd)
 {
-  FlushFileBuffers (fd);
+  if (allow_fd_syncs)
+    FlushFileBuffers (fd);
+}
+
+void
+grub_util_disable_fd_syncs (void)
+{
+  allow_fd_syncs = 0;
 }
 
 void
include/grub/emu/hostfile.h +2 -0
index ab01fbc..8e37d5a 100644
@@ -50,6 +50,8 @@ EXPORT_FUNC(grub_util_fd_strerror) (void);
 void
 grub_util_fd_sync (grub_util_fd_t fd);
 void
+grub_util_disable_fd_syncs (void);
+void
 EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
 
 grub_uint64_t
util/grub-install-common.c +1 -1
index 7ecef3e..fcf994d 100644
@@ -492,7 +492,7 @@ grub_install_make_image_wrap (const char *dir, const char *prefix,
 				     memdisk_path, config_path,
 				     mkimage_target, note, comp);
   fflush (fp);
-  fsync (fileno (fp));
+  grub_util_fd_sync (fileno (fp));
   fclose (fp);
 }
 
util/grub-mknetdir.c +1 -0
index 3f91705..40ca724 100644
@@ -171,6 +171,7 @@ main (int argc, char *argv[])
   const char *pkglibdir;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
   rootdir = xstrdup ("/srv/tftp");
   pkglibdir = grub_util_get_pkglibdir ();
 
util/grub-mkrescue.c +2 -1
index 7a76bc3..b081b3b 100644
@@ -369,6 +369,7 @@ main (int argc, char *argv[])
   const char *pkgdatadir;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
 
   pkgdatadir = grub_util_get_pkgdatadir ();
 
@@ -529,7 +530,7 @@ main (int argc, char *argv[])
 					    GRUB_COMPRESSION_AUTO);
 	      sz = ftello (sa);
 	      fflush (sa);
-	      fsync (fileno (sa));
+	      grub_util_fd_sync (fileno (sa));
 	      fclose (sa);
 
 	      if (sz > 32768)
util/grub-mkstandalone.c +1 -0
index 774af2f..3097f70 100644
@@ -305,6 +305,7 @@ main (int argc, char *argv[])
   int i;
 
   grub_util_host_init (&argc, &argv);
+  grub_util_disable_fd_syncs ();
 
   files = xmalloc ((argc + 1) * sizeof (files[0]));