Bug 836039 - Reduce cache size per SQLite connection to 2MB

r=asuth
This commit is contained in:
Marco Bonardo 2013-02-21 11:12:48 +01:00
parent 8e78198f97
commit efeb14948c
3 changed files with 8 additions and 32 deletions

View File

@ -43,12 +43,8 @@
#define MIN_AVAILABLE_BYTES_PER_CHUNKED_GROWTH 524288000 // 500 MiB
// Maximum size of the pages cache per connection. If the default cache_size
// value evaluates to a larger size, it will be reduced to save memory.
#define MAX_CACHE_SIZE_BYTES 4194304 // 4 MiB
// Default maximum number of pages to allow in the connection pages cache.
#define DEFAULT_CACHE_SIZE_PAGES 2000
// Maximum size of the pages cache per connection.
#define MAX_CACHE_SIZE_KIBIBYTES 2048 // 2 MiB
#ifdef PR_LOGGING
PRLogModuleInfo* gStorageLog = nullptr;
@ -576,26 +572,13 @@ Connection::initializeInternal(nsIFile* aDatabaseFile)
nsresult rv = ExecuteSimpleSQL(pageSizeQuery);
NS_ENSURE_SUCCESS(rv, rv);
// Get the current page_size, since it may differ from the specified value.
sqlite3_stmt *stmt;
NS_NAMED_LITERAL_CSTRING(pragma_page_size,
MOZ_STORAGE_UNIQUIFY_QUERY_STR "PRAGMA page_size");
int srv = prepareStatement(pragma_page_size, &stmt);
if (srv == SQLITE_OK) {
if (SQLITE_ROW == stepStatement(stmt)) {
pageSize = ::sqlite3_column_int64(stmt, 0);
}
(void)::sqlite3_finalize(stmt);
}
// Setting the cache_size forces the database open, verifying if it is valid
// or corrupt. So this is executed regardless it being actually needed.
// The cache_size is calculated from the actual page_size, to save memory.
nsAutoCString cacheSizeQuery(MOZ_STORAGE_UNIQUIFY_QUERY_STR
"PRAGMA cache_size = ");
cacheSizeQuery.AppendInt(std::min(DEFAULT_CACHE_SIZE_PAGES,
int32_t(MAX_CACHE_SIZE_BYTES / pageSize)));
srv = executeSql(cacheSizeQuery.get());
cacheSizeQuery.AppendInt(-MAX_CACHE_SIZE_KIBIBYTES);
int srv = executeSql(cacheSizeQuery.get());
if (srv != SQLITE_OK) {
::sqlite3_close(mDBConn);
mDBConn = nullptr;

View File

@ -54,12 +54,7 @@ function new_file(name)
function run_test()
{
// This is copied from the logic in Connection::initialize().
function cacheSize(pageSize) {
const DEFAULT_CACHE_SIZE_PAGES = 2000;
const MAX_CACHE_SIZE_BYTES = 4 * 1024 * 1024;
return Math.min(DEFAULT_CACHE_SIZE_PAGES, MAX_CACHE_SIZE_BYTES / pageSize);
}
const kExpectedCacheSize = -2048; // 2MiB
let pageSizes = [
1024,
@ -69,11 +64,9 @@ function run_test()
for (let i = 0; i < pageSizes.length; i++) {
let pageSize = pageSizes[i];
let expectedCacheSize = cacheSize(pageSize);
check_size(getDatabase,
new_file("shared" + pageSize), pageSize, expectedCacheSize);
new_file("shared" + pageSize), pageSize, kExpectedCacheSize);
check_size(getService().openUnsharedDatabase,
new_file("unshared" + pageSize), pageSize, expectedCacheSize);
new_file("unshared" + pageSize), pageSize, kExpectedCacheSize);
}
}

View File

@ -5,7 +5,7 @@
// This file tests that dbs are using 32k pagesize
const kExpectedPageSize = 32768; // 32K
const kExpectedCacheSize = 128; // (4MiB / 32KiB)
const kExpectedCacheSize = -2048; // 2MiB
function check_size(db)
{