SQLite4
Check-in [0cbb5cc2cd]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix bugs on this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | mmap-on-demand
Files: files | file ages | folders
SHA1: 0cbb5cc2cdc91da23cce3823f3542da89d89a431
User & Date: dan 2013-02-05 09:51:19
Context
2013-03-02
09:15
Merge trunk changes into this branch. check-in: 6666862302 user: dan tags: mmap-on-demand
2013-02-05
09:51
Fix bugs on this branch. check-in: 0cbb5cc2cd user: dan tags: mmap-on-demand
2013-02-04
19:04
Map and unmap parts of the database file on an LRU basis to limit the amount of address space consumed at any one time (for 32-bit address spaces). It looks like this might be slower than read() and write() anyway... check-in: d1b1a9e969 user: dan tags: mmap-on-demand
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/lsm_file.c.

824
825
826
827
828
829
830


831
832
833
834
835
836
837
....
1539
1540
1541
1542
1543
1544
1545
1546

1547
1548
1549
1550
1551
1552
1553
....
1628
1629
1630
1631
1632
1633
1634
1635

1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
    pFS->pDb = pDb;
    pFS->pEnv = pDb->pEnv;
    if( pDb->compress.xCompress ){
      pFS->pCompress = &pDb->compress;
    }else{
      pFS->mmapmgr.eUseMmap = pDb->eMmap;
      pFS->mmapmgr.nMapsz = 1*1024*1024;


    }

    /* Make a copy of the database and log file names. */
    memcpy(pFS->zDb, zDb, nDb+1);
    memcpy(pFS->zLog, zDb, nDb);
    memcpy(&pFS->zLog[nDb], "-log", 5);

................................................................................
      fsPageAddToLru(pFS, p);
      p->pFS = pFS;
    }
    p->iPg = iReal;

    p->aData = fsMmapRef(pFS, iOff, pFS->nPagesize, &p->pRef, &rc);
    if( rc!=LSM_OK ){
      lsmFsPageRelease(p);

      p = 0;
    }
  }else{

    /* Search the hash-table for the page */
    iHash = fsHashKey(pFS->nHash, iReal);
    for(p=pFS->apHash[iHash]; p; p=p->pHashNext){
................................................................................
int lsmFsReadSyncedId(lsm_db *db, int iMeta, i64 *piVal){
  FileSystem *pFS = db->pFS;
  int rc = LSM_OK;

  assert( iMeta==1 || iMeta==2 );
  if( pFS->mmapmgr.eUseMmap!=LSM_MMAP_OFF ){
    MmapMgrRef *pRef = 0;
    u8 *pMap;                     /* Mapping of two meta pages */


    pMap = (u8 *)fsMmapRef(pFS, 0, LSM_META_PAGE_SIZE*2, &pRef, &rc);
    if( rc==LSM_OK ){
      *piVal = (i64)lsmGetU64(&pMap[(iMeta-1)*LSM_META_PAGE_SIZE]);
      fsMmapUnref(pFS, &pRef);
    }
  }else{
    MetaPage *pMeta = 0;
    rc = lsmFsMetaPageGet(pFS, 0, iMeta, &pMeta);
    if( rc==LSM_OK ){
      *piVal = (i64)lsmGetU64(pMeta->aData);







>
>







 







|
>







 







|
>

|

|







824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
....
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
....
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
    pFS->pDb = pDb;
    pFS->pEnv = pDb->pEnv;
    if( pDb->compress.xCompress ){
      pFS->pCompress = &pDb->compress;
    }else{
      pFS->mmapmgr.eUseMmap = pDb->eMmap;
      pFS->mmapmgr.nMapsz = 1*1024*1024;

      pFS->mmapmgr.nMapsz = 4*1024;
    }

    /* Make a copy of the database and log file names. */
    memcpy(pFS->zDb, zDb, nDb+1);
    memcpy(pFS->zLog, zDb, nDb);
    memcpy(&pFS->zLog[nDb], "-log", 5);

................................................................................
      fsPageAddToLru(pFS, p);
      p->pFS = pFS;
    }
    p->iPg = iReal;

    p->aData = fsMmapRef(pFS, iOff, pFS->nPagesize, &p->pRef, &rc);
    if( rc!=LSM_OK ){
      p->pHashNext = pFS->pFree;
      pFS->pFree = p;
      p = 0;
    }
  }else{

    /* Search the hash-table for the page */
    iHash = fsHashKey(pFS->nHash, iReal);
    for(p=pFS->apHash[iHash]; p; p=p->pHashNext){
................................................................................
int lsmFsReadSyncedId(lsm_db *db, int iMeta, i64 *piVal){
  FileSystem *pFS = db->pFS;
  int rc = LSM_OK;

  assert( iMeta==1 || iMeta==2 );
  if( pFS->mmapmgr.eUseMmap!=LSM_MMAP_OFF ){
    MmapMgrRef *pRef = 0;
    u8 *pMap;                     /* Mapping of meta pages */
    int iOff = (iMeta==2 ? LSM_META_PAGE_SIZE : 0);

    pMap = (u8 *)fsMmapRef(pFS, iOff, LSM_META_PAGE_SIZE, &pRef, &rc);
    if( rc==LSM_OK ){
      *piVal = (i64)lsmGetU64(pMap);
      fsMmapUnref(pFS, &pRef);
    }
  }else{
    MetaPage *pMeta = 0;
    rc = lsmFsMetaPageGet(pFS, 0, iMeta, &pMeta);
    if( rc==LSM_OK ){
      *piVal = (i64)lsmGetU64(pMeta->aData);

Changes to src/lsm_unix.c.

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

210

211
212
213
214
215
216
217
  if( prc!=0 ) return LSM_IOERR_BKPT;

  if( nByte<=0 ){
    sz = (size_t)(LSM_MAX(nByte*-1, (i64)buf.st_size));
  }else{
    sz = (size_t)nByte;
  }
  sz = (size_t)(LSM_MAX(sz, 1<<15));

  if( (off+sz)>buf.st_size ){
    prc = ftruncate(p->fd, (off+sz));
    if( prc!=0 ) return LSM_IOERR_BKPT;
  }

  *ppOut = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED, p->fd, off);

  if( *ppOut==0 ) return LSM_IOERR_BKPT;


  *pszOut = (i64)sz;
  return LSM_OK;
}

static int lsmPosixOsUnmap(
  lsm_file *pFile, 







<







>
|
>







195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  if( prc!=0 ) return LSM_IOERR_BKPT;

  if( nByte<=0 ){
    sz = (size_t)(LSM_MAX(nByte*-1, (i64)buf.st_size));
  }else{
    sz = (size_t)nByte;
  }


  if( (off+sz)>buf.st_size ){
    prc = ftruncate(p->fd, (off+sz));
    if( prc!=0 ) return LSM_IOERR_BKPT;
  }

  *ppOut = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED, p->fd, off);
  if( *ppOut==MAP_FAILED ){
    return LSM_IOERR_BKPT;
  }

  *pszOut = (i64)sz;
  return LSM_OK;
}

static int lsmPosixOsUnmap(
  lsm_file *pFile,