Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

[patch 7/8] WL4081 Allow use of direct IO (O_DIRECT) with azio

From: <stewart(at)mysql.com>
Date: Thu Oct 11 2007 - 04:45:48 EDT


Change azio to either posix_memalign allocate in and out buffers OR allow user to allocate these. Flag in azio_stream should be where padding was so no additional memory used.

This enables O_DIRECT usage with azio if aligned buffers are allocated (by default, the azio allocation - posix_memalign - does this).

Index: telco-6.2/storage/ndb/include/util/azlib.h


  • telco-6.2.orig/storage/ndb/include/util/azlib.h 2007-10-11 17:01:34.509692276 +1000 +++ telco-6.2/storage/ndb/include/util/azlib.h 2007-10-11 17:01:42.134066225 +1000
    @@ -199,18 +199,18 @@ extern "C" {
    #define AZ_BUFSIZE_READ 32768 #define AZ_BUFSIZE_WRITE 16384

-
 typedef struct azio_stream {
   z_stream stream;

   int      z_err;   /* error code for last stream operation */
   int      z_eof;   /* set if end of input file */
   File     file;   /* .gz file */
-  Byte     inbuf[AZ_BUFSIZE_READ];  /* input buffer */
-  Byte     outbuf[AZ_BUFSIZE_WRITE]; /* output buffer */
+  Byte     *inbuf;  /* input buffer */
+  Byte     *outbuf; /* output buffer */
   uLong    crc;     /* crc32 of uncompressed data */
   char     *msg;    /* error message */
   int      transparent; /* 1 if input file is not a .gz file */
   char     mode;    /* 'w' or 'r' */
+  char     bufalloced; /* true if azio allocated buffers */
   my_off_t  start;   /* start of compressed data in file (header skipped) */
   my_off_t  in;      /* bytes into deflate or inflate */
   my_off_t  out;     /* bytes out of deflate or inflate */

@@ -233,7 +233,6 @@ typedef struct azio_stream {
 } azio_stream;  
                         /* basic functions */
-
 extern int azopen(azio_stream *s, const char *path, int Flags);  /*

      Opens a gzip (.gz) file for reading or writing. The mode parameter Index: telco-6.2/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.cpp


  • telco-6.2.orig/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.cpp 2007-10-11 17:01:35.277729945 +1000 +++ telco-6.2/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.cpp 2007-10-11 17:01:42.138066422 +1000
    @@ -172,6 +172,15 @@ AsyncFile::run()
    (((UintPtr)theWriteBufferUnaligned + NDB_O_DIRECT_WRITE_ALIGNMENT - 1) & ~(UintPtr)(NDB_O_DIRECT_WRITE_ALIGNMENT - 1));
+  azfBufferUnaligned= (Byte*)ndbd_malloc((AZ_BUFSIZE_READ+AZ_BUFSIZE_WRITE)
+                                         +NDB_O_DIRECT_WRITE_ALIGNMENT-1);
+
+  azf.inbuf= (Byte*)(((UintPtr)azfBufferUnaligned
+                      + NDB_O_DIRECT_WRITE_ALIGNMENT - 1) &
+                     ~(UintPtr)(NDB_O_DIRECT_WRITE_ALIGNMENT - 1));
+
+  azf.outbuf= azf.inbuf + AZ_BUFSIZE_READ;
+

   NdbMutex_Unlock(theStartMutexPtr);
   NdbCondition_Signal(theStartConditionPtr);    

@@ -1024,7 +1033,13 @@ AsyncFile::closeReq(Request * request)

   else
     ::close(theFd);
   use_gz= 0;

+  Byte *a,*b;
+  a= azf.inbuf;
+  b= azf.outbuf;
Do you need help?X

   memset(&azf,0,sizeof(azf));

+  azf.inbuf= a;
+  azf.outbuf= b;
+

   if (-1 == r) {
 #ifndef DBUG_OFF

     if (theFd == -1) {
@@ -1225,6 +1240,10 @@ void AsyncFile::endReq()

   // Thread is ended with return
   if (theWriteBufferUnaligned)
     ndbd_free(theWriteBufferUnaligned, theWriteBufferSize);

+
+  if (azfBufferUnaligned)
+    ndbd_free(azfBufferUnaligned, (AZ_BUFSIZE_READ*AZ_BUFSIZE_WRITE)
+              +NDB_O_DIRECT_WRITE_ALIGNMENT-1);
 }    

Index: telco-6.2/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp


  • telco-6.2.orig/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp 2007-10-11 17:01:34.629698162 +1000 +++ telco-6.2/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp 2007-10-11 17:01:42.734095655 +1000
    @@ -242,6 +242,7 @@ private:
    int theWriteBufferSize; char* theWriteBuffer; void* theWriteBufferUnaligned; + void* azfBufferUnaligned;
   size_t m_write_wo_sync;  // Writes wo/ sync
   size_t m_auto_sync_freq; // Auto sync freq in bytes
Index: telco-6.2/storage/ndb/src/common/util/azio.c
===================================================================
--- telco-6.2.orig/storage/ndb/src/common/util/azio.c	2007-10-11 17:01:35.313731711 +1000
Do you need more help?X
+++ telco-6.2/storage/ndb/src/common/util/azio.c 2007-10-11 17:01:42.798098794 +1000

@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 

 static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */  static int const az_magic[3] = {0xfe, 0x03, 0x01}; /* az magic header */
@@ -55,6 +56,17 @@ int az_open (azio_stream *s, const char

   s->stream.zalloc = (alloc_func)0;
   s->stream.zfree = (free_func)0;
   s->stream.opaque = (voidpf)0;
+  s->bufalloced = 0;
+  if(!s->inbuf)
+  {
+    err= posix_memalign(&(s->inbuf),512,AZ_BUFSIZE_READ);
+    if(err)
+      return err;
+    err= posix_memalign(&(s->outbuf),512,AZ_BUFSIZE_WRITE);
+    if(err)
+      return err;

+ s->bufalloced = 1;
+ }

   memset(s->inbuf, 0, AZ_BUFSIZE_READ);    memset(s->outbuf, 0, AZ_BUFSIZE_WRITE);    s->stream.next_in = s->inbuf;
@@ -378,6 +390,12 @@ int destroy (s)
 

   if (s->z_err < 0) err = s->z_err;  

+  if(s->bufalloced)
+  {
+    free(s->inbuf);
+    free(s->outbuf);
+  }
+
Can we help you?X

   return err;
 }  

--
Stewart Smith

-- 
MySQL Code Commits Mailing List
For list archives: 
http://lists.mysql.com/commits
To unsubscribe:    
http://lists.mysql.com/commits?unsub=lists@pantek.com
Received on Thu Oct 11 09:22:29 2007

This archive was generated by hypermail 2.1.8 : Thu Jul 03 2008 - 09:43:35 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library