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

Side by Side Diff: storage/browser/blob/blob_memory_controller.h

Issue 2552153002: [BlobStorage] Enabling disk paging and direct storage. (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_MEMORY_CONTROLLER_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_MEMORY_CONTROLLER_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_MEMORY_CONTROLLER_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_MEMORY_CONTROLLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <unordered_map> 14 #include <unordered_map>
15 #include <unordered_set> 15 #include <unordered_set>
16 #include <utility> 16 #include <utility>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/callback.h" 19 #include "base/callback_forward.h"
20 #include "base/callback_helpers.h" 20 #include "base/callback_helpers.h"
21 #include "base/containers/mru_cache.h" 21 #include "base/containers/mru_cache.h"
22 #include "base/files/file.h" 22 #include "base/files/file.h"
23 #include "base/files/file_path.h" 23 #include "base/files/file_path.h"
24 #include "base/macros.h" 24 #include "base/macros.h"
25 #include "base/memory/ref_counted.h" 25 #include "base/memory/ref_counted.h"
26 #include "base/memory/weak_ptr.h" 26 #include "base/memory/weak_ptr.h"
27 #include "base/optional.h" 27 #include "base/optional.h"
28 #include "base/time/time.h" 28 #include "base/time/time.h"
29 #include "storage/browser/storage_browser_export.h" 29 #include "storage/browser/storage_browser_export.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 std::vector<scoped_refptr<ShareableBlobDataItem>> unreserved_file_items, 150 std::vector<scoped_refptr<ShareableBlobDataItem>> unreserved_file_items,
151 const FileQuotaRequestCallback& done_callback); 151 const FileQuotaRequestCallback& done_callback);
152 152
153 // Called when initially populated or upon later access. 153 // Called when initially populated or upon later access.
154 void NotifyMemoryItemsUsed( 154 void NotifyMemoryItemsUsed(
155 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items); 155 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items);
156 156
157 size_t memory_usage() const { return blob_memory_used_; } 157 size_t memory_usage() const { return blob_memory_used_; }
158 uint64_t disk_usage() const { return disk_used_; } 158 uint64_t disk_usage() const { return disk_used_; }
159 159
160 // Schedules a task on the file runner to calculate blob storage quota limits.
161 void CalculateBlobStorageLimits();
162
163 base::WeakPtr<BlobMemoryController> GetWeakPtr();
164
160 const BlobStorageLimits& limits() const { return limits_; } 165 const BlobStorageLimits& limits() const { return limits_; }
161 void set_limits_for_testing(const BlobStorageLimits& limits) { 166 void set_limits_for_testing(const BlobStorageLimits& limits) {
167 manual_limits_set_ = true;
162 limits_ = limits; 168 limits_ = limits;
163 } 169 }
164 170
165 private: 171 private:
166 class FileQuotaAllocationTask; 172 class FileQuotaAllocationTask;
167 class MemoryQuotaAllocationTask; 173 class MemoryQuotaAllocationTask;
168 174
169 using PendingMemoryQuotaTaskList = 175 using PendingMemoryQuotaTaskList =
170 std::list<std::unique_ptr<MemoryQuotaAllocationTask>>; 176 std::list<std::unique_ptr<MemoryQuotaAllocationTask>>;
171 using PendingFileQuotaTaskList = 177 using PendingFileQuotaTaskList =
172 std::list<std::unique_ptr<FileQuotaAllocationTask>>; 178 std::list<std::unique_ptr<FileQuotaAllocationTask>>;
173 179
180 void OnStorageLimitsCalculated(BlobStorageLimits limits);
181
174 base::WeakPtr<QuotaAllocationTask> AppendMemoryTask( 182 base::WeakPtr<QuotaAllocationTask> AppendMemoryTask(
175 uint64_t total_bytes_needed, 183 uint64_t total_bytes_needed,
176 std::vector<scoped_refptr<ShareableBlobDataItem>> unreserved_memory_items, 184 std::vector<scoped_refptr<ShareableBlobDataItem>> unreserved_memory_items,
177 const MemoryQuotaRequestCallback& done_callback); 185 const MemoryQuotaRequestCallback& done_callback);
178 186
179 void MaybeGrantPendingMemoryRequests(); 187 void MaybeGrantPendingMemoryRequests();
180 188
181 size_t CollectItemsForEviction( 189 size_t CollectItemsForEviction(
182 std::vector<scoped_refptr<ShareableBlobDataItem>>* output); 190 std::vector<scoped_refptr<ShareableBlobDataItem>>* output);
183 191
(...skipping 19 matching lines...) Expand all
203 // This is registered as a callback for file deletions on the file reference 211 // This is registered as a callback for file deletions on the file reference
204 // of our paging files. We decrement the disk space used. 212 // of our paging files. We decrement the disk space used.
205 void OnBlobFileDelete(uint64_t size, const base::FilePath& path); 213 void OnBlobFileDelete(uint64_t size, const base::FilePath& path);
206 214
207 base::FilePath GenerateNextPageFileName(); 215 base::FilePath GenerateNextPageFileName();
208 216
209 // This records diagnostic counters of our memory quotas. Called when usage 217 // This records diagnostic counters of our memory quotas. Called when usage
210 // changes. 218 // changes.
211 void RecordTracingCounters() const; 219 void RecordTracingCounters() const;
212 220
221 // Store that we set manual limits so we don't accidentally override them with
222 // our configuration task.
223 bool manual_limits_set_ = false;
213 BlobStorageLimits limits_; 224 BlobStorageLimits limits_;
214 225
215 // Memory bookkeeping. These numbers are all disjoint. 226 // Memory bookkeeping. These numbers are all disjoint.
216 // This is the amount of memory we're using for blobs in RAM, including the 227 // This is the amount of memory we're using for blobs in RAM, including the
217 // in_flight_memory_used_. 228 // in_flight_memory_used_.
218 size_t blob_memory_used_ = 0; 229 size_t blob_memory_used_ = 0;
219 // This is memory we're temporarily using while we try to write blob items to 230 // This is memory we're temporarily using while we try to write blob items to
220 // disk. 231 // disk.
221 size_t in_flight_memory_used_ = 0; 232 size_t in_flight_memory_used_ = 0;
222 // This is the amount of memory we're using on disk. 233 // This is the amount of memory we're using on disk.
(...skipping 20 matching lines...) Expand all
243 // another blob successfully grabs a ref, we can prevent it from adding the 254 // another blob successfully grabs a ref, we can prevent it from adding the
244 // item to the recent_item_cache_ above. 255 // item to the recent_item_cache_ above.
245 std::unordered_set<uint64_t> items_paging_to_file_; 256 std::unordered_set<uint64_t> items_paging_to_file_;
246 257
247 base::WeakPtrFactory<BlobMemoryController> weak_factory_; 258 base::WeakPtrFactory<BlobMemoryController> weak_factory_;
248 259
249 DISALLOW_COPY_AND_ASSIGN(BlobMemoryController); 260 DISALLOW_COPY_AND_ASSIGN(BlobMemoryController);
250 }; 261 };
251 } // namespace storage 262 } // namespace storage
252 #endif // STORAGE_BROWSER_BLOB_BLOB_MEMORY_CONTROLLER_H_ 263 #endif // STORAGE_BROWSER_BLOB_BLOB_MEMORY_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698