Index: src/lsm_file.c ================================================================== --- src/lsm_file.c +++ src/lsm_file.c @@ -243,12 +243,10 @@ int nCacheAlloc; /* Current cache size (in pages) */ Page *pLruFirst; /* Head of the LRU list */ Page *pLruLast; /* Tail of the LRU list */ int nHash; /* Number of hash slots in hash table */ Page **apHash; /* nHash Hash slots */ - - /* Both types of pages */ Page *pWaiting; /* b-tree pages waiting to be written */ /* Statistics */ int nOut; /* Number of outstanding pages */ int nWrite; /* Total number of pages written */ @@ -979,10 +977,16 @@ for(pp=&pFS->apHash[iHash]; *pp!=pPg; pp=&(*pp)->pHashNext); *pp = pPg->pHashNext; pPg->pHashNext = 0; } +static void fsPageBufferFree(Page *pPg){ + pPg->pFS->nCacheAlloc--; + lsmFree(pPg->pFS->pEnv, pPg->aData); + lsmFree(pPg->pFS->pEnv, pPg); +} + /* ** Purge the cache of all non-mmap pages with nRef==0. */ void lsmFsPurgeCache(FileSystem *pFS){ @@ -991,14 +995,12 @@ pPg = pFS->pLruFirst; while( pPg ){ Page *pNext = pPg->pLruNext; assert( pPg->flags & PAGE_FREE ); fsPageRemoveFromHash(pFS, pPg); - lsmFree(pFS->pEnv, pPg->aData); - lsmFree(pFS->pEnv, pPg); + fsPageBufferFree(pPg); pPg = pNext; - pFS->nCacheAlloc--; } pFS->pLruFirst = 0; pFS->pLruLast = 0; assert( pFS->nCacheAlloc<=pFS->nOut && pFS->nCacheAlloc>=0 ); @@ -1062,20 +1064,10 @@ } *ppOut = pPage; return rc; } -static void fsPageBufferFree(Page *pPg){ - assert( pPg->pLruNext==0 ); - assert( pPg->pLruPrev==0 ); - assert( pPg->pFS->pLruFirst!=pPg ); - assert( pPg->pFS->pLruLast!=pPg ); - - lsmFree(pPg->pFS->pEnv, pPg->aData); - lsmFree(pPg->pFS->pEnv, pPg); -} - static void fsGrowMapping( FileSystem *pFS, i64 iSz, int *pRc ){ Index: src/lsm_unix.c ================================================================== --- src/lsm_unix.c +++ src/lsm_unix.c @@ -200,10 +200,15 @@ off_t iSz; int prc; PosixFile *p = (PosixFile *)pFile; struct stat buf; + /* If the file is between 0 and 2MB in size, extend it in chunks of 256K. + ** Thereafter, in chunks of 1MB at a time. */ + const int aIncrSz[] = {256*1024, 1024*1024}; + int nIncrSz = aIncrSz[iMin>(2*1024*1024)]; + if( p->pMap ){ munmap(p->pMap, p->nMap); *ppOut = p->pMap = 0; *pnOut = p->nMap = 0; } @@ -212,11 +217,11 @@ memset(&buf, 0, sizeof(buf)); prc = fstat(p->fd, &buf); if( prc!=0 ) return LSM_IOERR_BKPT; iSz = buf.st_size; if( iSzfd, iSz); if( prc!=0 ) return LSM_IOERR_BKPT; } p->pMap = mmap(0, iSz, PROT_READ|PROT_WRITE, MAP_SHARED, p->fd, 0);