--- Begin Message ---
Subject: |
30.0.50; `write-region-inhibit-fsync' and copy-on-write file systems |
Date: |
Sun, 01 Jan 2023 18:51:59 +0000 |
Hi,
We are currently exploring performance of frequent file writes in Emacs.
This is important in org-persist library when we need to cache large
number of data pieces, writing them on disk.
It turns out that Emacs is pretty slow when writing hundreds of files:
(benchmark-run-compiled
1000
(with-temp-file "/tmp/test"
(insert "test"))) ; => 4 sec
Mostly because of fsync:
(benchmark-run-compiled
1000
(let ((write-region-inhibit-fsync t))
(with-temp-file "/tmp/test"
(insert "test")))) ; => 0.15 sec
Timothy have found the following comment in src/fileio.c:
/* 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.
Hence, for now by default fsync is used only when interactive.
For more on why fsync often fails to work on today's hardware, see:
Zheng M et al. Understanding the robustness of SSDs under power fault.
11th USENIX Conf. on File and Storage Technologies, 2013 (FAST '13), 271-84
https://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
https://austingroupbugs.net/view.php?id=672 */
write_region_inhibit_fsync = noninteractive;
Although fsync may provide some benefit on generic file systems, it does
not look like it is any useful in copy-on-write file systems.
I am wondering if Emacs could detect file system when writing the file
and disable fsync for FSes like BTRFS and other CoW file systems.
In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.35, cairo version 1.17.6) of 2022-12-26 built on localhost
Repository revision: cc29fab3a66c59e77d0ff67c0f3e2e34ec80a03c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Gentoo Linux
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#60474: 30.0.50; `write-region-inhibit-fsync' and copy-on-write file systems |
Date: |
Mon, 2 Jan 2023 11:38:00 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 |
On 2023-01-02 04:12, Eli Zaretskii wrote:
Thanks, this is okay for master, but could you perhaps add a sentence,
in the manual and in NEWS, about the exceptional situations when this
variable should be reset to nil? I think we should say something,
otherwise the need for the variable is questionable.
I gave that a shot and installed the attached patch to master. This
patch also removes a now-duplicate assignment to
write_region_inhibit_fsync in init_fileio. Closing the bug report.
While doing this I noticed that the only place
write-region-inhibit-fsync is let-bound to nil in Emacs's own code is in
lisp/emacs-lisp/multisession.el, due to commit
ccb602836426f1fc2e43fa3506427744668f24c6 dated 2021-12-17 which I
hypothesize is due to MS-Windows needing it when multiple processes are
accessing the same file in a transaction-like application. So the
attached patch adds some wording to that effect. Please feel free to
improve it. I suppose for similar reasons it may also be helpful in
GNU/Linux with transaction-like Emacs apps on networked file systems; I
haven't checked this, though, and anyway once you're on a network this
sort of thing is dubious anyway.
0001-Improve-interactive-file-saving-performance.patch
Description: Text Data
--- End Message ---