Skip to content

Commit

Permalink
[sqlite] use mmap
Browse files Browse the repository at this point in the history
Summary:
SQLite can use memory-mapped databases, which can improve read performance (only read due to the way it's used in SQLite).

This is exposed via a command line parameter that defaults to enabled for Linux/Darwin and disabled for Windows (untested).

Reviewed By: jvillard

Differential Revision:
D50228601

Privacy Context Container: L1122176

fbshipit-source-id: 8e42d3bb66a07851b6bfc210eec5170983508886
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Oct 17, 2023
1 parent d6a7bd6 commit 718eb62
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions infer/man/man1/infer-analyze.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ OPTIONS
--sqlite-max-blob-size int
Maximum blob/string size for data written in SQLite.

--sqlite-mmap-size int
Size of memory map for mmaped SQLite databases, zero value
disables memory mapping.

--sqlite-page-size int
SQLite page size in bytes, must be a power of two between 512 and
65536.
Expand Down
4 changes: 4 additions & 0 deletions infer/man/man1/infer-capture.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ OPTIONS
--sqlite-max-blob-size int
Maximum blob/string size for data written in SQLite.

--sqlite-mmap-size int
Size of memory map for mmaped SQLite databases, zero value
disables memory mapping.

--sqlite-page-size int
SQLite page size in bytes, must be a power of two between 512 and
65536.
Expand Down
4 changes: 4 additions & 0 deletions infer/man/man1/infer-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,10 @@ OPTIONS
Maximum blob/string size for data written in SQLite.
See also infer-analyze(1), infer-capture(1), and infer-run(1).

--sqlite-mmap-size int
Size of memory map for mmaped SQLite databases, zero value
disables memory mapping. See also infer-analyze(1), infer-capture(1), and infer-run(1).

--sqlite-page-size int
SQLite page size in bytes, must be a power of two between 512 and
65536. See also infer-analyze(1), infer-capture(1), and infer-run(1).
Expand Down
4 changes: 4 additions & 0 deletions infer/man/man1/infer-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ OPTIONS
--sqlite-max-blob-size int
Maximum blob/string size for data written in SQLite.

--sqlite-mmap-size int
Size of memory map for mmaped SQLite databases, zero value
disables memory mapping.

--sqlite-page-size int
SQLite page size in bytes, must be a power of two between 512 and
65536.
Expand Down
4 changes: 4 additions & 0 deletions infer/man/man1/infer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,10 @@ OPTIONS
Maximum blob/string size for data written in SQLite.
See also infer-analyze(1), infer-capture(1), and infer-run(1).

--sqlite-mmap-size int
Size of memory map for mmaped SQLite databases, zero value
disables memory mapping. See also infer-analyze(1), infer-capture(1), and infer-run(1).

--sqlite-page-size int
SQLite page size in bytes, must be a power of two between 512 and
65536. See also infer-analyze(1), infer-capture(1), and infer-run(1).
Expand Down
16 changes: 16 additions & 0 deletions infer/src/base/Config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3280,6 +3280,20 @@ and sqlite_max_blob_size =
"Maximum blob/string size for data written in SQLite."


and sqlite_mmap_size =
let default =
match Version.build_platform with
| Windows ->
0 (* disable as untested *)
| Linux | Darwin ->
256 * 1024 * 1024 (* 256 Mb, see https://www.sqlite.org/mmap.html *)
in
CLOpt.mk_int ~long:"sqlite-mmap-size" ~default
~in_help:
InferCommand.[(Analyze, manual_generic); (Capture, manual_generic); (Run, manual_generic)]
"Size of memory map for mmaped SQLite databases, zero value disables memory mapping."


and sqlite_vfs = CLOpt.mk_string_opt ~long:"sqlite-vfs" "VFS for SQLite"

and subtype_multirange =
Expand Down Expand Up @@ -4518,6 +4532,8 @@ and sqlite_lock_timeout = !sqlite_lock_timeout

and sqlite_max_blob_size = !sqlite_max_blob_size

and sqlite_mmap_size = !sqlite_mmap_size

and sqlite_vfs = !sqlite_vfs

and starvation_skip_analysis = !starvation_skip_analysis
Expand Down
2 changes: 2 additions & 0 deletions infer/src/base/Config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ val sqlite_lock_timeout : int

val sqlite_max_blob_size : int

val sqlite_mmap_size : int

val sqlite_vfs : string option

val starvation_skip_analysis : Yojson.Basic.t
Expand Down
2 changes: 2 additions & 0 deletions infer/src/base/Database.ml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ end = struct
db_path
in
Sqlite3.busy_timeout db Config.sqlite_lock_timeout ;
SqliteUtils.exec db ~log:"mmap"
~stmt:(Printf.sprintf "PRAGMA mmap_size=%d" Config.sqlite_mmap_size) ;
SqliteUtils.exec db ~log:"synchronous=OFF" ~stmt:"PRAGMA synchronous=OFF" ;
SqliteUtils.exec db ~log:"sqlite cache size"
~stmt:(Printf.sprintf "PRAGMA cache_size=%i" Config.sqlite_cache_size) ;
Expand Down

0 comments on commit 718eb62

Please sign in to comment.