diff options
author | drh <drh@noemail.net> | 2019-12-12 17:17:24 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-12-12 17:17:24 +0000 |
commit | 0225d819c4ca87cd29cd6f58d50c75bcee6213bc (patch) | |
tree | 79e89c4779e081f3ab54b0aeea85eacd6b278c78 /src | |
parent | 20d6c1fe1bafcef4b60656a4f2c6da03cc5b98ed (diff) | |
download | sqlite-0225d819c4ca87cd29cd6f58d50c75bcee6213bc.tar.gz sqlite-0225d819c4ca87cd29cd6f58d50c75bcee6213bc.zip |
Change the size of a mini-lookaside allocation to a macro (MINI_SZ) rather
than a magic number (128).
FossilOrigin-Name: 5e1949bca998f3c8c23a8ebf01c7a2e7a2af1fdad43886271e1fe0f25411551d
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 8 | ||||
-rw-r--r-- | src/malloc.c | 6 | ||||
-rw-r--r-- | src/sqliteInt.h | 3 |
3 files changed, 10 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c index 96234bfe4..5b70273af 100644 --- a/src/main.c +++ b/src/main.c @@ -720,9 +720,9 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.pMiniFree = 0; /* The arithmetic below causes the number of large lookaside slots to be 1/3 ** the number of mini slots, based on the observation that 75% of allocations - ** are <=128B. + ** are <= MINI_SZ bytes. */ - cnt = szAlloc/(3*128+sz); + cnt = szAlloc/(3*MINI_SZ+sz); #endif db->lookaside.sz = (u16)sz; db->lookaside.szTrue = (u16)sz; @@ -740,11 +740,11 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ #ifndef SQLITE_OMIT_MINI_LOOKASIDE db->lookaside.pMiddle = p; /* Fill the remainder of the buffer with mini slots */ - while(p<=(LookasideSlot*)&((u8*)pStart)[szAlloc-128]){ + while(p<=(LookasideSlot*)&((u8*)pStart)[szAlloc-MINI_SZ]){ p->pNext = db->lookaside.pMiniInit; db->lookaside.pMiniInit = p; db->lookaside.nSlot++; - p = (LookasideSlot*)&((u8*)p)[128]; + p = (LookasideSlot*)&((u8*)p)[MINI_SZ]; } #endif db->lookaside.pEnd = p; diff --git a/src/malloc.c b/src/malloc.c index 9241b97c7..8f77c9643 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -334,7 +334,7 @@ int sqlite3MallocSize(void *p){ } static int lookasideMallocSize(sqlite3 *db, void *p){ #ifndef SQLITE_OMIT_MINI_LOOKASIDE - return p<db->lookaside.pMiddle ? db->lookaside.szTrue : 128; + return p<db->lookaside.pMiddle ? db->lookaside.szTrue : MINI_SZ; #else return db->lookaside.szTrue; #endif @@ -408,7 +408,7 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){ if( p>=db->lookaside.pMiddle ){ # ifdef SQLITE_DEBUG /* Trash all content in the buffer being freed */ - memset(p, 0xaa, 128); + memset(p, 0xaa, MINI_SZ); # endif pBuf->pNext = db->lookaside.pMiniFree; db->lookaside.pMiniFree = pBuf; @@ -583,7 +583,7 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ } db->lookaside.anStat[1]++; # ifndef SQLITE_OMIT_MINI_LOOKASIDE - }else if( n<=128 ){ + }else if( n<=MINI_SZ ){ if( (pBuf = db->lookaside.pMiniFree)!=0 ){ db->lookaside.pMiniFree = pBuf->pNext; db->lookaside.anStat[0]++; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 528092337..d01c8128b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1303,6 +1303,9 @@ struct LookasideSlot { #define EnableLookaside db->lookaside.bDisable--;\ db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue +/* Size of the MINI lookside allocation */ +#define MINI_SZ 128 + /* ** A hash table for built-in function definitions. (Application-defined ** functions use a regular table table from hash.h.) |