Change the definition of SQLITE_CONFIG_SCRATCH so that at most one scratch

buffer is used per thread.  Use the generic heap memory allocator for the
WalIterator object when running a checkpoint.

FossilOrigin-Name: 391c9b85abcb5ba300fb2e116384639310c69ed2
This commit is contained in:
drh
2014-11-04 14:22:27 +00:00
parent 5279d3433c
commit cbd55b0362
6 changed files with 24 additions and 30 deletions
+2 -5
View File
@@ -6650,12 +6650,9 @@ static int balance_nonroot(
+ nMaxCells*sizeof(u16) /* szCell */
+ pBt->pageSize; /* aSpace1 */
/* EVIDENCE-OF: R-37926-08392 SQLite will never request a scratch buffer
** that is more than 6 times the database page size, except when
** performing a checkpoint in WAL mode when the scratch buffer request
** size is a small fraction of the size of the WAL file. */
/* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
** that is more than 6 times the database page size. */
assert( szScratch<=6*pBt->pageSize );
apCell = sqlite3ScratchMalloc( szScratch );
if( apCell==0 ){
rc = SQLITE_NOMEM;
+6 -5
View File
@@ -377,11 +377,12 @@ void *sqlite3ScratchMalloc(int n){
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
/* Verify that no more than two scratch allocations per thread
** are outstanding at one time. (This is only checked in the
** single-threaded case since checking in the multi-threaded case
** would be much more complicated.) */
assert( scratchAllocOut<=1 );
/* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
** buffers per thread.
**
** This can only be checked in single-threaded mode.
*/
assert( scratchAllocOut==0 );
if( p ) scratchAllocOut++;
#endif
+2 -6
View File
@@ -1541,13 +1541,9 @@ struct sqlite3_mem_methods {
** and the maximum number of scratch allocations (N).)^
** The first argument must be a pointer to an 8-byte aligned buffer
** of at least sz*N bytes of memory.
** ^SQLite will not use more than two scratch buffers per thread and not
** more than one scratch buffer per thread when not performing
** a [checkpoint] in [WAL mode].
** ^SQLite will not use more than one scratch buffers per thread.
** ^SQLite will never request a scratch buffer that is more than 6
** times the database page size, except when performing a [checkpoint]
** in [WAL mode] when the scratch buffer request size is a small fraction
** of the size of the WAL file.
** times the database page size.
** ^If SQLite needs needs additional
** scratch memory beyond what is provided by this configuration option, then
** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
+4 -4
View File
@@ -1504,7 +1504,7 @@ static void walMergesort(
** Free an iterator allocated by walIteratorInit().
*/
static void walIteratorFree(WalIterator *p){
sqlite3ScratchFree(p);
sqlite3_free(p);
}
/*
@@ -1539,7 +1539,7 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){
nByte = sizeof(WalIterator)
+ (nSegment-1)*sizeof(struct WalSegment)
+ iLast*sizeof(ht_slot);
p = (WalIterator *)sqlite3ScratchMalloc(nByte);
p = (WalIterator *)sqlite3_malloc(nByte);
if( !p ){
return SQLITE_NOMEM;
}
@@ -1549,7 +1549,7 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){
/* Allocate temporary space used by the merge-sort routine. This block
** of memory will be freed before this function returns.
*/
aTmp = (ht_slot *)sqlite3ScratchMalloc(
aTmp = (ht_slot *)sqlite3_malloc(
sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
);
if( !aTmp ){
@@ -1586,7 +1586,7 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){
p->aSegment[i].aPgno = (u32 *)aPgno;
}
}
sqlite3ScratchFree(aTmp);
sqlite3_free(aTmp);
if( rc!=SQLITE_OK ){
walIteratorFree(p);