Browse Source

Use O_DIRECT mode in seqreader

Suren A. Chilingaryan 12 years ago
parent
commit
133aa25923
1 changed files with 12 additions and 4 deletions
  1. 12 4
      seqreader.c

+ 12 - 4
seqreader.c

@@ -11,8 +11,10 @@
 #include <string.h>
 #include <errno.h>
 
-#define BUFSIZE 65536
-#define BLOCK_SIZE 16384
+#define FASTWRITER_SYNCIO_ALIGN 512
+
+#define BUFSIZE 2097152
+#define BLOCK_SIZE 2097152
 #define WRITE_INTERVAL 1
 
 
@@ -29,16 +31,18 @@ int main(int argc, char *argv[]) {
     size_t skip;
     size_t run;
     ssize_t res;
-    char buffer[BUFSIZE];
+    char *buffer;//[BUFSIZE];
     long double mcoef = 1000000. / (1024 * 1024);
     
+    posix_memalign((void**)&buffer, FASTWRITER_SYNCIO_ALIGN, BUFSIZE);
+    
     if (argc < 2) {
 	printf("Usage: %s <directory|device> [skip]\n", argv[0]);
 	exit(0);
     }
     
     if (strstr(argv[1], "/dev/")) {
-	int fd = open(argv[1], O_RDONLY|O_NOATIME|O_LARGEFILE/*|O_DIRECT*/, 0);
+	int fd = open(argv[1], O_RDONLY|O_NOATIME|O_LARGEFILE|O_DIRECT, 0);
 	if (fd < 0) {
 	    printf("Unable to open device %s\n", argv[1]);
 	    exit(1);
@@ -72,6 +76,8 @@ int main(int argc, char *argv[]) {
 	    exit(-1);
 	}
 
+	free(buffer);
+	
 	return 0;
     }
 
@@ -124,5 +130,7 @@ int main(int argc, char *argv[]) {
       }
       closedir(dir);
     }
+    
+    free(buffer);
 
 }