From: Romain Francoise <romain@orebokech.com>
Cc: emacs-devel@gnu.org
Subject: Re: Making fsync() optional
Date: Tue, 13 Sep 2005 20:19:31 +0200 [thread overview]
Message-ID: <87mzmgsudo.fsf@pacem.orebokech.com> (raw)
In-Reply-To: <E1EFD8E-0000mM-8O@fencepost.gnu.org> (Richard M. Stallman's message of "Tue, 13 Sep 2005 11:55:38 -0400")
"Richard M. Stallman" <rms@gnu.org> writes:
> It is not called after each write, just once at the end of writing the
> whole file.
Yes, that's what I meant, sorry for the confusion.
> This is very important for safety. Without this, you can type C-x
> C-s, and see the command finish, and see the message that the file has
> been written, but you can still lose it all if the system crashes
> after that.
In theory, yes. In practice, IDE drives use write caching and lie to
the kernel about the status of the data: even if fsync() returns the
data may not be on the platter. The drives do that to write data to
disk out of order, and to be able to delay writing blocks as long as
needed under heavy seek load. The only way to ensure immediate data
consistency is to disable write caching (on GNU/Linux, using the -W
option to hdparm) or to use SCSI disks.
> However, I would not mind adding a flag to turn it off, as long as the
> doc string of that flag warns that this is dangerous.
OK. I'm proposing a revised patch below.
I'm not sure if I should document the variable in the manual: it is
rather specialized so people who need it will know what it does and
won't need the manual to find it... and it is self-explanatory. (And as
it's potentially dangerous, we don't want inexperienced users to enable
it.)
>> It also forces the disk to spin up on laptops (even with laptop mode
>> and friends).
> It has to do that anyway. I don't want it to wait a minute before it
> writes the file!
There are specialized modes in the Linux kernel that cache all data for
some time and spin up the drive periodically only to commit all the
data, then spin down the drive, etc. This allows for maximum power
saving on laptops--provided no fsync() calls are issued.
(Of course, not everyone wants this.)
Proposed patch:
Index: src/fileio.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/fileio.c,v
retrieving revision 1.553
diff -c -r1.553 fileio.c
*** src/fileio.c 12 Sep 2005 13:42:49 -0000 1.553
--- src/fileio.c 13 Sep 2005 17:54:16 -0000
***************
*** 225,230 ****
--- 225,235 ----
expanding file names. This can be bound to / or \. */
Lisp_Object Vdirectory_sep_char;
+ #ifdef HAVE_FSYNC
+ /* Nonzero means skip the call to fsync() in Fwrite-region. */
+ int inhibit_fsync;
+ #endif
+
extern Lisp_Object Vuser_login_name;
#ifdef WINDOWSNT
***************
*** 5298,5304 ****
Disk full in NFS may be reported here. */
/* mib says that closing the file will try to write as fast as NFS can do
it, and that means the fsync here is not crucial for autosave files. */
! if (!auto_saving && fsync (desc) < 0)
{
/* If fsync fails with EINTR, don't treat that as serious. */
if (errno != EINTR)
--- 5303,5309 ----
Disk full in NFS may be reported here. */
/* mib says that closing the file will try to write as fast as NFS can do
it, and that means the fsync here is not crucial for autosave files. */
! if (!auto_saving && !inhibit_fsync && fsync (desc) < 0)
{
/* If fsync fails with EINTR, don't treat that as serious. */
if (errno != EINTR)
***************
*** 6743,6748 ****
--- 6748,6760 ----
shortly after Emacs reads your `.emacs' file, if you have not yet given it
a non-nil value. */);
Vauto_save_list_file_name = Qnil;
+
+ #ifdef HAVE_FSYNC
+ DEFVAR_BOOL ("inhibit-fsync", &inhibit_fsync,
+ doc: /* Non-nil means don't call fsync() after saving files.
+ Enabling this variable may result in data loss! */);
+ inhibit_fsync = 0;
+ #endif
defsubr (&Sfind_file_name_handler);
defsubr (&Sfile_name_directory);
--
Romain Francoise <romain@orebokech.com> | I've become someone else's
it's a miracle -- http://orebokech.com/ | nightmare...
next prev parent reply other threads:[~2005-09-13 18:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-12 19:27 Making fsync() optional Romain Francoise
2005-09-13 15:55 ` Richard M. Stallman
2005-09-13 18:19 ` Romain Francoise [this message]
2005-09-14 14:06 ` Richard M. Stallman
2005-09-15 8:45 ` Romain Francoise
2005-09-16 1:01 ` Richard M. Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mzmgsudo.fsf@pacem.orebokech.com \
--to=romain@orebokech.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.