]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Use heap instead of stack for large buffers in the pager. Fix for #2262. (CVS 3673)
authordanielk1977 <danielk1977@noemail.net>
Tue, 6 Mar 2007 13:45:59 +0000 (13:45 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Tue, 6 Mar 2007 13:45:59 +0000 (13:45 +0000)
FossilOrigin-Name: dfe1dffa4515ed6494055887d351863fe0cdb87f

manifest
manifest.uuid
src/pager.c

index 5eaf6690f5b366c0a5384bb175cf11e21c6db1d9..c3b8675253ba078dbeee0641d12ef84cf8e55a5f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Do\snot\sread\sthe\slast\spage\sof\sa\soverflow\schain\swhen\sdeleting\sthat\schain.\r\nJust\sadd\sthe\spage\sto\sthe\sfreelist.\s\sThis\sreduces\sI/O.\s(CVS\s3672)
-D 2007-03-06T11:42:19
+C Use\sheap\sinstead\sof\sstack\sfor\slarge\sbuffers\sin\sthe\spager.\sFix\sfor\s#2262.\s(CVS\s3673)
+D 2007-03-06T13:46:00
 F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -85,7 +85,7 @@ F src/os_unix.c abdb0f7b8e3f078b8b48d4c0b8c801693046774d
 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
 F src/os_win.c 8736cf3a49fd651a6538857480f302807d57814c
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c c78d1cc1a02d9c6ab3263c3ca757e4466973fa2a
+F src/pager.c 680bf115aa1678a011ce046f2a1ef4cad45576cb
 F src/pager.h 8881591ca23d1e5fd83c95fa8317245fbcf64227
 F src/parse.y bcfe366c1fd61cfc40e5344eb69a31997a821af0
 F src/pragma.c 5091300911670ddaa552bfa12c45cbca1bb7e7d6
@@ -435,7 +435,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 2ba5be311945a4c15b6dce7c01efefb513b9a973
-R b6b1462461ede272fb76bf4d7e144940
-U drh
-Z ecb4e965eec3f8ba87257a871ce271b7
+P 6db945f7a7587c8c7adada92f94ac7936b901cf1
+R fd445e52d946f4b2dccfd0401e136fcc
+U danielk1977
+Z 899687d498719bea31167b023df14d79
index 711bdeb71fa29fa7cdfc1206a12199f8779927d8..a02a6aec97f0114ac79445fcee5054466bbb6a02 100644 (file)
@@ -1 +1 @@
-6db945f7a7587c8c7adada92f94ac7936b901cf1
\ No newline at end of file
+dfe1dffa4515ed6494055887d351863fe0cdb87f
\ No newline at end of file
index 73f04af69ed2136be36fdc4485cc180e5052d3ce..bf7d3caa153f9e8ec289a8024463545d3f8fde88 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.285 2007/03/04 13:15:28 drh Exp $
+** @(#) $Id: pager.c,v 1.286 2007/03/06 13:46:00 danielk1977 Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
@@ -284,6 +284,7 @@ struct Pager {
 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   Pager *pNext;               /* Linked list of pagers in this thread */
 #endif
+  char *pTmpSpace;            /* Pager.pageSize bytes of space for tmp use */
 };
 
 /*
@@ -998,17 +999,17 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
   PgHdr *pPg;                   /* An existing page in the cache */
   Pgno pgno;                    /* The page number of a page in journal */
   u32 cksum;                    /* Checksum used for sanity checking */
-  u8 aData[SQLITE_MAX_PAGE_SIZE];  /* Temp storage for a page */
+  u8 *aData = (u8 *)pPager->pTmpSpace;   /* Temp storage for a page */
 
   /* useCksum should be true for the main journal and false for
   ** statement journals.  Verify that this is always the case
   */
   assert( jfd == (useCksum ? pPager->jfd : pPager->stfd) );
-
+  assert( aData );
 
   rc = read32bits(jfd, &pgno);
   if( rc!=SQLITE_OK ) return rc;
-  rc = sqlite3OsRead(jfd, &aData, pPager->pageSize);
+  rc = sqlite3OsRead(jfd, aData, pPager->pageSize);
   if( rc!=SQLITE_OK ) return rc;
   pPager->journalOff += pPager->pageSize + 4;
 
@@ -1187,7 +1188,7 @@ static int pager_reload_cache(Pager *pPager){
   PgHdr *pPg;
   int rc = SQLITE_OK;
   for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
-    char zBuf[SQLITE_MAX_PAGE_SIZE];
+    char *zBuf = pPager->pTmpSpace;        /* Temp storage for one page */
     if( !pPg->dirty ) continue;
     if( (int)pPg->pgno <= pPager->origDbSize ){
       rc = sqlite3OsSeek(pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1));
@@ -1676,14 +1677,18 @@ int sqlite3pager_open(
   if( zFullPathname ){
     nameLen = strlen(zFullPathname);
     pPager = sqliteMalloc( sizeof(*pPager) + nameLen*3 + 30 );
+    if( pPager && rc==SQLITE_OK ){
+      pPager->pTmpSpace = (char *)sqliteMallocRaw(SQLITE_DEFAULT_PAGE_SIZE);
+    }
   }
 
+
   /* If an error occured in either of the blocks above, free the memory 
   ** pointed to by zFullPathname, free the Pager structure and close the 
   ** file. Since the pager is not allocated there is no need to set 
   ** any Pager.errMask variables.
   */
-  if( !pPager || !zFullPathname || rc!=SQLITE_OK ){
+  if( !pPager || !zFullPathname || !pPager->pTmpSpace || rc!=SQLITE_OK ){
     sqlite3OsClose(&fd);
     sqliteFree(zFullPathname);
     sqliteFree(pPager);
@@ -1780,6 +1785,7 @@ int sqlite3pager_set_pagesize(Pager *pPager, int pageSize){
   assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE );
   if( !pPager->memDb ){
     pPager->pageSize = pageSize;
+    sqlite3ReallocOrFree((void **)&pPager->pTmpSpace, pageSize);
   }
   return pPager->pageSize;
 }
@@ -2115,6 +2121,7 @@ int sqlite3pager_close(Pager *pPager){
   }
 #endif
   sqliteFree(pPager->aHash);
+  sqliteFree(pPager->pTmpSpace);
   sqliteFree(pPager);
   return SQLITE_OK;
 }