GNU bug report logs - #14273
`write-region-inhibit-fsync' should default to t

Previous Next

Package: emacs;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Fri, 26 Apr 2013 06:53:02 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14273 in the body.
You can then email your comments to 14273 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#14273; Package emacs. (Fri, 26 Apr 2013 06:53:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Eggert <eggert <at> cs.ucla.edu>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 26 Apr 2013 06:53:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: bug-gnu-emacs <at> gnu.org
Subject: `write-region-inhibit-fsync' should default to t
Date: Thu, 25 Apr 2013 23:41:13 -0700
Tags: patch

These days it's better to default write-region-inhibit-fsync to t.
Here's a proposed patch, which I hope is self-explanatory.
This change speeds up "make compile-always" by 15% on my platform.

=== modified file 'doc/emacs/ChangeLog'
--- doc/emacs/ChangeLog	2013-04-04 03:46:25 +0000
+++ doc/emacs/ChangeLog	2013-04-26 06:35:33 +0000
@@ -1,3 +1,20 @@
+2013-04-26  Paul Eggert  <eggert <at> cs.ucla.edu>
+
+	`write-region-inhibit-fsync' now defaults to t.
+	* files.texi (Customize Save): Document this.
+	fsync can be a major performance hit.  Often it doesn't suffice to
+	make the file-save operation survive a crash anyway, so its
+	utility is questionable.
+	For more on why fsync often fails to work on today's hardware, see:
+	Zheng M, Tucek J, Qin F, Lillibridge M. Understanding the
+	robustness of SSDs under power fault. 11th USENIX Conference on
+	File and Storage Technologies, 2013 (FAST '13), 271-84
+	http://www.usenix.org/system/files/conference/fast13/fast13-final80.pdf
+	For more on why fsync does not suffice even if it works properly, see:
+	Roche X. Necessary step(s) to synchronize filename operations on disk.
+	Austin Group Defect 672, 2013-03-19
+	http://austingroupbugs.net/view.php?id=672
+
 2013-03-17  Paul Eggert  <eggert <at> cs.ucla.edu>
 
 	doc: convert some TeX accents to UTF-8

=== modified file 'doc/emacs/files.texi'
--- doc/emacs/files.texi	2013-02-25 17:36:03 +0000
+++ doc/emacs/files.texi	2013-04-26 06:35:33 +0000
@@ -705,13 +705,20 @@
 final newlines.
 
 @vindex write-region-inhibit-fsync
-  When Emacs saves a file, it invokes the @code{fsync} system call to
-force the data immediately out to disk.  This is important for safety
-if the system crashes or in case of power outage.  However, it can be
-disruptive on laptops using power saving, as it may force a disk
-spin-up each time you save a file.  If you accept an increased risk of
-data loss, you can set @code{write-region-inhibit-fsync} to a
-non-@code{nil} value to disable the synchronization.
+  Normally, when programs like Emacs write a file, the operating
+system briefly caches the file's data in main memory before committing
+the data to disk.  This can greatly improve performance; for example,
+when running on laptops, it can avoid a disk spin-up each time Emacs
+saves a file.  However, it risks data loss if the operating system
+crashes before committing the cache to disk.
+
+  To lessen this risk, set @code{write-region-inhibit-fsync} to
+@code{nil}: this causes Emacs to invoke the @code{fsync} system call
+after saving a file.  Using @code{fsync} does not eliminate the risk
+of data loss, partly because many systems do not implement
+@code{fsync} properly, and partly because Emacs's file-saving
+procedure typically relies also on directory updates that might not
+survive a crash even if @code{fsync} works properly.
 
 @node Interlocking
 @subsection Protection against Simultaneous Editing

=== modified file 'etc/ChangeLog'
--- etc/ChangeLog	2013-04-24 16:50:14 +0000
+++ etc/ChangeLog	2013-04-26 06:35:33 +0000
@@ -1,3 +1,7 @@
+2013-04-26  Paul Eggert  <eggert <at> cs.ucla.edu>
+
+	* NEWS: `write-region-inhibit-fsync' now defaults to t.
+
 2013-04-24  Tassilo Horn  <tsdh <at> gnu.org>
 
 	* themes/tsdh-dark-theme.el (tsdh-dark): Add ido faces and remove

=== modified file 'etc/NEWS'
--- etc/NEWS	2013-04-25 17:39:44 +0000
+++ etc/NEWS	2013-04-26 06:35:33 +0000
@@ -61,6 +61,8 @@
 ** `initial-buffer-choice' can now specify a function to set up the
 initial buffer.
 
+** `write-region-inhibit-fsync' now defaults to t instead of to nil.
+
 ** ACL support has been added.
 +++
 *** Emacs preserves the ACL entries of files when backing up.

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2013-04-24 15:09:49 +0000
+++ src/ChangeLog	2013-04-26 06:35:33 +0000
@@ -1,3 +1,8 @@
+2013-04-26  Paul Eggert  <eggert <at> cs.ucla.edu>
+
+	* fileio.c (syms_of_fileio):
+	`write-region-inhibit-fsync' now defaults to t.
+
 2013-04-24  Kenichi Handa  <handa <at> gnu.org>
 
 	* coding.c (decode_coding_iso_2022): When an invalid escape

=== modified file 'src/fileio.c'
--- src/fileio.c	2013-04-07 16:18:41 +0000
+++ src/fileio.c	2013-04-26 06:35:33 +0000
@@ -6072,8 +6072,9 @@
   DEFVAR_BOOL ("write-region-inhibit-fsync", write_region_inhibit_fsync,
 	       doc: /* Non-nil means don't call fsync in `write-region'.
 This variable affects calls to `write-region' as well as save commands.
-A non-nil value may result in data loss!  */);
-  write_region_inhibit_fsync = 0;
+Setting this to nil may avoid data loss if the system loses power or
+the operating system crashes.  */);
+  write_region_inhibit_fsync = 1;
 
   DEFVAR_BOOL ("delete-by-moving-to-trash", delete_by_moving_to_trash,
                doc: /* Specifies whether to use the system's trash can.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14273; Package emacs. (Fri, 26 Apr 2013 13:14:01 GMT) Full text and rfc822 format available.

Message #8 received at 14273 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 14273 <at> debbugs.gnu.org
Subject: Re: bug#14273: `write-region-inhibit-fsync' should default to t
Date: Fri, 26 Apr 2013 09:13:51 -0400
> These days it's better to default write-region-inhibit-fsync to t.

Agreed,


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14273; Package emacs. (Fri, 26 Apr 2013 13:51:02 GMT) Full text and rfc822 format available.

Message #11 received at 14273 <at> debbugs.gnu.org (full text, mbox):

From: Romain Francoise <romain <at> orebokech.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 14273 <at> debbugs.gnu.org
Subject: Re: bug#14273: `write-region-inhibit-fsync' should default to t
Date: Fri, 26 Apr 2013 15:50:28 +0200
Paul Eggert <eggert <at> cs.ucla.edu> writes:

> These days it's better to default write-region-inhibit-fsync to t.

FWIW, I disagree.

Yes, fsync hurts performance, and yes it's not always effective anyway.
But there are still many situations where it does help get the data to
disk in time to prevent data loss, and as far as default values are
concerned Emacs should err on the side of safety.

(You'll note that I was the one who added this option back in 2005.)

> This change speeds up "make compile-always" by 15% on my platform.

If build time is an issue, you can use `eatmydata' (or any of the
existing safety-disabling wrappers) to get the same benefit.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14273; Package emacs. (Sun, 28 Apr 2013 07:42:01 GMT) Full text and rfc822 format available.

Message #14 received at 14273 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Romain Francoise <romain <at> orebokech.com>
Cc: 14273 <at> debbugs.gnu.org
Subject: Re: bug#14273: `write-region-inhibit-fsync' should default to t
Date: Sun, 28 Apr 2013 00:41:35 -0700
[Message part 1 (text/plain, inline)]
On 04/26/2013 06:50 AM, Romain Francoise wrote:
> there are still many situations where it does help get the data to
> disk in time to prevent data loss

I'm sympathetic to this comment.  Still, Emacs uses fsync
far too often, and this often significantly hurts performance
for no particularly good reason.

How about the attached patch instead?  It causes Emacs to use fsync by
default only when operating interactively.  When running in batch
mode, fsync is disabled by default.  This would fix the performance
problem I observed (Emacs batch byte-compiles) without affecting
the warm fuzzy feeling one gets when one types C-x C-s.

I suppose Stefan may prefer the original patch, as it's simpler.
I'm OK either way, I guess.


[chefsync.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14273; Package emacs. (Sun, 28 Apr 2013 10:33:01 GMT) Full text and rfc822 format available.

Message #17 received at 14273 <at> debbugs.gnu.org (full text, mbox):

From: Romain Francoise <romain <at> orebokech.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 14273 <at> debbugs.gnu.org
Subject: Re: bug#14273: `write-region-inhibit-fsync' should default to t
Date: Sun, 28 Apr 2013 12:32:14 +0200
Paul Eggert <eggert <at> cs.ucla.edu> writes:

> How about the attached patch instead?  It causes Emacs to use fsync by
> default only when operating interactively.  When running in batch
> mode, fsync is disabled by default.  This would fix the performance
> problem I observed (Emacs batch byte-compiles) without affecting
> the warm fuzzy feeling one gets when one types C-x C-s.

Looks good to me. Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14273; Package emacs. (Sat, 04 May 2013 19:55:02 GMT) Full text and rfc822 format available.

Message #20 received at 14273 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 14273 <at> debbugs.gnu.org, Romain Francoise <romain <at> orebokech.com>
Subject: Re: bug#14273: `write-region-inhibit-fsync' should default to t
Date: Sat, 04 May 2013 15:53:33 -0400
> How about the attached patch instead?  It causes Emacs to use fsync by
> default only when operating interactively.

That looks OK for now.

> +	fsync can be a significant performance hit.  Often it doesn't
> +	suffice to make the file-save operation survive a crash.  For
> +	batch scripts, which are typically part of larger shell commands
> +	that don't fsync other files, its effect on performance can be
> +	significant so its utility is particularly questionable.
> +	For more on why fsync often fails to work on today's hardware, see:
> +	Zheng M, Tucek J, Qin F, Lillibridge M. Understanding the
> +	robustness of SSDs under power fault. 11th USENIX Conference on
> +	File and Storage Technologies, 2013 (FAST '13), 271-84
> +	http://www.usenix.org/system/files/conference/fast13/fast13-final80.pdf
> +	For more on why fsync does not suffice even if it works properly, see:
> +	Roche X. Necessary step(s) to synchronize filename operations on disk.
> +	Austin Group Defect 672, 2013-03-19
> +	http://austingroupbugs.net/view.php?id=672
> +	* cmdargs.texi (Initial Options):
> +	* files.texi (Customize Save): Document this.

But this longish text does not belong in the commitlog/changelog but in
the code.


        Stefan




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sun, 05 May 2013 00:55:01 GMT) Full text and rfc822 format available.

Notification sent to Paul Eggert <eggert <at> cs.ucla.edu>:
bug acknowledged by developer. (Sun, 05 May 2013 00:55:01 GMT) Full text and rfc822 format available.

Message #25 received at 14273-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 14273-done <at> debbugs.gnu.org, Romain Francoise <romain <at> orebokech.com>
Subject: Re: bug#14273: `write-region-inhibit-fsync' should default to t
Date: Sat, 04 May 2013 17:53:38 -0700
On 05/04/2013 12:53 PM, Stefan Monnier wrote:

> But this longish text does not belong in the commitlog/changelog but in
> the code.

OK, thanks, I moved it to the code and installed it.

I noticed another fsync that wasn't needed, when creating lock
files on hosts that don't support symlinks, and deleted that
fsync too.

I'm marking this bug as done.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 02 Jun 2013 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 351 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.