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

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: 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
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..264f8b32e8029f145c7c2ee8aebe768f2b81a0db 100644
--- a/third_party/leveldatabase/env_chromium.cc
+++ b/third_party/leveldatabase/env_chromium.cc
@@ -20,9 +20,11 @@
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/sys_info.h"
#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 +493,41 @@ 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));
+}
+
+size_t WriteBufferSize(const base::FilePath& path) {
+ return WriteBufferSize(base::SysInfo::AmountOfTotalDiskSpace(path));
+}
+
ChromiumEnv::ChromiumEnv() : ChromiumEnv("LevelDBEnv") {}
ChromiumEnv::ChromiumEnv(const std::string& name)

Powered by Google App Engine
This is Rietveld 408576698