[OpenAFS-devel] Patch to disable fsync()ing

Robert Banz banz@umbc.edu
Fri, 16 Mar 2007 12:08:57 -0400


The following patch adds the options "-nofsync" to the namei-based  
fileserver and volserver, disabling fsync() operations.

For the volserver, local tests have shown that this speeds up volume  
moves significantly.

For the fileserver, I've seen 4x increases in speed when doing file- 
creation/deletion intensive tasks.

I'd only recommend using it if your underlying filesystem is gosh  
darn stable -- but we haven't seen any problems running things like  
this for months now (even with a couple power outages! :( )

This patch is against 1.4.2.


Robert Banz
Coordinator, Core Systems
banz@umbc.edu



diff -c -r openafs-1.4.2-dist/src/viced/afsfileprocs.c openafs-1.4.2- 
nofsync/src/viced/afsfileprocs.c
*** openafs-1.4.2-dist/src/viced/afsfileprocs.c Mon Sep 25 22:13:17 2006
--- openafs-1.4.2-nofsync/src/viced/afsfileprocs.c      Fri Mar 16  
10:46:05 2007
***************
*** 119,124 ****
--- 119,130 ----
   extern void FidZap(DirHandle * file);
   extern void FidZero(DirHandle * file);

+ #ifdef AFS_NAMEI_ENV
+ extern int volops_fsync;
+ #else
+ static int volops_fsync = 1;
+ #endif
+
   #ifdef AFS_PTHREAD_ENV
   pthread_mutex_t fileproc_glock_mutex;
   #endif /* AFS_PTHREAD_ENV */
***************
*** 1232,1239 ****
                 V_parentId(volptr));
       assert(!rc);
       IH_RELEASE(targetptr->handle);
!
!     rc = FDH_SYNC(newFdP);
       assert(rc == 0);
       FDH_CLOSE(newFdP);
       targetptr->handle = newH;
--- 1238,1249 ----
                 V_parentId(volptr));
       assert(!rc);
       IH_RELEASE(targetptr->handle);
!
!     if ( volops_fsync ) {
!       rc = FDH_SYNC(newFdP);
!     } else {
!       rc = 0;
!     }
       assert(rc == 0);
       FDH_CLOSE(newFdP);
       targetptr->handle = newH;
diff -c -r openafs-1.4.2-dist/src/viced/viced.c openafs-1.4.2-nofsync/ 
src/viced/viced.c
*** openafs-1.4.2-dist/src/viced/viced.c        Fri Sep 15 19:19:28 2006
--- openafs-1.4.2-nofsync/src/viced/viced.c     Fri Mar 16 10:36:03 2007
***************
*** 158,163 ****
--- 158,167 ----
   extern int LogLevel;
   extern int Statistics;

+ #ifdef AFS_NAMEI_ENV
+ extern int volops_fsync;
+ #endif
+
   int busyonrst = 1;
   int timeout = 30;
   int SawSpare;
***************
*** 760,765 ****
--- 764,772 ----
       strcat(buffer, "[-abortthreshold <abort threshold>] ");
   /*   strcat(buffer, "[-enable_peer_stats] "); */
   /*   strcat(buffer, "[-enable_process_stats] "); */
+ #ifdef AFS_NAMEI_ENV
+     strcat(buffer, "[-nofsync]");
+ #endif
       strcat(buffer, "[-help]\n");
   /*
       ViceLog(0, ("%s", buffer));
***************
*** 1158,1163 ****
--- 1165,1175 ----
             /* set syslog logging flag */
             mrafsStyleLogs = 1;
         }
+ #ifdef AFS_NAMEI_ENV
+   else if (strcmp(argv[i], "-nofsync") == 0) {
+     volops_fsync = 0;
+   }
+ #endif
         else {
             return (-1);
         }
diff -c -r openafs-1.4.2-dist/src/vol/clone.c openafs-1.4.2-nofsync/ 
src/vol/clone.c
*** openafs-1.4.2-dist/src/vol/clone.c  Fri Oct  6 08:33:57 2006
--- openafs-1.4.2-nofsync/src/vol/clone.c       Fri Mar 16 10:30:54 2007
***************
*** 89,94 ****
--- 89,100 ----
   void CloneVolume();
   void CloneVolume_r();

+ #ifdef AFS_NAMEI_ENV
+ extern int volops_fsync;
+ #else
+ int volops_fsync = 1;
+ #endif
+
   static int
   ci_AddItem(struct clone_head *ah, Inode aino)
   {
***************
*** 385,391 ****
                 error = FDH_TRUNC(rwFd, offset);
             }
         }
!       FDH_SYNC(rwFd);
         FDH_CLOSE(rwFd);
       }

--- 391,399 ----
                 error = FDH_TRUNC(rwFd, offset);
             }
         }
!       if ( volops_fsync ) {
!         FDH_SYNC(rwFd);
!   }
         FDH_CLOSE(rwFd);
       }

diff -c -r openafs-1.4.2-dist/src/vol/namei_ops.c openafs-1.4.2- 
nofsync/src/vol/namei_ops.c
*** openafs-1.4.2-dist/src/vol/namei_ops.c      Wed Sep 20 01:52:35 2006
--- openafs-1.4.2-nofsync/src/vol/namei_ops.c   Fri Mar 16 11:19:22 2007
***************
*** 76,81 ****
--- 76,83 ----
   #ifndef HAVE_FLOCK
   #include <fcntl.h>

+ int volops_fsync = 1;
+
   /*
    * This function emulates a subset of flock()
    */
***************
*** 1001,1007 ****
       if (write(fdP->fd_fd, (char *)&row, sizeof(row)) != sizeof 
(row)) {
         goto badGetFreeTag;
       }
!     FDH_SYNC(fdP);
       flock(fdP->fd_fd, LOCK_UN);
       FDH_REALLYCLOSE(fdP);
       return col;;
--- 1003,1010 ----
       if (write(fdP->fd_fd, (char *)&row, sizeof(row)) != sizeof 
(row)) {
         goto badGetFreeTag;
       }
!     if ( volops_fsync )
!       FDH_SYNC(fdP);
       flock(fdP->fd_fd, LOCK_UN);
       FDH_REALLYCLOSE(fdP);
       return col;;
***************
*** 1063,1069 ****
         errno = EBADF;
         goto bad_SetLinkCount;
       }
!     FDH_SYNC(fdP);

       code = 0;

--- 1066,1073 ----
         errno = EBADF;
         goto bad_SetLinkCount;
       }
!     if ( volops_fsync )
!       FDH_SYNC(fdP);

       code = 0;

***************
*** 1173,1179 ****
         fclose(fp);
         return -2;
       }
!     if (fsync(fileno(fp)) == -1) {
         Log("Unable to successfully fsync inode file for %s\n",  
mountedOn);
         fclose(fp);
         return -2;
--- 1177,1183 ----
         fclose(fp);
         return -2;
       }
!     if (volops_fsync && (fsync(fileno(fp)) == -1)) {
         Log("Unable to successfully fsync inode file for %s\n",  
mountedOn);
         fclose(fp);
         return -2;
diff -c -r openafs-1.4.2-dist/src/vol/volume.c openafs-1.4.2-nofsync/ 
src/vol/volume.c
*** openafs-1.4.2-dist/src/vol/volume.c Thu Aug 24 16:21:49 2006
--- openafs-1.4.2-nofsync/src/vol/volume.c      Fri Mar 16 10:32:00 2007
***************
*** 181,186 ****
--- 181,192 ----
   static void VReleaseVolumeHandles_r(Volume * vp);
   static void VCloseVolumeHandles_r(Volume * vp);

+ #ifdef AFS_NAMEI_ENV
+ extern int volops_fsync;
+ #else
+ static int volops_fsync = 1;
+ #endif
+
   int LogLevel;                 /* Vice loglevel--not defined as  
extern so that it will be
                                  * defined when not linked with  
vice, XXXX */
   ProgramType programType;      /* The type of program using the  
package */
***************
*** 1550,1556 ****
         int code;
         fdP = IH_OPEN(V_diskDataHandle(vp));
         assert(fdP != NULL);
!       code = FDH_SYNC(fdP);
         assert(code == 0);
         FDH_CLOSE(fdP);
       }
--- 1556,1566 ----
         int code;
         fdP = IH_OPEN(V_diskDataHandle(vp));
         assert(fdP != NULL);
!       if ( volops_fsync ) {
!         code = FDH_SYNC(fdP);
!   } else {
!     code = 0;
!   }
         assert(code == 0);
         FDH_CLOSE(fdP);
       }
diff -c -r openafs-1.4.2-dist/src/volser/volmain.c openafs-1.4.2- 
nofsync/src/volser/volmain.c
*** openafs-1.4.2-dist/src/volser/volmain.c     Sun Sep  3 01:51:42 2006
--- openafs-1.4.2-nofsync/src/volser/volmain.c  Fri Mar 16 10:42:02 2007
***************
*** 97,102 ****
--- 97,106 ----

   int rxBind = 0;

+ #ifdef AFS_NAMEI_ENV
+ extern int volops_fsync;
+ #endif
+
   #define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
   afs_uint32 SHostAddrs[ADDRSPERSITE];

***************
*** 371,376 ****
--- 375,385 ----
         } else if (strcmp(argv[code], "-enable_process_stats") == 0) {
             rx_enableProcessRPCStats();
         }
+ #ifdef AFS_NAMEI_ENV
+   else if ( strcmp(argv[code], "-nofsync") == 0 ) {
+     volops_fsync = 0;
+   }
+ #endif
   #ifndef AFS_NT40_ENV
         else if (strcmp(argv[code], "-syslog") == 0) {
             /* set syslog logging flag */
***************
*** 397,402 ****
--- 406,414 ----
                    "[-nojumbo] [-rxmaxmtu <bytes>] [-rxbind] "
                    "[-udpsize <size of socket buffer in bytes>] "
                    "[-enable_peer_stats] [-enable_process_stats] "
+ #ifdef AFS_NAMEI_ENV
+        "[-nofsync] "
+ #endif
                    "[-help]\n");
   #endif
             VS_EXIT(1);