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 = static_cast<uint64_t>(3ll * disk_size / 50); |
85 #else | 87 #else |
86 limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 10ll); | 88 limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 10ll); |
87 #endif | 89 #endif |
88 } | 90 } |
89 UMA_HISTOGRAM_COUNTS_1M("Storage.Blob.MaxDiskSpace", | 91 UMA_HISTOGRAM_COUNTS_1M("Storage.Blob.MaxDiskSpace", |
90 limits.desired_max_disk_space / kMegabyte); | 92 limits.desired_max_disk_space / kMegabyte); |
91 limits.effective_max_disk_space = limits.desired_max_disk_space; | 93 limits.effective_max_disk_space = limits.desired_max_disk_space; |
92 | 94 |
93 return limits; | 95 return limits; |
94 } | 96 } |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 MaybeGrantPendingMemoryRequests(); | 977 MaybeGrantPendingMemoryRequests(); |
976 } | 978 } |
977 | 979 |
978 void BlobMemoryController::OnBlobFileDelete(uint64_t size, | 980 void BlobMemoryController::OnBlobFileDelete(uint64_t size, |
979 const FilePath& path) { | 981 const FilePath& path) { |
980 DCHECK_LE(size, disk_used_); | 982 DCHECK_LE(size, disk_used_); |
981 disk_used_ -= size; | 983 disk_used_ -= size; |
982 } | 984 } |
983 | 985 |
984 } // namespace storage | 986 } // namespace storage |
OLD | NEW |