Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: third_party/leveldatabase/env_chromium.cc

Issue 2243363002: IndexedDB: Limit the size of a leveldb write buffer to minimize disk space. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Eliminated overloaded WriteBufferSize. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/leveldatabase/env_chromium.h ('k') | third_party/leveldatabase/env_chromium_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/leveldatabase/env_chromium.cc
diff --git a/third_party/leveldatabase/env_chromium.cc b/third_party/leveldatabase/env_chromium.cc
index 54a9a902115935cdcdb1d27274ea64de090cde37..029f5f7d2e75e1e73c4445f4c4b0098e56cebc42 100644
--- a/third_party/leveldatabase/env_chromium.cc
+++ b/third_party/leveldatabase/env_chromium.cc
@@ -23,6 +23,7 @@
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/trace_event.h"
#include "third_party/leveldatabase/chromium_logger.h"
+#include "third_party/leveldatabase/src/include/leveldb/options.h"
#include "third_party/re2/src/re2/re2.h"
using base::FilePath;
@@ -491,6 +492,37 @@ bool IndicatesDiskFull(const leveldb::Status& status) {
base::File::FILE_ERROR_NO_SPACE);
}
+// Given the size of the disk, identified by |disk_size| in bytes, determine the
+// appropriate write_buffer_size. Ignoring snapshots, if the current set of
+// tables in a database contains a set of key/value pairs identified by {A}, and
+// a set of key/value pairs identified by {B} has been written and is in the log
+// file, then during compaction you will have {A} + {B} + {A, B} = 2A + 2B.
+// There is no way to know the size of A, so minimizing the size of B will
+// maximize the likelihood of a successful compaction.
+size_t WriteBufferSize(int64_t disk_size) {
+ const leveldb::Options default_options;
+ const int64_t kMinBufferSize = 1024 * 1024;
+ const int64_t kMaxBufferSize = default_options.write_buffer_size;
+ const int64_t kDiskMinBuffSize = 10 * 1024 * 1024;
+ const int64_t kDiskMaxBuffSize = 40 * 1024 * 1024;
+
+ if (disk_size == -1)
+ return default_options.write_buffer_size;
+
+ if (disk_size <= kDiskMinBuffSize)
+ return kMinBufferSize;
+
+ if (disk_size >= kDiskMaxBuffSize)
+ return kMaxBufferSize;
+
+ // A linear equation to intersect (kDiskMinBuffSize, kMinBufferSize) and
+ // (kDiskMaxBuffSize, kMaxBufferSize).
+ return static_cast<size_t>(
+ kMinBufferSize +
+ ((kMaxBufferSize - kMinBufferSize) * (disk_size - kDiskMinBuffSize)) /
+ (kDiskMaxBuffSize - kDiskMinBuffSize));
+}
+
ChromiumEnv::ChromiumEnv() : ChromiumEnv("LevelDBEnv") {}
ChromiumEnv::ChromiumEnv(const std::string& name)
« no previous file with comments | « third_party/leveldatabase/env_chromium.h ('k') | third_party/leveldatabase/env_chromium_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698