aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authornumist <numist@noemail.net>2019-12-12 02:50:07 +0000
committernumist <numist@noemail.net>2019-12-12 02:50:07 +0000
commit115d663c05758e5d32a5c5123c1d7b4b5460ae7c (patch)
tree397de6901c0615c6c1a547250b5a20116614d17b /src/main.c
parent3ecc05bc3fb414a0a184b4d69d5ecc38ddb24951 (diff)
downloadsqlite-115d663c05758e5d32a5c5123c1d7b4b5460ae7c.tar.gz
sqlite-115d663c05758e5d32a5c5123c1d7b4b5460ae7c.zip
More efficient implementation of a lookaside allocator that supports mini (in this case, harcoded to 128B) slots.
FossilOrigin-Name: b02fdc09c838f355d9efce57f817d6a86153153b4a1f2b763914f4aaa34cb76e
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 1afeee0bd..96234bfe4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -683,6 +683,7 @@ int sqlite3_config(int op, ...){
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
#ifndef SQLITE_OMIT_LOOKASIDE
void *pStart;
+ sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
if( sqlite3LookasideUsed(db,0)>0 ){
return SQLITE_BUSY;
@@ -705,7 +706,7 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
pStart = 0;
}else if( pBuf==0 ){
sqlite3BeginBenignMalloc();
- pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */
+ pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */
sqlite3EndBenignMalloc();
if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
}else{
@@ -714,6 +715,15 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
db->lookaside.pStart = pStart;
db->lookaside.pInit = 0;
db->lookaside.pFree = 0;
+#ifndef SQLITE_OMIT_MINI_LOOKASIDE
+ db->lookaside.pMiniInit = 0;
+ 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.
+ */
+ cnt = szAlloc/(3*128+sz);
+#endif
db->lookaside.sz = (u16)sz;
db->lookaside.szTrue = (u16)sz;
if( pStart ){
@@ -727,6 +737,16 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
db->lookaside.pInit = p;
p = (LookasideSlot*)&((u8*)p)[sz];
}
+#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]){
+ p->pNext = db->lookaside.pMiniInit;
+ db->lookaside.pMiniInit = p;
+ db->lookaside.nSlot++;
+ p = (LookasideSlot*)&((u8*)p)[128];
+ }
+#endif
db->lookaside.pEnd = p;
db->lookaside.bDisable = 0;
db->lookaside.bMalloced = pBuf==0 ?1:0;