/ Check-in [5b60df55]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Simplify the page recycling condition in pcache1. Fix test cases to work with the latest changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pcache-bulk-local
Files: files | file ages | folders
SHA1: 5b60df5503f61922326b3e10e94aa197b17afe4b
User & Date: drh 2015-07-07 14:06:18
Context
2015-07-07
15:14
No need to test sqlite3GlobalConfig.bCoreMutex when SQLITE_THREADSAFE==0. check-in: 26db0fee user: drh tags: pcache-bulk-local
14:06
Simplify the page recycling condition in pcache1. Fix test cases to work with the latest changes. check-in: 5b60df55 user: drh tags: pcache-bulk-local
2015-07-06
20:57
A unified cache is now only used for SQLITE_ENABLE_MEMORY_MANAGEMENT, or if SQLITE_CONFIG_PAGECACHE defines a shared start-time page cache buffer and the application is single-threaded. check-in: d5ff1d69 user: drh tags: pcache-bulk-local
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/pcache1.c.

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
    return 0;
  }

  if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
  assert( pCache->nHash>0 && pCache->apHash );

  /* Step 4. Try to recycle a page. */
  if( pCache->bPurgeable && pGroup->pLruTail && (
         (pCache->nPage+1>=pCache->nMax)
      || pGroup->nCurrentPage>=pGroup->nMaxPage
      || pcache1UnderMemoryPressure(pCache)
  )){
    PCache1 *pOther;
    pPage = pGroup->pLruTail;
    assert( pPage->isPinned==0 );
    pcache1RemoveFromHash(pPage, 0);
    pcache1PinPage(pPage);
    pOther = pPage->pCache;
    if( pOther->szAlloc != pCache->szAlloc ){







|
|
<
|
|







814
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829
830
831
    return 0;
  }

  if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
  assert( pCache->nHash>0 && pCache->apHash );

  /* Step 4. Try to recycle a page. */
  if( pCache->bPurgeable
   && pGroup->pLruTail

   && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
  ){
    PCache1 *pOther;
    pPage = pGroup->pLruTail;
    assert( pPage->isPinned==0 );
    pcache1RemoveFromHash(pPage, 0);
    pcache1PinPage(pPage);
    pOther = pPage->pCache;
    if( pOther->szAlloc != pCache->szAlloc ){

Changes to test/memdb.test.

415
416
417
418
419
420
421
422
423
424

425
426
427
428
429
430
431
432
    execsql {
      PRAGMA auto_vacuum = full;
      CREATE TABLE t1(a);
      INSERT INTO t1 VALUES(randstr(1000,1000));
      INSERT INTO t1 VALUES(randstr(1000,1000));
      INSERT INTO t1 VALUES(randstr(1000,1000));
    }
    set memused [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1]
    set pgovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 1]
    execsql { DELETE FROM t1 }

    set memused2 [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1]
    expr {($memused2 + 2048 < $memused) || $pgovfl==0}
  } {1}
}

} ;# ifcapable memorydb

finish_test







|
<

>
|
<






415
416
417
418
419
420
421
422

423
424
425

426
427
428
429
430
431
    execsql {
      PRAGMA auto_vacuum = full;
      CREATE TABLE t1(a);
      INSERT INTO t1 VALUES(randstr(1000,1000));
      INSERT INTO t1 VALUES(randstr(1000,1000));
      INSERT INTO t1 VALUES(randstr(1000,1000));
    }
    set before [db one {PRAGMA page_count}]

    execsql { DELETE FROM t1 }
    set after [db one {PRAGMA page_count}]
    expr {$before>$after}

  } {1}
}

} ;# ifcapable memorydb

finish_test

Changes to test/memsubsys1.test.

71
72
73
74
75
76
77

78
79
80
81
82
83
84
...
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
...
308
309
310
311
312
313
314

315
316
317
set xtra_size 290

# Test 1:  Both PAGECACHE and SCRATCH are shut down.
#
db close
sqlite3_shutdown
sqlite3_config_lookaside 0 0

sqlite3_initialize
reset_highwater_marks
build_test_db memsubsys1-1 {PRAGMA page_size=1024}
do_test memsubsys1-1.3 {
  set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
} 0
do_test memsubsys1-1.4 {
................................................................................

# Test 3:  Activate PAGECACHE with 20 pages but use the wrong page size
# so that PAGECACHE is not used.
#
db close
sqlite3_shutdown
sqlite3_config_pagecache [expr 512+$xtra_size] 20

sqlite3_initialize
reset_highwater_marks
build_test_db memsubsys1-3.1 {PRAGMA page_size=1024}
#show_memstats
do_test memsubsys1-3.1.3 {
  set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
} 0
do_test memsubsys1-3.1.4 {
  set overflow [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
  # Note:  The measured PAGECACHE_OVERFLOW is amount malloc() returns, not what
  # was requested.  System malloc() implementations might (arbitrarily) return
................................................................................

db close
sqlite3_shutdown
sqlite3_config_memstatus 1
sqlite3_config_pagecache 0 0
sqlite3_config_scratch 0 0
sqlite3_config_lookaside 100 500

sqlite3_initialize
autoinstall_test_functions
finish_test







>







 







>



<







 







>



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
112
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
...
309
310
311
312
313
314
315
316
317
318
319
set xtra_size 290

# Test 1:  Both PAGECACHE and SCRATCH are shut down.
#
db close
sqlite3_shutdown
sqlite3_config_lookaside 0 0
sqlite3_config_pagecache 0 0
sqlite3_initialize
reset_highwater_marks
build_test_db memsubsys1-1 {PRAGMA page_size=1024}
do_test memsubsys1-1.3 {
  set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
} 0
do_test memsubsys1-1.4 {
................................................................................

# Test 3:  Activate PAGECACHE with 20 pages but use the wrong page size
# so that PAGECACHE is not used.
#
db close
sqlite3_shutdown
sqlite3_config_pagecache [expr 512+$xtra_size] 20
sqlite3_config singlethread
sqlite3_initialize
reset_highwater_marks
build_test_db memsubsys1-3.1 {PRAGMA page_size=1024}

do_test memsubsys1-3.1.3 {
  set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
} 0
do_test memsubsys1-3.1.4 {
  set overflow [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
  # Note:  The measured PAGECACHE_OVERFLOW is amount malloc() returns, not what
  # was requested.  System malloc() implementations might (arbitrarily) return
................................................................................

db close
sqlite3_shutdown
sqlite3_config_memstatus 1
sqlite3_config_pagecache 0 0
sqlite3_config_scratch 0 0
sqlite3_config_lookaside 100 500
sqlite3_config serialized
sqlite3_initialize
autoinstall_test_functions
finish_test

Changes to test/pcache2.test.

20
21
22
23
24
25
26

27
28
29
30
31
32
33
..
69
70
71
72
73
74
75

76
77
78
79
# pages are being used for cache.
#
do_test pcache2-1.1 {
  db close
  sqlite3_reset_auto_extension
  sqlite3_shutdown
  sqlite3_config_pagecache 6000 100

  sqlite3_initialize
  autoinstall_test_functions
  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1
  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
} {0 0 0}

# Open up two database connections to separate files.
................................................................................
} {0 13 13}

db close
catch {db2 close}
sqlite3_reset_auto_extension
sqlite3_shutdown
sqlite3_config_pagecache 0 0

sqlite3_initialize
autoinstall_test_functions

finish_test







>







 







>




20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
70
71
72
73
74
75
76
77
78
79
80
81
# pages are being used for cache.
#
do_test pcache2-1.1 {
  db close
  sqlite3_reset_auto_extension
  sqlite3_shutdown
  sqlite3_config_pagecache 6000 100
  sqlite3_config singlethread
  sqlite3_initialize
  autoinstall_test_functions
  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1
  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
} {0 0 0}

# Open up two database connections to separate files.
................................................................................
} {0 13 13}

db close
catch {db2 close}
sqlite3_reset_auto_extension
sqlite3_shutdown
sqlite3_config_pagecache 0 0
sqlite3_config serialized
sqlite3_initialize
autoinstall_test_functions

finish_test