1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

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
This commit is contained in:
drh
2008-09-15 15:36:57 +00:00
parent 4ff6202642
commit b5774cfa8f
4 changed files with 90 additions and 16 deletions

View File

@@ -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