Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "storage/browser/blob/blob_memory_controller.h" | 5 #include "storage/browser/blob/blob_memory_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 using MemoryAllocation = BlobMemoryController::MemoryAllocation; | 46 using MemoryAllocation = BlobMemoryController::MemoryAllocation; |
| 47 using QuotaAllocationTask = BlobMemoryController::QuotaAllocationTask; | 47 using QuotaAllocationTask = BlobMemoryController::QuotaAllocationTask; |
| 48 using DiskSpaceFuncPtr = BlobMemoryController::DiskSpaceFuncPtr; | 48 using DiskSpaceFuncPtr = BlobMemoryController::DiskSpaceFuncPtr; |
| 49 | 49 |
| 50 // CrOS: | 50 // CrOS: |
| 51 // * Ram - 20% | 51 // * Ram - 20% |
| 52 // * Disk - 50% | 52 // * Disk - 50% |
| 53 // Note: The disk is the user partition, so the operating system can still | 53 // Note: The disk is the user partition, so the operating system can still |
| 54 // function if this is full. | 54 // function if this is full. |
| 55 // Android: | 55 // Android: |
| 56 // * RAM - 20% | 56 // * RAM - 1% |
| 57 // * Disk - 5% | 57 // * Disk - 6% |
| 58 // Desktop: | 58 // Desktop: |
| 59 // * Ram - 20%, or 2 GB if x64. | 59 // * Ram - 20%, or 2 GB if x64. |
| 60 // * Disk - 10% | 60 // * Disk - 10% |
| 61 BlobStorageLimits CalculateBlobStorageLimitsImpl(const FilePath& storage_dir, | 61 BlobStorageLimits CalculateBlobStorageLimitsImpl(const FilePath& storage_dir, |
| 62 bool disk_enabled) { | 62 bool disk_enabled) { |
| 63 int64_t disk_size = | 63 int64_t disk_size = |
| 64 disk_enabled ? base::SysInfo::AmountOfTotalDiskSpace(storage_dir) : 0ull; | 64 disk_enabled ? base::SysInfo::AmountOfTotalDiskSpace(storage_dir) : 0ull; |
| 65 int64_t memory_size = base::SysInfo::AmountOfPhysicalMemory(); | 65 int64_t memory_size = base::SysInfo::AmountOfPhysicalMemory(); |
| 66 | 66 |
| 67 BlobStorageLimits limits; | 67 BlobStorageLimits limits; |
| 68 | 68 |
| 69 // Don't do specialty configuration for error size (-1). | 69 // Don't do specialty configuration for error size (-1). |
| 70 if (memory_size > 0) { | 70 if (memory_size > 0) { |
| 71 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && defined(ARCH_CPU_64_BITS) | 71 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && defined(ARCH_CPU_64_BITS) |
| 72 constexpr size_t kTwoGigabytes = 2ull * 1024 * 1024 * 1024; | 72 constexpr size_t kTwoGigabytes = 2ull * 1024 * 1024 * 1024; |
| 73 limits.max_blob_in_memory_space = kTwoGigabytes; | 73 limits.max_blob_in_memory_space = kTwoGigabytes; |
| 74 #elif defined(OS_ANDROID) | |
| 75 limits.max_blob_in_memory_space = static_cast<size_t>(memory_size / 100ll); | |
| 74 #else | 76 #else |
| 75 limits.max_blob_in_memory_space = static_cast<size_t>(memory_size / 5ll); | 77 limits.max_blob_in_memory_space = static_cast<size_t>(memory_size / 5ll); |
| 76 #endif | 78 #endif |
| 77 } | 79 } |
| 78 | 80 |
| 79 // Don't do specialty configuration for error size (-1). Allow no disk. | 81 // Don't do specialty configuration for error size (-1). Allow no disk. |
| 80 if (disk_size >= 0) { | 82 if (disk_size >= 0) { |
| 81 #if defined(OS_CHROMEOS) | 83 #if defined(OS_CHROMEOS) |
| 82 limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 2ll); | 84 limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 2ll); |
| 83 #elif defined(OS_ANDROID) | 85 #elif defined(OS_ANDROID) |
| 84 limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 20ll); | 86 limits.desired_max_disk_space = |
| 87 static_cast<uint64_t>(6 * disk_size / 1000ll); | |
|
dmurph
2017/05/03 21:58:19
How about doing "3ll * disk_size / 50" (6%, tries
| |
| 85 #else | 88 #else |
| 86 limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 10ll); | 89 limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 10ll); |
| 87 #endif | 90 #endif |
| 88 } | 91 } |
| 89 UMA_HISTOGRAM_COUNTS_1M("Storage.Blob.MaxDiskSpace", | 92 UMA_HISTOGRAM_COUNTS_1M("Storage.Blob.MaxDiskSpace", |
| 90 limits.desired_max_disk_space / kMegabyte); | 93 limits.desired_max_disk_space / kMegabyte); |
| 91 limits.effective_max_disk_space = limits.desired_max_disk_space; | 94 limits.effective_max_disk_space = limits.desired_max_disk_space; |
| 92 | 95 |
| 93 return limits; | 96 return limits; |
| 94 } | 97 } |
| (...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 975 MaybeGrantPendingMemoryRequests(); | 978 MaybeGrantPendingMemoryRequests(); |
| 976 } | 979 } |
| 977 | 980 |
| 978 void BlobMemoryController::OnBlobFileDelete(uint64_t size, | 981 void BlobMemoryController::OnBlobFileDelete(uint64_t size, |
| 979 const FilePath& path) { | 982 const FilePath& path) { |
| 980 DCHECK_LE(size, disk_used_); | 983 DCHECK_LE(size, disk_used_); |
| 981 disk_used_ -= size; | 984 disk_used_ -= size; |
| 982 } | 985 } |
| 983 | 986 |
| 984 } // namespace storage | 987 } // namespace storage |
| OLD | NEW |