From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Romain Francoise Newsgroups: gmane.emacs.devel Subject: Re: Making fsync() optional Date: Tue, 13 Sep 2005 20:19:31 +0200 Organization: orebokech dot com Message-ID: <87mzmgsudo.fsf@pacem.orebokech.com> References: <87oe6yf5o9.fsf@pacem.orebokech.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1126636301 18484 80.91.229.2 (13 Sep 2005 18:31:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 13 Sep 2005 18:31:41 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 13 20:31:39 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EFFYs-0004Yz-Ee for ged-emacs-devel@m.gmane.org; Tue, 13 Sep 2005 20:31:18 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EFFYr-000246-PQ for ged-emacs-devel@m.gmane.org; Tue, 13 Sep 2005 14:31:17 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EFFXW-0001vP-8R for emacs-devel@gnu.org; Tue, 13 Sep 2005 14:29:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EFFXP-0001r5-17 for emacs-devel@gnu.org; Tue, 13 Sep 2005 14:29:47 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EFFXN-0001l4-Lj for emacs-devel@gnu.org; Tue, 13 Sep 2005 14:29:45 -0400 Original-Received: from [82.67.41.165] (helo=yeast.orebokech.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EFFNp-0003Fx-Ky; Tue, 13 Sep 2005 14:19:54 -0400 Original-Received: from pacem.orebokech.com (pacem.orebokech.com [192.168.1.3]) by yeast.orebokech.com (Postfix) with ESMTP id 15BB812FC1; Tue, 13 Sep 2005 20:19:30 +0200 (CEST) Original-Received: by pacem.orebokech.com (Postfix, from userid 1000) id BB79352406; Tue, 13 Sep 2005 20:19:31 +0200 (CEST) Original-To: rms@gnu.org X-Face: }9mYu,e_@+e!`Z-P5kVXa3\_b:hdJ"B)ww[&=b<2=awG:GOIM (Richard M. Stallman's message of "Tue, 13 Sep 2005 11:55:38 -0400") X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:42899 Archived-At: "Richard M. Stallman" 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 | I've become someone else's it's a miracle -- http://orebokech.com/ | nightmare...