Modifying Samba to skip file system reads for IOZONE READ and REREAD tests

Richard Sharpe rsharpe at richardsharpe.com
Thu Apr 28 00:17:45 GMT 2005


Hi,

In exploring some performance issues I had with highly variable read
performance (difference of 25MB/s between highest and lowest numbers), I
modified Samba to skip file system reads for IOZONE files ...

Attached are the diffs ... in case anyone else wants to do something
similar.

Regards
-----
Richard Sharpe, rsharpe[at]richardsharpe.com, rsharpe[at]samba.org,
sharpe[at]ethereal.com, http://www.richardsharpe.com
-------------- next part --------------
==== //depot/branch/pioneer-mg/src/samba/source/include/smb.h#1 - /usr1/rsharpe/rsharpe-calpc02-pioneer-mg/src/samba/source/include/smb.h ====
@@ -415,6 +415,8 @@
 	BOOL directory_delete_on_close;
 	char *fsp_name;
  	FAKE_FILE_HANDLE *fake_file_handle;
+	BOOL iozone_file;
+	char *buffer;
 #ifdef PANFS_LOCKS
 	SMB_BIG_UINT share_lock_handle; /* Keeps a share lock */
 #endif
==== //depot/branch/pioneer-mg/src/samba/source/smbd/close.c#3 - /usr1/rsharpe/rsharpe-calpc02-pioneer-mg/src/samba/source/smbd/close.c ====
@@ -324,6 +324,8 @@
 	if (fsp->fsp_name)
 		string_free(&fsp->fsp_name);
 
+        if (fsp->iozone_file) SAFE_FREE(fsp->buffer);
+
 	file_free(fsp);
 
 	if (err == -1 || err1 == -1) {
==== //depot/branch/pioneer-mg/src/samba/source/smbd/open.c#4 - /usr1/rsharpe/rsharpe-calpc02-pioneer-mg/src/samba/source/smbd/open.c ====
@@ -327,6 +327,37 @@
 			return False;
 		}
 
+		/* 
+		 * Little hack for IOZONE ... if name is iozone.DUMMY.
+		 * then set a flag and create a buffer for read
+		 */
+                {
+                  const char * slashloc = strrchr(fname, '/');
+                  if (!slashloc) slashloc = fname;
+                  if (strncmp(fname, "iozone.DUMMY.", 13) == 0) {
+                    DEBUG(0, ("IOZONE file detected: %s. Using IOZONE trick.\n",fname));
+                    fsp->iozone_file = True;
+                    fsp->buffer = (char *)malloc(65536);
+                    if (!fsp->buffer) {
+                      DEBUG(0, ("Unable to allocate memory for IOZONE trick. Falling back.\n"));
+                      fsp->iozone_file = False;
+                    }
+                    else {
+                      int i, j;
+                      memset(fsp->buffer, '\0', 65536);
+                      /* set the funny pattern in the buffer */
+                      for (i = 0; i < 65536; i += 32) {
+                        fsp->buffer[i] = 0xA5;
+                      }
+                      for (i = 0; i < 65536; i = i + 4096) {
+                        for (j = 0; j < 8; j++) {
+                          fsp->buffer[i + j] = 0xA5;
+                        }
+                      }
+                    }
+                  }
+                }
+
 		/* Inherit the ACL if the file was created. */
 		if ((local_flags & O_CREAT) && !VALID_STAT(*psbuf))
 			inherit_access_acl(conn, fname, mode);
==== //depot/branch/pioneer-mg/src/samba/source/smbd/reply.c#3 - /usr1/rsharpe/rsharpe-calpc02-pioneer-mg/src/samba/source/smbd/reply.c ====
@@ -2175,6 +2175,11 @@
 
 #endif
 
+        if (fsp->iozone_file) {
+          memcpy(data, fsp->buffer, smb_maxcnt);
+          nread = smb_maxcnt;
+        }
+        else
 	nread = read_file(fsp,data,startpos,smb_maxcnt);
   
 	if (nread < 0) {


More information about the samba-technical mailing list