/ Check-in [5ed8ad78]
Login

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

Overview
Comment:Do not use the Linux mremap() call. Use the same strategy for xMremap() as on OSX instead.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental-mmap
Files: files | file ages | folders
SHA1:5ed8ad780c991d2ca44003ee84350fb5e95ad58e
User & Date: dan 2013-03-21 14:47:47
Context
2013-03-21
15:57
Fix a problem when opening a write-transaction while there exist read-only b-tree cursors in mmap mode. check-in: 32e0bbb7 user: dan tags: experimental-mmap
14:47
Do not use the Linux mremap() call. Use the same strategy for xMremap() as on OSX instead. check-in: 5ed8ad78 user: dan tags: experimental-mmap
2013-03-20
18:25
Optimize the xMremap method in os_unix.c some. check-in: 9529ed88 user: dan tags: experimental-mmap
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
  /* According to some sources, the effect of changing the size of the
  ** underlying file on mapped regions that correspond to the added or
  ** removed pages is undefined. However, there is reason to believe that
  ** on modern platforms like Linux or OSX, things just work. For example,
  ** it is possible to create a mapping larger than the file on disk and
  ** extend the file on disk later on.
  **
  ** Exploit this on OSX to reduce the number of munmap()/mmap() calls
  ** if the file size is changing. In this case all mappings are rounded
  ** up to the nearest 4MB. And if a new mapping is requested that has the
  ** same rounded size as an old mapping, the old mapping can simply be
  ** reused as is.
  **
  ** It would be possible to do the above on Linux too. However, Linux has
  ** the non-standard mremap() call to resize existing mappings, which can
  ** be used instead.  */
#if defined(__APPLE__)
  nNewRnd = ROUNDUP(nNew, 4096*1024);
  nOldRnd = ROUNDUP(nOld, 4096*1024);
#else
  nNewRnd = ROUNDUP(nNew, 4096*1);
  nOldRnd = ROUNDUP(nOld, 4096*1);
#endif

  /* On OSX or Linux, reuse the old mapping if it is the right size. */
#if defined(__APPLE__) || defined(__linux__)
  if( nNewRnd==nOldRnd ){
    return SQLITE_OK;
  }
#endif

  /* On Linux, if there is both an old and new mapping, resize the old 
  ** mapping using the non-standard mremap() call.  */
#if defined(_GNU_SOURCE) && defined(__linux__)
  if( nNewRnd && nOldRnd ){
    void *pOld = *ppMap;
    *ppMap = pNew = mremap(pOld, nOldRnd, nNewRnd, MREMAP_MAYMOVE);
    if( pNew==MAP_FAILED ){
      *ppMap = 0;
      return SQLITE_IOERR_MREMAP;
    }
    return SQLITE_OK;
  }
#endif

  /* If we get this far, unmap any old mapping. */
  if( nOldRnd!=0 ){
    void *pOld = *ppMap;







|
|
|
|
|
<
<
<
<
|










<
<
<
<
<
<
<
<
<
<
<
<
<
<







4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485




4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496














4497
4498
4499
4500
4501
4502
4503
  /* According to some sources, the effect of changing the size of the
  ** underlying file on mapped regions that correspond to the added or
  ** removed pages is undefined. However, there is reason to believe that
  ** on modern platforms like Linux or OSX, things just work. For example,
  ** it is possible to create a mapping larger than the file on disk and
  ** extend the file on disk later on.
  **
  ** Exploit this on Linux and OSX to reduce the number of munmap()/mmap() 
  ** calls required if the file size is changing. In this case all mappings 
  ** are rounded up to the nearest 4MB. And if a new mapping is requested 
  ** that has the same rounded size as an old mapping, the old mapping can 
  ** be reused as is. */




#if defined(__APPLE__) || defined(__linux__)
  nNewRnd = ROUNDUP(nNew, 4096*1024);
  nOldRnd = ROUNDUP(nOld, 4096*1024);
#else
  nNewRnd = ROUNDUP(nNew, 4096*1);
  nOldRnd = ROUNDUP(nOld, 4096*1);
#endif

  /* On OSX or Linux, reuse the old mapping if it is the right size. */
#if defined(__APPLE__) || defined(__linux__)
  if( nNewRnd==nOldRnd ){














    return SQLITE_OK;
  }
#endif

  /* If we get this far, unmap any old mapping. */
  if( nOldRnd!=0 ){
    void *pOld = *ppMap;