MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Vadim Tkachenko Date:December 1 2005 12:34pm
Subject:bk commit into 5.1 tree (vtkachenko:1.1998)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of vtkachenko. When vtkachenko does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1998 05/12/01 13:34:48 vtkachenko@stripped +17 -0
  Many files:
    Added mmap support for MyISAM engine

  storage/myisam/myisamdef.h
    1.83 05/12/01 13:34:10 vtkachenko@stripped +12 -0
    Added mmap support for MyISAM engine

  storage/myisam/mi_statrec.c
    1.13 05/12/01 13:34:10 vtkachenko@stripped +11 -12
    Added mmap support for MyISAM engine

  storage/myisam/mi_packrec.c
    1.34 05/12/01 13:34:10 vtkachenko@stripped +6 -15
    Added mmap support for MyISAM engine

  storage/myisam/mi_open.c
    1.97 05/12/01 13:34:10 vtkachenko@stripped +4 -1
    Added mmap support for MyISAM engine

  storage/myisam/mi_locking.c
    1.41 05/12/01 13:34:10 vtkachenko@stripped +9 -1
    Added mmap support for MyISAM engine

  storage/myisam/mi_extra.c
    1.48 05/12/01 13:34:09 vtkachenko@stripped +22 -0
    Added mmap support for MyISAM engine

  storage/myisam/mi_dynrec.c
    1.41 05/12/01 13:34:09 vtkachenko@stripped +175 -7
    Added mmap support for MyISAM engine

  storage/myisam/mi_delete_all.c
    1.18 05/12/01 13:34:09 vtkachenko@stripped +7 -0
    Added mmap support for MyISAM engine

  storage/myisam/mi_close.c
    1.20 05/12/01 13:34:08 vtkachenko@stripped +1 -0
    Added mmap support for MyISAM engine

  sql/set_var.cc
    1.150 05/12/01 13:34:08 vtkachenko@stripped +3 -0
    Added mmap support for MyISAM engine

  sql/records.cc
    1.44 05/12/01 13:34:08 vtkachenko@stripped +4 -0
    Added mmap support for MyISAM engine

  sql/mysqld.cc
    1.496 05/12/01 13:34:08 vtkachenko@stripped +7 -0
    Added mmap support for MyISAM engine

  sql/mysql_priv.h
    1.349 05/12/01 13:34:08 vtkachenko@stripped +1 -1
    Added mmap support for MyISAM engine

  sql/ha_myisam.cc
    1.163 05/12/01 13:34:08 vtkachenko@stripped +4 -0
    Added mmap support for MyISAM engine

  include/my_sys.h
    1.178 05/12/01 13:34:08 vtkachenko@stripped +4 -0
    Added mmap support for MyISAM engine

  include/my_base.h
    1.75 05/12/01 13:34:08 vtkachenko@stripped +2 -1
    Added mmap support for MyISAM engine

  configure.in
    1.314 05/12/01 13:34:08 vtkachenko@stripped +1 -1
    Added mmap support for MyISAM engine

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	vtkachenko
# Host:	quadxeon.mysql.com
# Root:	/benchmarks/ext3/BUILDS/mysql-5.1-new

--- 1.313/configure.in	2005-11-24 14:23:10 +01:00
+++ 1.314/configure.in	2005-12-01 13:34:08 +01:00
@@ -1819,7 +1819,7 @@
   getcwd gethostbyaddr_r gethostbyname_r getpass getpassphrase getpwnam \
   getpwuid getrlimit getrusage getwd gmtime_r index initgroups isnan \
   localtime_r locking longjmp lrand48 madvise mallinfo memcpy memmove \
-  mkstemp mlockall perror poll pread pthread_attr_create mmap getpagesize \
+  mkstemp mlockall perror poll pread pthread_attr_create mmap mmap64 getpagesize \
   pthread_attr_getstacksize pthread_attr_setprio pthread_attr_setschedparam \
   pthread_attr_setstacksize pthread_condattr_create pthread_getsequence_np \
   pthread_key_delete pthread_rwlock_rdlock pthread_setprio \

--- 1.74/include/my_base.h	2005-11-28 20:07:09 +01:00
+++ 1.75/include/my_base.h	2005-12-01 13:34:08 +01:00
@@ -152,7 +152,8 @@
     other fields intact. When this is off (by default) InnoDB will use memcpy
     to overwrite entire row.
   */
-  HA_EXTRA_KEYREAD_PRESERVE_FIELDS
+  HA_EXTRA_KEYREAD_PRESERVE_FIELDS,
+  HA_EXTRA_MMAP
 };
 
 	/* The following is parameter to ha_panic() */

--- 1.177/include/my_sys.h	2005-11-21 15:36:57 +01:00
+++ 1.178/include/my_sys.h	2005-12-01 13:34:08 +01:00
@@ -821,7 +821,11 @@
 #define MAP_NOSYNC      0
 #endif
 
+#ifdef HAVE_MMAP64
+#define my_mmap(a,b,c,d,e,f)    mmap64(a,b,c,d,e,f)
+#else
 #define my_mmap(a,b,c,d,e,f)    mmap(a,b,c,d,e,f)
+#endif
 #ifdef HAVE_GETPAGESIZE
 #define my_getpagesize()        getpagesize()
 #else

--- 1.19/storage/myisam/mi_close.c	2005-04-08 00:54:34 +02:00
+++ 1.20/storage/myisam/mi_close.c	2005-12-01 13:34:08 +01:00
@@ -96,6 +96,7 @@
     {
       int i,keys;
       keys = share->state.header.keys;
+      VOID(rwlock_destroy(&share->mmap_lock));
       for(i=0; i<keys; i++) {
 	VOID(rwlock_destroy(&share->key_root_lock[i]));
       }

--- 1.17/storage/myisam/mi_delete_all.c	2005-10-06 10:26:05 +02:00
+++ 1.18/storage/myisam/mi_delete_all.c	2005-12-01 13:34:09 +01:00
@@ -22,6 +22,7 @@
 int mi_delete_all_rows(MI_INFO *info)
 {
   uint i;
+  char buf[22];
   MYISAM_SHARE *share=info->s;
   MI_STATE_INFO *state=&share->state;
   DBUG_ENTER("mi_delete_all_rows");
@@ -58,6 +59,12 @@
       my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME))  )
     goto err;
   VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
+#ifdef HAVE_MMAP
+  /* Resize mmaped area */
+  rw_wrlock(&info->s->mmap_lock);
+  mi_remap_file(info, (my_off_t)0);
+  rw_unlock(&info->s->mmap_lock);
+#endif
   allow_break();			/* Allow SIGHUP & SIGINT */
   DBUG_RETURN(0);
 

--- 1.40/storage/myisam/mi_dynrec.c	2005-05-17 10:10:42 +02:00
+++ 1.41/storage/myisam/mi_dynrec.c	2005-12-01 13:34:09 +01:00
@@ -50,6 +50,174 @@
 
 	/* Interface function from MI_INFO */
 
+#ifdef HAVE_MMAP
+
+/*
+  Create mmaped area for MyISAM handler
+
+  SYNOPSIS
+    mi_dynmap_file()
+    info		MyISAM handler
+
+  RETURN
+    0  ok
+    1  error.
+*/
+
+my_bool mi_dynmap_file(MI_INFO *info, my_off_t size)
+{
+  DBUG_ENTER("mi_dynmap_file");
+  info->s->file_map= (byte*)
+                  my_mmap(0, (size_t)(size + MEMMAP_EXTRA_MARGIN),
+                          info->s->mode==O_RDONLY ? PROT_READ :
+                          PROT_READ | PROT_WRITE,
+                          MAP_SHARED | MAP_NORESERVE,
+                          info->dfile, 0L);
+  if (info->s->file_map == (byte*) MAP_FAILED)
+  {
+    info->s->file_map= NULL;
+    DBUG_RETURN(1);
+  }
+#if defined(HAVE_MADVISE)
+  madvise(info->s->file_map, size, MADV_RANDOM);
+#endif
+  info->s->mmaped_length= size;
+  DBUG_RETURN(0);
+}
+
+
+/*
+  Resize mmaped area for MyISAM handler
+
+  SYNOPSIS
+    mi_remap_file()
+    info		MyISAM handler
+
+  RETURN
+*/
+
+void mi_remap_file(MI_INFO *info, my_off_t size)
+{
+  if (info->s->file_map)
+  {
+    VOID(my_munmap(info->s->file_map,
+                   (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN));
+    mi_dynmap_file(info, size);
+  }
+}
+#endif
+
+
+/*
+  Read bytes from MySAM handler, using mmap or pread
+
+  SYNOPSIS
+    mi_mmap_pread()
+    info		MyISAM handler
+    Buffer              Input buffer
+    Count               Count of bytes for read
+    offset              Start position
+    MyFlags             
+
+  RETURN
+    0  ok
+*/
+
+uint mi_mmap_pread(MI_INFO *info, byte *Buffer,
+                    uint Count, my_off_t offset, myf MyFlags)
+{
+  DBUG_PRINT("info", ("mi_read with mmap %d\n", info->dfile));
+  if (info->s->concurrent_insert)
+    rw_rdlock(&info->s->mmap_lock);
+
+  /*
+    The following test may fail in the following cases:
+    - We failed to remap a memory area (fragmented memory?)
+    - This thread has done some writes, but not yet extended the
+    memory mapped area.
+  */
+
+  if (info->s->mmaped_length >= offset + Count)
+  {
+    memcpy(Buffer, info->s->file_map + offset, Count);
+    if (info->s->concurrent_insert)
+      rw_unlock(&info->s->mmap_lock);
+    return 0;
+  }
+  else
+  {
+    if (info->s->concurrent_insert)
+      rw_unlock(&info->s->mmap_lock);
+    return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
+  }
+}
+
+
+        /* wrapper for my_pread in case if mmap isn't used */
+
+uint mi_nommap_pread(MI_INFO *info, byte *Buffer,
+                      uint Count, my_off_t offset, myf MyFlags)
+{
+  return my_pread(info->dfile, Buffer, Count, offset, MyFlags);
+}
+
+
+/*
+  Write bytes to MySAM handler, using mmap or pwrite
+
+  SYNOPSIS
+    mi_mmap_pwrite()
+    info		MyISAM handler
+    Buffer              Output buffer
+    Count               Count of bytes for write
+    offset              Start position
+    MyFlags             
+
+  RETURN
+    0  ok
+    !=0  error.  In this case return error from pwrite
+*/
+
+uint mi_mmap_pwrite(MI_INFO *info, byte *Buffer,
+                     uint Count, my_off_t offset, myf MyFlags)
+{
+  DBUG_PRINT("info", ("mi_write with mmap %d\n", info->dfile));
+  if (info->s->concurrent_insert)
+    rw_rdlock(&info->s->mmap_lock);
+
+  /*
+    The following test may fail in the following cases:
+    - We failed to remap a memory area (fragmented memory?)
+    - This thread has done some writes, but not yet extended the
+    memory mapped area.
+  */
+
+  if (info->s->mmaped_length >= offset + Count)
+  {
+    memcpy(info->s->file_map + offset, Buffer, Count); 
+    if (info->s->concurrent_insert)
+      rw_unlock(&info->s->mmap_lock);
+    return 0;
+  }
+  else
+  {
+    if (info->s->concurrent_insert)
+      rw_unlock(&info->s->mmap_lock);
+    return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
+  }
+
+}
+
+
+        /* wrapper for my_pwrite in case if mmap isn't used */
+
+uint mi_nommap_pwrite(MI_INFO *info, byte *Buffer,
+                      uint Count, my_off_t offset, myf MyFlags)
+{
+  return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
+}
+
+
 int _mi_write_dynamic_record(MI_INFO *info, const byte *record)
 {
   ulong reclength=_mi_rec_pack(info,info->rec_buff,record);
@@ -243,7 +411,7 @@
 	  & BLOCK_DELETED))
       DBUG_RETURN(1);				/* Something is wrong */
     mi_sizestore(tmp.header+4,block_info->next_filepos);
-    if (my_pwrite(info->dfile,(char*) tmp.header+4,8,
+    if (info->s->file_write(info,(char*) tmp.header+4,8,
 		  block_info->prev_filepos+4, MYF(MY_NABP)))
       DBUG_RETURN(1);
     /* Unlink block from next block */
@@ -253,7 +421,7 @@
 	    & BLOCK_DELETED))
 	DBUG_RETURN(1);				/* Something is wrong */
       mi_sizestore(tmp.header+12,block_info->prev_filepos);
-      if (my_pwrite(info->dfile,(char*) tmp.header+12,8,
+      if (info->s->file_write(info,(char*) tmp.header+12,8,
 		    block_info->next_filepos+12,
 		    MYF(MY_NABP)))
 	DBUG_RETURN(1);
@@ -304,7 +472,7 @@
     {
       char buff[8];
       mi_sizestore(buff,filepos);
-      if (my_pwrite(info->dfile,buff, 8, delete_block+12, MYF(MY_NABP)))
+      if (info->s->file_write(info,buff, 8, delete_block+12, MYF(MY_NABP)))
 	DBUG_RETURN(1);				/* Error on write */
     }
     else
@@ -362,7 +530,7 @@
       bfill(block_info.header+12,8,255);
     else
       mi_sizestore(block_info.header+12,block_info.next_filepos);
-    if (my_pwrite(info->dfile,(byte*) block_info.header,20,filepos,
+    if (info->s->file_write(info,(byte*) block_info.header,20,filepos,
 		  MYF(MY_NABP)))
       DBUG_RETURN(1);
     info->s->state.dellink = filepos;
@@ -545,7 +713,7 @@
   else
   {
     info->rec_cache.seek_not_done=1;
-    if (my_pwrite(info->dfile,(byte*) *record-head_length,length+extra_length+
+    if (info->s->file_write(info,(byte*) *record-head_length,length+extra_length+
 		  del_length,filepos,info->s->write_flag))
       goto err;
   }
@@ -655,7 +823,7 @@
 	      mi_int3store(del_block.header+1, rest_length);
 	      mi_sizestore(del_block.header+4,info->s->state.dellink);
 	      bfill(del_block.header+12,8,255);
-	      if (my_pwrite(info->dfile,(byte*) del_block.header,20, next_pos,
+	      if (info->s->file_write(info,(byte*) del_block.header,20, next_pos,
 			    MYF(MY_NABP)))
 		DBUG_RETURN(1);
 	      info->s->state.dellink= next_pos;
@@ -1182,7 +1350,7 @@
       }
       if (left_length < block_info.data_len || ! block_info.data_len)
 	goto panic;			/* Wrong linked record */
-      if (my_pread(file,(byte*) to,block_info.data_len,block_info.filepos,
+      if (info->s->file_read(info,(byte*) to,block_info.data_len,block_info.filepos,
 		   MYF(MY_NABP)))
 	goto panic;
       left_length-=block_info.data_len;

--- 1.47/storage/myisam/mi_extra.c	2005-09-02 08:42:57 +02:00
+++ 1.48/storage/myisam/mi_extra.c	2005-12-01 13:34:09 +01:00
@@ -93,6 +93,8 @@
       my_errno=EACCES;
       break;
     }
+    if (info->s->file_map) /* Don't use cache if mmap */
+      break;
 #if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
     if ((share->options & HA_OPTION_COMPRESS_RECORD))
     {
@@ -150,6 +152,7 @@
       error=1;			/* Not possibly if not locked */
       break;
     }
+
     cache_size= (extra_arg ? *(ulong*) extra_arg :
 		 my_default_record_cache_size);
     if (!(info->opt_flag &
@@ -366,6 +369,25 @@
   case HA_EXTRA_CHANGE_KEY_TO_UNIQUE:
   case HA_EXTRA_CHANGE_KEY_TO_DUP:
     mi_extra_keyflag(info, function);
+    break;
+  case HA_EXTRA_MMAP:
+#ifdef HAVE_MMAP
+    pthread_mutex_lock(&share->intern_lock);
+    if (!share->file_map)
+    {
+      if (mi_dynmap_file(info, share->state.state.data_file_length))
+      {
+        DBUG_PRINT("warning",("mmap failed: errno: %d",errno));
+        error= my_errno= errno;
+      }
+      else
+      {
+        share->file_read= mi_mmap_pread;
+        share->file_write= mi_mmap_pwrite;
+      }
+    }
+    pthread_mutex_unlock(&share->intern_lock);
+#endif
     break;
   case HA_EXTRA_KEY_CACHE:
   case HA_EXTRA_NO_KEY_CACHE:

--- 1.40/storage/myisam/mi_locking.c	2005-05-17 10:10:42 +02:00
+++ 1.41/storage/myisam/mi_locking.c	2005-12-01 13:34:10 +01:00
@@ -38,7 +38,6 @@
                       share->w_locks,
                       share->global_changed, share->state.open_count,
                       share->index_file_name));
-
   if (share->options & HA_OPTION_READ_ONLY_DATA ||
       info->lock_type == lock_type)
     DBUG_RETURN(0);
@@ -84,6 +83,14 @@
 			   (uint) share->changed, share->w_locks));
 	if (share->changed && !share->w_locks)
 	{
+          if (info->s->mmaped_length != info->s->state.state.data_file_length)
+          {
+            if (info->s->concurrent_insert)
+              rw_wrlock(&info->s->mmap_lock);
+            mi_remap_file(info, info->s->state.state.data_file_length);
+            if (info->s->concurrent_insert)
+              rw_unlock(&info->s->mmap_lock);
+          }
 	  share->state.process= share->last_process=share->this_process;
 	  share->state.unique=   info->last_unique=  info->this_unique;
 	  share->state.update_count= info->last_loop= ++info->this_loop;
@@ -215,6 +222,7 @@
 	}
       }
       VOID(_mi_test_if_changed(info));
+        
       info->lock_type=lock_type;
       info->invalidator=info->s->invalidator;
       share->w_locks++;

--- 1.96/storage/myisam/mi_open.c	2005-11-06 13:12:52 +01:00
+++ 1.97/storage/myisam/mi_open.c	2005-12-01 13:34:10 +01:00
@@ -288,6 +288,7 @@
 #ifdef THREAD
 			 &share->key_root_lock,sizeof(rw_lock_t)*keys,
 #endif
+			 &share->mmap_lock,sizeof(rw_lock_t),
 			 NullS))
       goto err;
     errpos=4;
@@ -459,7 +460,6 @@
 					(keys ? MI_INDEX_BLOCK_MARGIN *
 					 share->blocksize * keys : 0));
     share->blocksize=min(IO_SIZE,myisam_block_size);
-
     share->data_file_type=STATIC_RECORD;
     if (share->options & HA_OPTION_COMPRESS_RECORD)
     {
@@ -482,6 +482,7 @@
     VOID(pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST));
     for (i=0; i<keys; i++)
       VOID(my_rwlock_init(&share->key_root_lock[i], NULL));
+    VOID(my_rwlock_init(&share->mmap_lock, NULL));
     if (!thr_lock_inited)
     {
       /* Probably a single threaded program; Don't use concurrent inserts */
@@ -736,6 +737,8 @@
     share->compare_unique=_mi_cmp_static_unique;
     share->calc_checksum= mi_static_checksum;
   }
+  share->file_read= mi_nommap_pread;
+  share->file_write= mi_nommap_pwrite;
   if (!(share->options & HA_OPTION_CHECKSUM))
     share->calc_checksum=0;
   return;

--- 1.33/storage/myisam/mi_packrec.c	2005-09-06 09:11:52 +02:00
+++ 1.34/storage/myisam/mi_packrec.c	2005-12-01 13:34:10 +01:00
@@ -1192,34 +1192,25 @@
   if (!info->s->file_map)
   {
     if (my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)) <
-	share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN)
+        share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN)
     {
       DBUG_PRINT("warning",("File isn't extended for memmap"));
       DBUG_RETURN(0);
     }
-    file_map=(byte*)
-      my_mmap(0,(size_t)(share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN),PROT_READ,
-	   MAP_SHARED | MAP_NORESERVE,info->dfile,0L);
-    if (file_map == (byte*) MAP_FAILED)
-    {
-      DBUG_PRINT("warning",("mmap failed: errno: %d",errno));
-      my_errno=errno;
+    if (mi_dynmap_file(info, share->state.state.data_file_length))
       DBUG_RETURN(0);
-    }
-    info->s->file_map=file_map;
   }
   info->opt_flag|= MEMMAP_USED;
-  info->read_record=share->read_record=_mi_read_mempack_record;
-  share->read_rnd=_mi_read_rnd_mempack_record;
+  info->read_record= share->read_record= _mi_read_mempack_record;
+  share->read_rnd= _mi_read_rnd_mempack_record;
   DBUG_RETURN(1);
 }
 
 
 void _mi_unmap_file(MI_INFO *info)
 {
-  VOID(my_munmap(info->s->file_map,
-	      (size_t) info->s->state.state.data_file_length+
-	      MEMMAP_EXTRA_MARGIN));
+  VOID(my_munmap(info->s->file_map, 
+                 (size_t) info->s->mmaped_length + MEMMAP_EXTRA_MARGIN));
 }
 
 

--- 1.12/storage/myisam/mi_statrec.c	2005-05-17 10:10:42 +02:00
+++ 1.13/storage/myisam/mi_statrec.c	2005-12-01 13:34:10 +01:00
@@ -22,20 +22,19 @@
 int _mi_write_static_record(MI_INFO *info, const byte *record)
 {
   uchar temp[8];				/* max pointer length */
-
   if (info->s->state.dellink != HA_OFFSET_ERROR &&
       !info->append_insert_at_end)
   {
     my_off_t filepos=info->s->state.dellink;
     info->rec_cache.seek_not_done=1;		/* We have done a seek */
-    if (my_pread(info->dfile,(char*) &temp[0],info->s->base.rec_reflength,
+    if (info->s->file_read(info,(char*) &temp[0],info->s->base.rec_reflength,
 		info->s->state.dellink+1,
 		 MYF(MY_NABP)))
       goto err;
     info->s->state.dellink= _mi_rec_pos(info->s,temp);
     info->state->del--;
     info->state->empty-=info->s->base.pack_reclength;
-    if (my_pwrite(info->dfile, (char*) record, info->s->base.reclength,
+    if (info->s->file_write(info, (char*) record, info->s->base.reclength,
 		  filepos,
 		  MYF(MY_NABP)))
       goto err;
@@ -64,19 +63,19 @@
     else
     {
       info->rec_cache.seek_not_done=1;		/* We have done a seek */
-      if (my_pwrite(info->dfile,(char*) record,info->s->base.reclength,
+      if (info->s->file_write(info,(char*) record,info->s->base.reclength,
 		    info->state->data_file_length,
 		    info->s->write_flag))
-	goto err;
+        goto err;
       if (info->s->base.pack_reclength != info->s->base.reclength)
       {
 	uint length=info->s->base.pack_reclength - info->s->base.reclength;
 	bzero((char*) temp,length);
-	if (my_pwrite(info->dfile, (byte*) temp,length,
+	if (info->s->file_write(info, (byte*) temp,length,
 		      info->state->data_file_length+
 		      info->s->base.reclength,
 		      info->s->write_flag))
-	  goto err;
+    goto err;
       }
     }
     info->state->data_file_length+=info->s->base.pack_reclength;
@@ -90,7 +89,7 @@
 int _mi_update_static_record(MI_INFO *info, my_off_t pos, const byte *record)
 {
   info->rec_cache.seek_not_done=1;		/* We have done a seek */
-  return (my_pwrite(info->dfile,
+  return (info->s->file_write(info,
 		    (char*) record,info->s->base.reclength,
 		    pos,
 		    MYF(MY_NABP)) != 0);
@@ -107,7 +106,7 @@
   _mi_dpointer(info,temp+1,info->s->state.dellink);
   info->s->state.dellink = info->lastpos;
   info->rec_cache.seek_not_done=1;
-  return (my_pwrite(info->dfile,(byte*) temp, 1+info->s->rec_reflength,
+  return (info->s->file_write(info,(byte*) temp, 1+info->s->rec_reflength,
 		    info->lastpos, MYF(MY_NABP)) != 0);
 }
 
@@ -131,7 +130,7 @@
   if ((info->opt_flag & READ_CHECK_USED))
   {						/* If check isn't disabled  */
     info->rec_cache.seek_not_done=1;		/* We have done a seek */
-    if (my_pread(info->dfile, (char*) info->rec_buff, info->s->base.reclength,
+    if (info->s->file_read(info, (char*) info->rec_buff, info->s->base.reclength,
 		 info->lastpos,
 		 MYF(MY_NABP)))
       DBUG_RETURN(-1);
@@ -154,7 +153,7 @@
   DBUG_ENTER("_mi_cmp_static_unique");
 
   info->rec_cache.seek_not_done=1;		/* We have done a seek */
-  if (my_pread(info->dfile, (char*) info->rec_buff, info->s->base.reclength,
+  if (info->s->file_read(info, (char*) info->rec_buff, info->s->base.reclength,
 	       pos, MYF(MY_NABP)))
     DBUG_RETURN(-1);
   DBUG_RETURN(mi_unique_comp(def, record, info->rec_buff,
@@ -180,7 +179,7 @@
       return(-1);
     info->rec_cache.seek_not_done=1;		/* We have done a seek */
 
-    error=my_pread(info->dfile,(char*) record,info->s->base.reclength,
+    error=info->s->file_read(info,(char*) record,info->s->base.reclength,
 		   pos,MYF(MY_NABP)) != 0;
     fast_mi_writeinfo(info);
     if (! error)

--- 1.82/storage/myisam/myisamdef.h	2005-11-04 21:09:58 +01:00
+++ 1.83/storage/myisam/myisamdef.h	2005-12-01 13:34:10 +01:00
@@ -179,6 +179,8 @@
   ha_checksum (*calc_checksum)(struct st_myisam_info*, const byte *);
   int (*compare_unique)(struct st_myisam_info*, MI_UNIQUEDEF *,
 			const byte *record, my_off_t pos);
+  uint (*file_read)(MI_INFO *, byte *, uint, my_off_t, myf);
+  uint (*file_write)(MI_INFO *, byte *, uint, my_off_t, myf);
   invalidator_by_filename invalidator;  /* query cache invalidator */
   ulong this_process;			/* processid */
   ulong last_process;			/* For table-change-check */
@@ -207,6 +209,8 @@
   pthread_mutex_t intern_lock;		/* Locking for use with _locking */
   rw_lock_t *key_root_lock;
 #endif
+  my_off_t mmaped_length;
+  rw_lock_t mmap_lock;
 } MYISAM_SHARE;
 
 
@@ -685,6 +689,14 @@
 extern uint save_pack_length(uint version, byte *block_buff, ulong length);
 extern uint read_pack_length(uint version, const uchar *buf, ulong *length);
 extern uint calc_pack_length(uint version, ulong length);
+extern uint mi_mmap_pread(MI_INFO *info, byte *Buffer,
+                           uint Count, my_off_t offset, myf MyFlags);
+extern uint mi_mmap_pwrite(MI_INFO *info, byte *Buffer,
+                            uint Count, my_off_t offset, myf MyFlags);
+extern uint mi_nommap_pread(MI_INFO *info, byte *Buffer,
+                             uint Count, my_off_t offset, myf MyFlags);
+extern uint mi_nommap_pwrite(MI_INFO *info, byte *Buffer,
+                             uint Count, my_off_t offset, myf MyFlags);
 
 uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite);
 uchar *mi_state_info_read(uchar *ptr, MI_STATE_INFO *state);

--- 1.162/sql/ha_myisam.cc	2005-11-23 21:44:55 +01:00
+++ 1.163/sql/ha_myisam.cc	2005-12-01 13:34:08 +01:00
@@ -304,6 +304,10 @@
   
   if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE))
     VOID(mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0));
+
+  if (!(test_if_locked & HA_OPEN_TMP_TABLE) && opt_myisam_use_mmap)
+    VOID(mi_extra(file, HA_EXTRA_MMAP, 0));
+
   info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
   if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
     VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0));

--- 1.348/sql/mysql_priv.h	2005-11-30 22:43:49 +01:00
+++ 1.349/sql/mysql_priv.h	2005-12-01 13:34:08 +01:00
@@ -1215,7 +1215,7 @@
 extern bool mysql_proc_table_exists;
 extern uint volatile thread_count, thread_running, global_read_lock;
 extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
-extern my_bool opt_safe_show_db, opt_local_infile;
+extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
 extern my_bool opt_slave_compressed_protocol, use_temp_pool;
 extern my_bool opt_readonly, lower_case_file_system;
 extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;

--- 1.495/sql/mysqld.cc	2005-11-30 22:43:49 +01:00
+++ 1.496/sql/mysqld.cc	2005-12-01 13:34:08 +01:00
@@ -428,6 +428,7 @@
 my_bool opt_log_slow_admin_statements= 0;
 my_bool lower_case_file_system= 0;
 my_bool opt_large_pages= 0;
+my_bool opt_myisam_use_mmap= 0;
 uint    opt_large_page_size= 0;
 my_bool opt_old_style_user_limits= 0, trust_function_creators= 0;
 /*
@@ -4558,6 +4559,7 @@
   OPT_MAX_ERROR_COUNT, OPT_MULTI_RANGE_COUNT, OPT_MYISAM_DATA_POINTER_SIZE,
   OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
   OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE,
+  OPT_MYISAM_USE_MMAP,
   OPT_MYISAM_STATS_METHOD,
   OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT,
   OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT,
@@ -5767,6 +5769,11 @@
    (gptr*) &global_system_variables.myisam_sort_buff_size,
    (gptr*) &max_system_variables.myisam_sort_buff_size, 0,
    GET_ULONG, REQUIRED_ARG, 8192*1024, 4, ~0L, 0, 1, 0},
+  {"myisam_use_mmap", OPT_MYISAM_USE_MMAP,
+   "Use memory mapping for read/write MyISAM tables",
+   (gptr*) &opt_myisam_use_mmap,
+   (gptr*) &opt_myisam_use_mmap, 0, GET_BOOL, NO_ARG, 0, 
+    0, 0, 0, 0, 0},
   {"myisam_stats_method", OPT_MYISAM_STATS_METHOD,
    "Specifies how MyISAM index statistics collection code should threat NULLs. "
    "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), "

--- 1.43/sql/records.cc	2005-11-05 12:20:31 +01:00
+++ 1.44/sql/records.cc	2005-12-01 13:34:08 +01:00
@@ -153,6 +153,10 @@
   info->table=table;
   info->file= table->file;
   info->forms= &info->table;		/* Only one table */
+  
+  if (table->s->tmp_table == TMP_TABLE && !table->sort.addon_field)
+    VOID(table->file->extra(HA_EXTRA_MMAP));
+  
   if (table->sort.addon_field)
   {
     info->rec_buf= table->sort.addon_buf;

--- 1.149/sql/set_var.cc	2005-11-26 05:20:46 +01:00
+++ 1.150/sql/set_var.cc	2005-12-01 13:34:08 +01:00
@@ -314,6 +314,8 @@
 sys_var_thd_ulonglong	sys_myisam_max_sort_file_size("myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
 sys_var_thd_ulong       sys_myisam_repair_threads("myisam_repair_threads", &SV::myisam_repair_threads);
 sys_var_thd_ulong	sys_myisam_sort_buffer_size("myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
+sys_var_bool_ptr	sys_myisam_use_mmap("myisam_use_mmap", 
+                                            &opt_myisam_use_mmap);
 
 sys_var_thd_enum        sys_myisam_stats_method("myisam_stats_method",
                                                 &SV::myisam_stats_method,
@@ -789,6 +791,7 @@
   {sys_myisam_repair_threads.name, (char*) &sys_myisam_repair_threads,
    SHOW_SYS},
   {sys_myisam_sort_buffer_size.name, (char*) &sys_myisam_sort_buffer_size, SHOW_SYS},
+  {sys_myisam_use_mmap.name, (char*) &sys_myisam_use_mmap, SHOW_SYS},
   
   {sys_myisam_stats_method.name, (char*) &sys_myisam_stats_method, SHOW_SYS},
   
Thread
bk commit into 5.1 tree (vtkachenko:1.1998)Vadim Tkachenko1 Dec