]> granicus.if.org Git - transmission/commitdiff
(trunk libT) fsync busy files every 15 seconds or so. On linux, use posix_fadvise...
authorCharles Kerr <charles@transmissionbt.com>
Mon, 26 Jan 2009 00:36:34 +0000 (00:36 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 26 Jan 2009 00:36:34 +0000 (00:36 +0000)
libtransmission/fdlimit.c

index c43668c109d2306462734bec9153d50bc288a7eb..bfb36e7a6b5f091a3b3dff52aefeb82062ff913c 100644 (file)
@@ -79,6 +79,9 @@ enum
 {
     NOFILE_BUFFER = 512, /* the process' number of open files is
                             globalMaxPeers + NOFILE_BUFFER */
+
+    SYNC_INTERVAL = 15   /* (arbitrary number) how many seconds to go
+                            between fsync calls for files in heavy use */
 };
 
 struct tr_openfile
@@ -89,6 +92,7 @@ struct tr_openfile
     char       filename[MAX_PATH_LENGTH];
     int        fd;
     uint64_t   date;
+    time_t     syncAt;
 };
 
 struct tr_fd_s
@@ -387,8 +391,7 @@ tr_fdFileCheckout( const char             * folder,
         }
         else
         {
-            dbgmsg(
-                "everything's full!  waiting for someone else to finish something" );
+            dbgmsg( "everything's full!  waiting for someone else to finish something" );
             tr_lockUnlock( gFd->lock );
             tr_wait( 200 );
             tr_lockLock( gFd->lock );
@@ -410,6 +413,7 @@ tr_fdFileCheckout( const char             * folder,
                 doWrite ? 'y' : 'n' );
         tr_strlcpy( o->filename, filename, sizeof( o->filename ) );
         o->isWritable = doWrite;
+        o->syncAt = time( NULL ) + SYNC_INTERVAL;
     }
 
     dbgmsg( "checking out '%s' in slot %d", filename, winner );
@@ -437,6 +441,15 @@ tr_fdFileReturn( int fd )
         o->isCheckedOut = 0;
         if( o->closeWhenDone )
             TrCloseFile( i );
+        else if( o->syncAt <= time( NULL ) ) {
+            dbgmsg( "fsync()ing file '%s' in slot #%d", o->filename, i );
+            fsync( o->fd );
+#ifdef HAVE_POSIX_FADVISE
+            /* TODO: test performance with and without this */
+            posix_fadvise( o->fd, 0, 0, POSIX_FADV_DONTNEED );
+#endif
+            o->syncAt = time( NULL ) + SYNC_INTERVAL;
+        }
 
         break;
     }