Hi Clemens, Thanks for your help!
On Sat, Jan 14, 2017 at 9:54 AM, Clemens Ladisch <clem...@ladisch.de> wrote: > Kim Gräsman wrote: >> I would expect SQLite to allocate a page cache per session. > > There is typically one page cache instance per connection. > (A connection is what you get from sqlite3_open*(); a session would be > what you get from sqlite3session_create().) Oh, I thought I'd seen 'session' somewhere, so went with that. Sorry about the confusion. >> So if we want to use SQLITE_CONFIG_PAGECACHE to provide a >> preallocated buffer for the page cache, it looks like we have to >> provide it for the worst case, i.e. max(page size) * sum(cache >> requirements for all sessions). Is that the case? > > Yes; the SQLITE_CONFIG_PAGECACHE memory is used by all cache instances. > >> is SQLITE_CONFIG_PAGECACHE used to specify an arena for page caches, >> or a buffer for pages between all sessions? > > A page cache instance is a list of pages; memory for each page is > allocated individually. ... from the buffer provided to SQLITE_CONFIG_PAGECACHE, right? Great, that confirms our suspicion. >> Since we have different page sizes (512 bytes and 4K respectively) I'm >> worried we'll have lots of dead space if SQLITE_CONFIG_PAGECACHE is >> set up for 4K pages and requests for 512-byte pages are served from >> there directly. > > If your use case is more complex than the simple mechanism offered by > SQLITE_CONFIG_PAGECACHE, consider using SQLITE_CONFIG_PCACHE2 (or > SQLITE_CONFIG_MALLOC). As for SQLITE_CONFIG_MALLOC, we were considering using that to configure a fixed-size arena for everything not covered by scratch + page cache. Not sure if it's even necessary. SQLITE_CONFIG_PCACHE2 looks comparatively difficult to get right, but I guess it would allow us to keep two arenas, one for 512-byte pages and one for 4K pages. Are these reasonable approaches? Also, having thought some more about this... The places where the docs warn that a page cache instance will fall back on sqlite3_malloc -- if the size of SQLITE_CONFIG_PAGECACHE is configured smaller than the cache sizes actually requested by connections, will every excess page allocation hit sqlite3_malloc? Many thanks, - Kim _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users