GNU bug report logs - #77680
[PATCH 0/4] Avoid 'fdatasync' calls for cache files

Previous Next

Package: guix-patches;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Wed, 9 Apr 2025 14:23:03 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Ludovic Courtès <ludo <at> gnu.org>
To: 77680 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>, Christopher Baines <guix <at> cbaines.net>, Josselin Poiret <dev <at> jpoiret.xyz>, Ludovic Courtès <ludo <at> gnu.org>, Mathieu Othacehe <othacehe <at> gnu.org>, Simon Tournier <zimon.toutoune <at> gmail.com>, Tobias Geerinckx-Rice <me <at> tobias.gr>
Subject: [bug#77680] [PATCH v2 2/4] utils: Add #:sync? parameter to ‘with-atomic-file-output’.
Date: Fri, 11 Apr 2025 15:54:58 +0200
* guix/utils.scm (with-atomic-file-output): Add #:sync? and honor it.
Add ‘force-output’ call.

Change-Id: I2479778ae55360c0fab3389ac9249045a27b3568
---
 guix/utils.scm | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/guix/utils.scm b/guix/utils.scm
index c7c23d9d5b..7ae98096c2 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012-2022, 2024 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2012-2022, 2024-2025 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2013, 2014, 2015 Mark H Weaver <mhw <at> netris.org>
 ;;; Copyright © 2014 Eric Bavier <bavier <at> member.fsf.org>
 ;;; Copyright © 2014 Ian Denhardt <ian <at> zenhack.net>
@@ -1057,16 +1057,22 @@ (define (call-with-temporary-directory proc)
       (lambda ()
         (false-if-exception (delete-file-recursively tmp-dir))))))
 
-(define (with-atomic-file-output file proc)
+(define* (with-atomic-file-output file proc #:key (sync? #t))
   "Call PROC with an output port for the file that is going to replace FILE.
 Upon success, FILE is atomically replaced by what has been written to the
-output port, and PROC's result is returned."
+output port, and PROC's result is returned.
+
+When SYNC? is true, call 'fdatasync' on the temporary file before renaming it
+to FILE; set it to #false for caches and temporary files to improve
+performance."
   (let* ((template (string-append file ".XXXXXX"))
          (out      (mkstemp! template)))
     (with-throw-handler #t
       (lambda ()
         (let ((result (proc out)))
-          (fdatasync out)
+          (when sync?
+            (force-output out)
+            (fdatasync out))
           (close-port out)
           (rename-file template file)
           result))
-- 
2.49.0





This bug report was last modified 95 days ago.

Previous Next


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