summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 15:59:10 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 15:59:10 +0000
commit6b50fec83127803432211052f4127659c0f8408e (patch)
treeb9939a095a570930d1311e51c6b8281e90c6d3b5 /third_party
parenteb993e2b3c376067a62e614f733c24b2027b4ead (diff)
downloadchromium_src-6b50fec83127803432211052f4127659c0f8408e.zip
chromium_src-6b50fec83127803432211052f4127659c0f8408e.tar.gz
chromium_src-6b50fec83127803432211052f4127659c0f8408e.tar.bz2
The preloading code allocates a ton of memory, loads everything in, goes through the pager, then deallocates the memory. It was previous just using malloc() and free(). This means it goes through heap allocate, which decides that large allocations (larger than ~500k) should get their own memory, and it calls VirtualAlloc(). However, it does this while holding the heap lock, meaning all other threads block their heap operations until the memory is allocated. Instead, since we know these allocations are likely to be large, just get raw pages from the OS directly.
Review URL: http://codereview.chromium.org/8935 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/sqlite/pager.c27
-rw-r--r--third_party/sqlite/preload-cache.patch23
2 files changed, 46 insertions, 4 deletions
diff --git a/third_party/sqlite/pager.c b/third_party/sqlite/pager.c
index b2d16158..aac6d059 100644
--- a/third_party/sqlite/pager.c
+++ b/third_party/sqlite/pager.c
@@ -4451,6 +4451,27 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){
#endif
/**
+** 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
+** the allocation will be large, go directly to the OS instead of the heap.
+**/
+static void* allocLarge(size_t size) {
+#ifdef OS_WIN
+ return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+#else
+ return sqliteMallocRaw(size);
+#endif
+}
+
+static void freeLarge(void* ptr) {
+#ifdef OS_WIN
+ VirtualFree(ptr, 0, MEM_RELEASE);
+#else
+ sqliteFree(ptr);
+#endif
+}
+
+/**
** Addition: This will attempt to populate the database cache with
** the first N bytes of the file, where N is the total size of the cache.
** Because we can load this as one chunk from the disk, this is much faster
@@ -4485,12 +4506,12 @@ int sqlite3PagerLoadall(Pager* pPager)
return rc;
/* load the file as one chunk */
- fileData = sqliteMallocRaw(loadSize);
+ fileData = allocLarge(loadSize);
if (! fileData)
return SQLITE_NOMEM;
rc = sqlite3OsRead(pPager->fd, fileData, loadSize);
if (rc != SQLITE_OK) {
- sqliteFree(fileData);
+ freeLarge(fileData);
return rc;
}
@@ -4508,7 +4529,7 @@ int sqlite3PagerLoadall(Pager* pPager)
break;
sqlite3PagerUnref(pPage);
}
- sqliteFree(fileData);
+ freeLarge(fileData);
return SQLITE_OK;
}
diff --git a/third_party/sqlite/preload-cache.patch b/third_party/sqlite/preload-cache.patch
index 3601a4b..d11e763 100644
--- a/third_party/sqlite/preload-cache.patch
+++ b/third_party/sqlite/preload-cache.patch
@@ -151,11 +151,32 @@ Index: pager.c
}
pPg->needRead = 0;
}
-@@ -4416,6 +4450,68 @@
+@@ -4416,6 +4450,89 @@
}
#endif
+/**
++** 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
++** the allocation will be large, go directly to the OS instead of the heap.
++**/
++static void* allocLarge(size_t size) {
++#ifdef OS_WIN
++ return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
++#else
++ return sqliteMallocRaw(size);
++#endif
++}
++
++static void freeLarge(void* ptr) {
++#ifdef OS_WIN
++ VirtualFree(ptr, 0, MEM_RELEASE);
++#else
++ sqliteFree(ptr);
++#endif
++}
++
++/**
+** Addition: This will attempt to populate the database cache with
+** the first N bytes of the file, where N is the total size of the cache.
+** Because we can load this as one chunk from the disk, this is much faster