diff --git a/manifest b/manifest index ab040e00ba..f58701d8fa 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunused\svariable.\s\sFix\sa\scompiler\swarning.\s(CVS\s5319) -D 2008-06-27T00:52:45 +C Change\smem5.c\sso\sthat\sthe\sminimum\sallocation\ssize\sis\sruntime\sconfigurable.\s(CVS\s5320) +D 2008-06-27T13:27:04 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -114,14 +114,14 @@ F src/insert.c f8c7da31409ec19a769b960a4a2b9cca7bab80bd F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df F src/loadext.c 40024a0f476c1279494876b9a002001b29e5d3e3 -F src/main.c 942283a5fc983a36504cc6476b6d054911921fec +F src/main.c 7c326318fe039ea6bab91209f3eabef26f1ba33a F src/malloc.c f52166df8abd7ff6990dbee1a0ce3534addc8617 F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a F src/mem1.c 8340fa5f969e9f9b9bdeb54106457a2003456d2b F src/mem2.c 23f9538f35fbcd5665afe7056a56be0c7ed65aa7 F src/mem3.c 8d34a22617a0eb96c05a83fc2c4fbbaed6bcfde1 F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909 -F src/mem5.c d0c7c8506eb3f64c0ea0f1e8defab4043f531dad +F src/mem5.c 2ad92d6aa224650f9fa9ad41fbf27b6cdae8a76f F src/mutex.c a485a0eac8ee2cd95f66e565b4c6696c18db968f F src/mutex.h e52ffa1dfc6a6077e8b1823d2c2b7dfcbcf85594 F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97 @@ -144,7 +144,7 @@ F src/select.c 5b213de002382aeaac5c9c2d3be7c98900bc3056 F src/shell.c 479807b87f0409289eec4a776cd6ae56d30544b1 F src/sqlite.h.in bcdf4f68ce70ca30f0c3d351858383ce398e3c66 F src/sqlite3ext.h 7bf1651c6fb7183831e5113b4b91662bbe67e5bf -F src/sqliteInt.h 969acf22dbe79075e486074a8ffdc1e2fc2b8b1f +F src/sqliteInt.h a3d505360be0385fdd6d02fef82f3f10e952259e F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 F src/status.c 6cb10377992505bd69f1ca1d75c1240a65f25a58 F src/table.c 1fa8f8113ac9cbc09ae4801c6d2a7f0af82c5822 @@ -166,7 +166,7 @@ F src/test_devsym.c 6012cb8e3acf812513511025a4fa5d626e0ba19b F src/test_func.c f4aafa10f17d52c43a64b47717265802e6e552b3 F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f F src/test_loadext.c df8ab3a6481ddebbdf0d28ebac5d9e0790f7860f -F src/test_malloc.c db4b54a81e83c0e71e1780365e022ed96fac52b0 +F src/test_malloc.c 68da4add2f3f5f2aace5a15122df80e5f8454af4 F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071 F src/test_mutex.c b1433eb96520656fb3e4a218253a94ac32bd5775 F src/test_onefile.c 243157b10275251c5dc2d6619aee2ff9ae22379c @@ -422,7 +422,7 @@ F test/pager2.test c025f91b75fe65e85febda64d9416428b8a5cab5 F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4 F test/pageropt.test 6df72c441db0a037b7ec6990d16311c24fbea77b F test/pagesize.test e0a8b3fe80f8b8e808d94a00734c7a18c76c407e -F test/permutations.test e915c7125487a734cf9fc94c9653fe0a05c08d29 +F test/permutations.test 17aa068f5f6612a9e91ec316463f94141436445a F test/pragma.test 44bc52afa72cabfeae82641e0033ca24919f3ce8 F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test c3405535b418d454e8a52196a0fc592ec9eec58d @@ -594,7 +594,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P a4005782690f022e982df4873779a029b28b9306 -R f1af58e903b479838053b138b998370c -U drh -Z b29d48455395ec1bf7cf810b7d415083 +P 0b01ec5cf7725a02d4c12167df125cef578f6219 +R 0a2d2902a0d1d00bcf1712dac8ab54a9 +U danielk1977 +Z 48c1b0881009fcf3cbbdeacd5d1ca6e8 diff --git a/manifest.uuid b/manifest.uuid index 81ddcca39f..7fab162c17 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0b01ec5cf7725a02d4c12167df125cef578f6219 \ No newline at end of file +4f95f4cdf77e134fab42148e10198c7b008d4ae6 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 3b49d9d125..52bcba1c12 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.465 2008/06/26 10:54:12 danielk1977 Exp $ +** $Id: main.c,v 1.466 2008/06/27 13:27:04 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -175,22 +175,6 @@ int sqlite3_config(int op, ...){ sqlite3Config.bFullMutex = 1; break; } -#ifdef SQLITE_ENABLE_MEMSYS3 - case SQLITE_CONFIG_MEMSYS3: { - u8 *pMem = va_arg(ap, u8*); - int nMem = va_arg(ap, int); - sqlite3MemSetMemsys3(pMem, nMem); - break; - } -#endif -#ifdef SQLITE_ENABLE_MEMSYS5 - case SQLITE_CONFIG_MEMSYS5: { - u8 *pMem = va_arg(ap, u8*); - int nMem = va_arg(ap, int); - sqlite3MemSetMemsys5(pMem, nMem); - break; - } -#endif case SQLITE_CONFIG_MALLOC: { /* Specify an alternative malloc implementation */ sqlite3Config.m = *va_arg(ap, sqlite3_mem_methods*); @@ -231,13 +215,34 @@ int sqlite3_config(int op, ...){ sqlite3Config.nPage = va_arg(ap, int); break; } + case SQLITE_CONFIG_HEAP: { - /* Designate a buffer for scratch memory space */ + /* Designate a buffer for heap memory space */ sqlite3Config.pHeap = va_arg(ap, void*); sqlite3Config.nHeap = va_arg(ap, int); sqlite3Config.mnReq = va_arg(ap, int); + + /* Fall through to install the mem5.c/mem3.c methods. If neither + ** ENABLE_MEMSYS3 nor ENABLE_MEMSYS5 is defined, fall through to + ** the default case and return an error. + */ + } + +#ifdef SQLITE_ENABLE_MEMSYS5 + case SQLITE_CONFIG_MEMSYS5: { + sqlite3_mem_methods *p = sqlite3MemGetMemsys5(); + sqlite3Config.m = *p; break; } +#endif +#ifdef SQLITE_ENABLE_MEMSYS3 + case SQLITE_CONFIG_MEMSYS3: { + sqlite3_mem_methods *p = sqlite3MemGetMemsys3(); + sqlite3Config.m = *p; + break; + } +#endif + default: { rc = SQLITE_ERROR; break; diff --git a/src/mem5.c b/src/mem5.c index 179528dd05..acbe92d15d 100644 --- a/src/mem5.c +++ b/src/mem5.c @@ -23,7 +23,7 @@ ** This version of the memory allocation subsystem is included ** in the build only if SQLITE_ENABLE_MEMSYS5 is defined. ** -** $Id: mem5.c,v 1.8 2008/06/25 14:57:54 danielk1977 Exp $ +** $Id: mem5.c,v 1.9 2008/06/27 13:27:04 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -41,7 +41,6 @@ #ifndef SQLITE_POW2_LOGMIN # define SQLITE_POW2_LOGMIN 6 #endif -#define POW2_MIN (1<=0 && i=0 && iLogsize=0 && iLogsize<=LOGMAX ); assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize ); - next = mem5.aPool[i].u.list.next; - prev = mem5.aPool[i].u.list.prev; + next = MEM5LINK(i)->next; + prev = MEM5LINK(i)->prev; if( prev<0 ){ mem5.aiFreelist[iLogsize] = next; }else{ - mem5.aPool[prev].u.list.next = next; + MEM5LINK(prev)->next = next; } if( next>=0 ){ - mem5.aPool[next].u.list.prev = prev; + MEM5LINK(next)->prev = prev; } } @@ -167,14 +166,14 @@ static void memsys5Link(int i, int iLogsize){ int x; assert( sqlite3_mutex_held(mem5.mutex) ); assert( i>=0 && i=0 && iLogsize=0 && iLogsize<=LOGMAX ); assert( (mem5.aCtrl[i] & CTRL_LOGSIZE)==iLogsize ); - mem5.aPool[i].u.list.next = x = mem5.aiFreelist[iLogsize]; - mem5.aPool[i].u.list.prev = -1; + x = MEM5LINK(i)->next = mem5.aiFreelist[iLogsize]; + MEM5LINK(i)->prev = -1; if( x>=0 ){ assert( xprev = i; } mem5.aiFreelist[iLogsize] = i; } @@ -202,9 +201,9 @@ static void memsys5Leave(void){ static int memsys5Size(void *p){ int iSize = 0; if( p ){ - int i = ((Mem5Block*)p) - mem5.aPool; + int i = ((u8 *)p-mem5.zPool)/mem5.nAtom; assert( i>=0 && i=0 && iLogsize=0 && iLogsize<=LOGMAX ); i = iFirst = mem5.aiFreelist[iLogsize]; assert( iFirst>=0 ); while( i>0 ){ if( inext; } memsys5Unlink(iFirst, iLogsize); return iFirst; @@ -246,14 +245,14 @@ static void *memsys5MallocUnsafe(int nByte){ /* Round nByte up to the next valid power of two */ if( nByte>POW2_MAX ) return 0; - for(iFullSz=POW2_MIN, iLogsize=0; iFullSz=NSIZE ) return 0; + for(iBin=iLogsize; mem5.aiFreelist[iBin]<0 && iBin<=LOGMAX; iBin++){} + if( iBin>LOGMAX ) return 0; i = memsys5UnlinkFirst(iBin); while( iBin>iLogsize ){ int newSize; @@ -275,7 +274,7 @@ static void *memsys5MallocUnsafe(int nByte){ if( mem5.maxOut=0 && i=0 && iBlock0 ); assert( mem5.currentOut>=0 ); mem5.currentCount--; - mem5.currentOut -= size*POW2_MIN; + mem5.currentOut -= size*mem5.nAtom; assert( mem5.currentOut>0 || mem5.currentCount==0 ); assert( mem5.currentCount>0 || mem5.currentOut==0 ); - mem5.aCtrl[i] = CTRL_FREE | iLogsize; - while( iLogsize>iLogsize) & 1 ){ - iBuddy = i - size; + if( (iBlock>>iLogsize) & 1 ){ + iBuddy = iBlock - size; }else{ - iBuddy = i + size; + iBuddy = iBlock + size; } - assert( iBuddy>=0 && iBuddy=0 ); + if( (iBuddy+(1<mem5.nBlock ) break; if( mem5.aCtrl[iBuddy]!=(CTRL_FREE | iLogsize) ) break; memsys5Unlink(iBuddy, iLogsize); iLogsize++; - if( iBuddymem5.nAtom ){ + mem5.nAtom = mem5.nAtom << 1; + } + + mem5.nBlock = (nByte / (mem5.nAtom+sizeof(u8))); + mem5.zPool = zByte; + mem5.aCtrl = (u8 *)&mem5.zPool[mem5.nBlock*mem5.nAtom]; + + for(ii=0; ii<=LOGMAX; ii++){ + mem5.aiFreelist[ii] = -1; + } + + iOffset = 0; + for(ii=LOGMAX; ii>=0; ii--){ + int nAlloc = (1<mem5.nBlock); + } + return SQLITE_OK; } @@ -409,6 +454,7 @@ void sqlite3Memsys5Dump(const char *zFilename){ #ifdef SQLITE_DEBUG FILE *out; int i, j, n; + int nMinLog; if( zFilename==0 || zFilename[0]==0 ){ out = stdout; @@ -421,9 +467,10 @@ void sqlite3Memsys5Dump(const char *zFilename){ } } memsys5Enter(); - for(i=0; i=0; j = mem5.aPool[j].u.list.next, n++){} - fprintf(out, "freelist items of size %d: %d\n", POW2_MIN << i, n); + nMinLog = memsys5Log(mem5.nAtom); + for(i=0; i<=LOGMAX && i+nMinLog<32; i++){ + for(n=0, j=mem5.aiFreelist[i]; j>=0; j = MEM5LINK(j)->next, n++){} + fprintf(out, "freelist items of size %d: %d\n", mem5.nAtom << i, n); } fprintf(out, "mem5.nAlloc = %llu\n", mem5.nAlloc); fprintf(out, "mem5.totalAlloc = %llu\n", mem5.totalAlloc); @@ -444,16 +491,10 @@ void sqlite3Memsys5Dump(const char *zFilename){ /* ** This routine is the only routine in this file with external -** linkage. -** -** Populate the low-level memory allocation function pointers in -** sqlite3Config.m with pointers to the routines in this file. The -** arguments specify the block of memory to manage. -** -** This routine is only called by sqlite3_config(), and therefore -** is not required to be threadsafe (it is not). +** linkage. It returns a pointer to a static sqlite3_mem_methods +** struct populated with the memsys5 methods. */ -void sqlite3MemSetMemsys5(u8 *zByte, int nByte){ +const sqlite3_mem_methods *sqlite3MemGetMemsys5(void){ static const sqlite3_mem_methods memsys5Methods = { memsys5Malloc, memsys5Free, @@ -464,25 +505,7 @@ void sqlite3MemSetMemsys5(u8 *zByte, int nByte){ memsys5Shutdown, 0 }; - int i; - - mem5.nBlock = (nByte / (sizeof(Mem5Block)+sizeof(u8))); - mem5.nBlock -= (mem5.nBlock%SZ_MAX); - mem5.aPool = (Mem5Block *)zByte; - mem5.aCtrl = (u8 *)&mem5.aPool[mem5.nBlock]; - - assert( sizeof(Mem5Block)==POW2_MIN ); - assert( mem5.nBlock>=SZ_MAX ); - assert( (mem5.nBlock%SZ_MAX)==0 ); - - for(i=0; i0 && 0==strcmp("-memsys3", Tcl_GetString(aArg[0])) ){ + nArg--; + aArg++; + isMemsys3 = 1; + } + if( nArg!=2 ){ + Tcl_WrongNumArgs(interp, 1, objv, "?-memsys3? NBYTE NMINALLOC"); + return TCL_ERROR; + } + if( Tcl_GetIntFromObj(interp, aArg[0], &nByte) ) return TCL_ERROR; + if( Tcl_GetIntFromObj(interp, aArg[1], &nMinAlloc) ) return TCL_ERROR; + + if( nByte>sizeof(zBuf) ){ + nByte = sizeof(zBuf); + } + rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc); + + Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); + return TCL_OK; +} + /* ** Usage: ** @@ -1106,6 +1147,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){ { "install_malloc_faultsim", test_install_malloc_faultsim ,0. }, { "sqlite3_config_memsys3", test_config_memsys3, SQLITE_CONFIG_MEMSYS3 }, { "sqlite3_config_memsys5", test_config_memsys3, SQLITE_CONFIG_MEMSYS5 }, + { "sqlite3_config_heap", test_config_heap, 0 }, { "sqlite3_dump_memsys3", test_dump_memsys3 , SQLITE_CONFIG_MEMSYS3 }, { "sqlite3_dump_memsys5", test_dump_memsys3 , SQLITE_CONFIG_MEMSYS5 } }; diff --git a/test/permutations.test b/test/permutations.test index 8c2f6f22bb..81cff4d5c4 100644 --- a/test/permutations.test +++ b/test/permutations.test @@ -9,7 +9,7 @@ # #*********************************************************************** # -# $Id: permutations.test,v 1.7 2008/06/25 14:57:54 danielk1977 Exp $ +# $Id: permutations.test,v 1.8 2008/06/27 13:27:04 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -367,7 +367,27 @@ ifcapable mem5 { catch {db close} sqlite3_reset_auto_extension sqlite3_shutdown - sqlite3_config_memsys5 1000000 + sqlite3_config_heap 1000000 64 + install_malloc_faultsim 1 + sqlite3_initialize + autoinstall_test_functions + } -shutdown { + catch {db close} + sqlite3_reset_auto_extension + sqlite3_shutdown + sqlite3_config_memsys5 0 + install_malloc_faultsim 1 + sqlite3_initialize + } + + run_tests "memsys5-2" -description { + Run tests using the allocator in mem5.c in a different configuration. + } -include { select1.test + } -initialize { + catch {db close} + sqlite3_reset_auto_extension + sqlite3_shutdown + sqlite3_config_heap 250000 16 install_malloc_faultsim 1 sqlite3_initialize autoinstall_test_functions