Skip to content

Commit

Permalink
sql::Connection::Preload() loads fs cache, not page cache.
Browse files Browse the repository at this point in the history
In theory, the fs cache should be good enough for any cases where a
client uses things early in execution, and if not used memory usage
will be better.

BUG= 243949

Review URL: https://chromiumcodereview.appspot.com/16173004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204860 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
shess@chromium.org committed Jun 7, 2013
1 parent bd12ce6 commit aae71b1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
44 changes: 44 additions & 0 deletions third_party/sqlite/amalgamation/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -42925,6 +42925,49 @@ SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, i
#endif

/* Begin preload-cache.patch for Chromium */
#if 1
/* NOTE(shess): Testing to see if simply reading the data into the
* filesystem buffers will have the positive speed impact without the
* negative memory impact.
*/
SQLITE_PRIVATE int sqlite3PagerLoadall(Pager* pPager)
{
int i, pageSize, loadPages, rc;
unsigned char *fileData;

/* TODO(shess): This test may not be relevant for this
* implementation, but keep the invariant consistent.
*/
pageSize = pPager->pageSize;
if (pPager->dbSize < 0 || pageSize < 0) {
/* pager not initialized, this means a statement is not open */
return SQLITE_MISUSE;
}

/* Allocate a buffer to read pages into. */
/* TODO(shess): No need to read by page, this could be a fixed-size
* buffer on stack.
*/
fileData = sqlite3Malloc(pageSize);
if (!fileData)
return SQLITE_NOMEM;

/* Load the smaller of the entire cache or the entire database. */
loadPages = sqlite3PcacheGetCachesize(pPager->pPCache);
if (loadPages > pPager->dbSize)
loadPages = pPager->dbSize;

/* Read database page by page. */
rc = SQLITE_OK;
for(i=0; i < loadPages; i++) {
rc = sqlite3OsRead(pPager->fd, fileData, pageSize, i*pageSize);
if (rc != SQLITE_OK)
break;
}
sqlite3_free(fileData);
return rc;
}
#else
/**
** When making large allocations, there is no need to stress the heap and
** potentially hold its lock while we allocate a bunch of memory. If we know
Expand Down Expand Up @@ -43007,6 +43050,7 @@ SQLITE_PRIVATE int sqlite3PagerLoadall(Pager* pPager)
freeLarge(fileData);
return SQLITE_OK;
}
#endif
/* End preload-cache.patch for Chromium */

/*
Expand Down
44 changes: 44 additions & 0 deletions third_party/sqlite/src/src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -6497,6 +6497,49 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
#endif

/* Begin preload-cache.patch for Chromium */
#if 1
/* NOTE(shess): Testing to see if simply reading the data into the
* filesystem buffers will have the positive speed impact without the
* negative memory impact.
*/
int sqlite3PagerLoadall(Pager* pPager)
{
int i, pageSize, loadPages, rc;
unsigned char *fileData;

/* TODO(shess): This test may not be relevant for this
* implementation, but keep the invariant consistent.
*/
pageSize = pPager->pageSize;
if (pPager->dbSize < 0 || pageSize < 0) {
/* pager not initialized, this means a statement is not open */
return SQLITE_MISUSE;
}

/* Allocate a buffer to read pages into. */
/* TODO(shess): No need to read by page, this could be a fixed-size
* buffer on stack.
*/
fileData = sqlite3Malloc(pageSize);
if (!fileData)
return SQLITE_NOMEM;

/* Load the smaller of the entire cache or the entire database. */
loadPages = sqlite3PcacheGetCachesize(pPager->pPCache);
if (loadPages > pPager->dbSize)
loadPages = pPager->dbSize;

/* Read database page by page. */
rc = SQLITE_OK;
for(i=0; i < loadPages; i++) {
rc = sqlite3OsRead(pPager->fd, fileData, pageSize, i*pageSize);
if (rc != SQLITE_OK)
break;
}
sqlite3_free(fileData);
return rc;
}
#else
/**
** When making large allocations, there is no need to stress the heap and
** potentially hold its lock while we allocate a bunch of memory. If we know
Expand Down Expand Up @@ -6579,6 +6622,7 @@ int sqlite3PagerLoadall(Pager* pPager)
freeLarge(fileData);
return SQLITE_OK;
}
#endif
/* End preload-cache.patch for Chromium */

/*
Expand Down

0 comments on commit aae71b1

Please sign in to comment.