]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplifications to the SQLITE_PAGECACHE_BLOCKALLOC logic. Reduce the number
authordrh <drh@noemail.net>
Tue, 23 Aug 2011 23:41:40 +0000 (23:41 +0000)
committerdrh <drh@noemail.net>
Tue, 23 Aug 2011 23:41:40 +0000 (23:41 +0000)
of difficult-to-reach branches.

FossilOrigin-Name: d5d835fe8352cb2009133246d4ed1cd310803f75

manifest
manifest.uuid
src/pcache1.c

index 967ac8305e1cde769516932dd06fb9c7c70f8257..6323eabd4367155b6828950eb95373eb613c5e08 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C If\sthe\sapplication-defined\sopenDirectory()\sfunction\sreturns\sSQLITE_CANTOPEN,\nthen\ssilently\signore\sthe\serror.\s\sThis\sallows\sthe\schromium\ssandbox\sto\sdisallow\nopening\sof\sdirectories\swithout\scausing\serrors.
-D 2011-08-23T20:11:32.027
+C Simplifications\sto\sthe\sSQLITE_PAGECACHE_BLOCKALLOC\slogic.\s\sReduce\sthe\snumber\nof\sdifficult-to-reach\sbranches.
+D 2011-08-23T23:41:40.811
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 8c930e7b493d59099ea1304bd0f2aed152eb3315
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -172,7 +172,7 @@ F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1
 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
 F src/pcache.c 49e718c095810c6b3334e3a6d89970aceaddefce
 F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050
-F src/pcache1.c a1d860753eee0a46165afaad3962a88463fb32a8
+F src/pcache1.c c8982f7048a70b7fd37975a8f6c84d6bc294175a
 F src/pragma.c ebcd20f1e654f5cb3aeef864ed69c4697719fbaa
 F src/prepare.c e64261559a3187698a3e7e6c8b001a4f4f98dab4
 F src/printf.c 585a36b6a963df832cfb69505afa3a34ed5ef8a1
@@ -961,7 +961,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5
 F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings.sh 2ebae31e1eb352696f3c2f7706a34c084b28c262
-P 40dd8a60be0ca79e0d0bf3a2b5a43f13c02b4971
-R 5e02443774dfa828b5ad397a58754916
+P 880b51150aaed804005f5062b4dd2fa0ffafa147
+R 690091bd4eec428f02b835dd5a4096b1
 U drh
-Z d188cae288df33cd4e6f9c6da0cbb238
+Z a67c28a746ea7a9568474b8f0d071914
index 98df3a2da1caae136f291bd71b6e4a5290640a89..32875c869f54f9286f89b16eda4a1d1a5adef584 100644 (file)
@@ -1 +1 @@
-880b51150aaed804005f5062b4dd2fa0ffafa147
\ No newline at end of file
+d5d835fe8352cb2009133246d4ed1cd310803f75
\ No newline at end of file
index b9cbcf98a51973446cb170395a07ce4ecac8b6f5..de96e5242ae8e219b7ccae5a0c021e7b705bc067 100644 (file)
@@ -56,7 +56,10 @@ struct PGroup {
   int mxPinned;                  /* nMaxpage + 10 - nMinPage */
   int nCurrentPage;              /* Number of purgeable pages allocated */
   PgHdr1 *pLruHead, *pLruTail;   /* LRU list of unpinned pages */
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
+  int isBusy;                    /* Do not run ReleaseMemory() if true */
   PGroupBlockList *pBlockList;   /* List of block-lists for this group */
+#endif
 };
 
 /*
@@ -401,32 +404,30 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
   nByte += sizeof(PGroupBlockList *);
   nByte = ROUND8(nByte);
 
-  do{
-    for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
-      if( pList->nByte==nByte ) break;
+  for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
+    if( pList->nByte==nByte ) break;
+  }
+  if( pList==0 ){
+    PGroupBlockList *pNew;
+    assert( pGroup->isBusy==0 );
+    assert( sqlite3_mutex_held(pGroup->mutex) );
+    pGroup->isBusy = 1;  /* Disable sqlite3PcacheReleaseMemory() */
+    pNew = (PGroupBlockList *)sqlite3MallocZero(sizeof(PGroupBlockList));
+    pGroup->isBusy = 0;  /* Reenable sqlite3PcacheReleaseMemory() */
+    if( pNew==0 ){
+      /* malloc() failure. Return early. */
+      return 0;
     }
-    if( pList==0 ){
-      PGroupBlockList *pNew;
-      pcache1LeaveMutex(pCache->pGroup);
-      pNew = (PGroupBlockList *)sqlite3MallocZero(sizeof(PGroupBlockList));
-      pcache1EnterMutex(pCache->pGroup);
-      if( pNew==0 ){
-        /* malloc() failure. Return early. */
-        return 0;
-      }
-      for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
-        if( pList->nByte==nByte ) break;
-      }
-      if( pList ){
-        sqlite3_free(pNew);
-      }else{
-        pNew->nByte = nByte;
-        pNew->pNext = pGroup->pBlockList;
-        pGroup->pBlockList = pNew;
-        pList = pNew;
-      }
+#ifdef SQLITE_DEBUG
+    for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
+      assert( pList->nByte!=nByte );
     }
-  }while( pList==0 );
+#endif
+    pNew->nByte = nByte;
+    pNew->pNext = pGroup->pBlockList;
+    pGroup->pBlockList = pNew;
+    pList = pNew;
+  }
 
   pBlock = pList->pFirst;
   if( pBlock==0 || pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) ){
@@ -436,6 +437,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
     ** structure and MINENTRY allocations of nByte bytes each. If the 
     ** allocator returns more memory than requested, then more than MINENTRY 
     ** allocations may fit in it. */
+    assert( sqlite3_mutex_held(pGroup->mutex) );
     pcache1LeaveMutex(pCache->pGroup);
     sz = sizeof(PGroupBlock) + PAGECACHE_BLOCKALLOC_MINENTRY * nByte;
     pBlock = (PGroupBlock *)sqlite3Malloc(sz);
@@ -481,6 +483,10 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
     pList->pLast->pNext = pBlock;
     pList->pLast = pBlock;
   }
+  p = PAGE_TO_PGHDR1(pCache, pPg);
+  if( pCache->bPurgeable ){
+    pCache->pGroup->nCurrentPage++;
+  }
 #else
   /* The group mutex must be released before pcache1Alloc() is called. This
   ** is because it may call sqlite3_release_memory(), which assumes that 
@@ -489,8 +495,6 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
   pcache1LeaveMutex(pCache->pGroup);
   pPg = pcache1Alloc(nByte);
   pcache1EnterMutex(pCache->pGroup);
-#endif
-
   if( pPg ){
     p = PAGE_TO_PGHDR1(pCache, pPg);
     if( pCache->bPurgeable ){
@@ -499,6 +503,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
   }else{
     p = 0;
   }
+#endif
   return p;
 }
 
@@ -1165,6 +1170,9 @@ void sqlite3PCacheSetDefault(void){
 */
 int sqlite3PcacheReleaseMemory(int nReq){
   int nFree = 0;
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
+  if( pcache1.grp.isBusy ) return 0;
+#endif
   assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
   assert( sqlite3_mutex_notheld(pcache1.mutex) );
   if( pcache1.pStart==0 ){