Shell page cache option not working (?)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Shell page cache option not working (?)

Aubrey Barnard
SQLite Users,

I'm experiencing unexpected behavior in trying to use the `-pagecache`
option for the `sqlite3` shell. Specifically, the `-pagecache` option
appears to have no effect even though `pragma cache_size` does. I can
see in the code that `-pagecache` causes an allocation which is stored
in the global configuration, so at this point I'm not sure what is
happening or what to do next.

For example:

$ ~/opt/bin/sqlite3 -pagecache 4096 1234 :memory: "pragma cache_size"
"pragma cache_size = -1000" "pragma cache_size"
Expected output:
-4936
-1000
Actual output:
-2000
-1000

$ ~/opt/bin/sqlite3 -pagecache 4096 1048576 :memory: "pragma cache_size"
"pragma cache_size = -1000" "pragma cache_size"
Expected output:
-4194304
-1000
Actual output:
Segmentation fault (core dumped)

$ ~/opt/bin/sqlite3 -pagecache 4096 1048575 :memory: "pragma cache_size"
"pragma cache_size = -1000" "pragma cache_size"
Expected output:
-4194300
-1000
Actual output:
-2000
-1000

The behavior is the same when using a DB file instead of `:memory:`.

Details:
uname -a: Linux <redacted> 3.10.0-862.14.4.el7.x86_64 #1 SMP Tue Sep 25
14:32:52 CDT 2018 x86_64 x86_64 x86_64 GNU/Linux
download: sqlite-amalgamation-3250300.zip
build: gcc -O3 -I. -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS4
-DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE
-DSQLITE_ENABLE_EXPLAIN_COMMENTS -DHAVE_USLEEP -DHAVE_READLINE
-DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_DBSTAT_VTAB shell.c sqlite3.c
-ldl -lpthread -lreadline -lncurses -o sqlite3
version: 3.25.3 2018-11-05 20:37:38
89e099fbe5e13c33e683bef07361231ca525b88f7907be7092058007b75036f2

Thank you very much for any help / suggestions / insights.

Aubrey
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Shell page cache option not working (?)

Richard Hipp-3
On 11/14/18, Aubrey Barnard <[hidden email]> wrote:
>
> $ ~/opt/bin/sqlite3 -pagecache 4096 1234 :memory: "pragma cache_size"
> "pragma cache_size = -1000" "pragma cache_size"
> Expected output:
> -4936
> -1000
> Actual output:
> -2000
> -1000

The PRAGMA cache_size=N sets a soft upper bound on the number of cache
buffers that will be used.  The -pagecache option uses
sqlite3_config(SQLITE_CONFIG_PAGECACHE) to use a separate memory
allocation as the initial memory pull from which to draw cache
buffers.  These are different things, and so one does not necessarily
change the other.

The PRAGMA cache_size=N is used to limit memory usage.

The SQLITE_CONFIG_PAGECACHE option is designed to reduce memory
fragmentation.  See
https://www.sqlite.org/malloc.html#_page_cache_memory for further
information on what that means and why it is important for some
systems.  (Hint: Unless you are working on a safety-critical embedded
system, this probably is not important to you.)

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users