aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2008-09-15 15:36:57 +0000
committerdrh <drh@noemail.net>2008-09-15 15:36:57 +0000
commitb5774cfa8f19b274fd4454003aa82834ca3f72e7 (patch)
tree4485db434492e99cb841647f5741872c2d97cd1a /src
parent4ff6202642ca024cab918bc77c2f53bb6d769550 (diff)
downloadsqlite-b5774cfa8f19b274fd4454003aa82834ca3f72e7.tar.gz
sqlite-b5774cfa8f19b274fd4454003aa82834ca3f72e7.zip
Adjust the page recycling algorithm so that the number of pages allocated
to each connection does not exceed its cache_size limit. (CVS 5701) FossilOrigin-Name: 3bc221b940565133ae8d95f59b3b120e57df0124
Diffstat (limited to 'src')
-rw-r--r--src/pcache.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/pcache.c b/src/pcache.c
index ece757165..2b90bd7e3 100644
--- a/src/pcache.c
+++ b/src/pcache.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file implements that page cache.
**
-** @(#) $Id: pcache.c,v 1.26 2008/09/02 09:38:07 danielk1977 Exp $
+** @(#) $Id: pcache.c,v 1.27 2008/09/15 15:36:58 drh Exp $
*/
#include "sqliteInt.h"
@@ -555,15 +555,16 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){
*ppPage = 0;
- /* If we have reached the limit for pinned/dirty pages, and there is at
- ** least one dirty page, invoke the xStress callback to cause a page to
- ** become clean.
+ /* If we have reached either the global or the local limit for
+ ** pinned+dirty pages, and there is at least one dirty page,
+ ** invoke the xStress callback to cause a page to become clean.
*/
expensive_assert( pCache->nPinned==pcachePinnedCount(pCache) );
expensive_assert( pcacheCheckSynced(pCache) );
if( pCache->xStress
&& pCache->pDirty
- && pCache->nPinned>=(pcache_g.nMaxPage+pCache->nMin-pcache_g.nMinPage)
+ && (pCache->nPinned>=(pcache_g.nMaxPage+pCache->nMin-pcache_g.nMinPage)
+ || pCache->nPinned>=pCache->nMax)
){
PgHdr *pPg;
assert(pCache->pDirtyTail);
@@ -586,8 +587,11 @@ static int pcacheRecycleOrAlloc(PCache *pCache, PgHdr **ppPage){
}
}
- /* If the global page limit has been reached, try to recycle a page. */
- if( pCache->bPurgeable && pcache_g.nCurrentPage>=pcache_g.nMaxPage ){
+ /* If either the local or the global page limit has been reached,
+ ** try to recycle a page.
+ */
+ if( pCache->bPurgeable && (pCache->nPage>=pCache->nMax-1 ||
+ pcache_g.nCurrentPage>=pcache_g.nMaxPage) ){
p = pcacheRecyclePage();
}
@@ -1267,4 +1271,3 @@ void sqlite3PcacheStats(
*pnRecyclable = nRecyclable;
}
#endif
-