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

Side by Side Diff: net/ssl/ssl_client_session_cache.cc

Issue 2696403007: Add a multiplier in tracking certificate memory allocation size (Closed)
Patch Set: self Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | net/ssl/ssl_client_session_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "net/ssl/ssl_client_session_cache.h" 5 #include "net/ssl/ssl_client_session_cache.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/containers/flat_set.h"
9 #include "base/memory/memory_coordinator_client_registry.h" 10 #include "base/memory/memory_coordinator_client_registry.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "base/time/clock.h" 12 #include "base/time/clock.h"
12 #include "base/time/default_clock.h" 13 #include "base/time/default_clock.h"
13 #include "base/trace_event/process_memory_dump.h" 14 #include "base/trace_event/process_memory_dump.h"
14 #include "net/cert/x509_util_openssl.h" 15 #include "net/cert/x509_util_openssl.h"
15 #include "third_party/boringssl/src/include/openssl/ssl.h" 16 #include "third_party/boringssl/src/include/openssl/ssl.h"
16 #include "third_party/boringssl/src/include/openssl/x509.h" 17 #include "third_party/boringssl/src/include/openssl/x509.h"
17 18
18 namespace net { 19 namespace net {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 std::string absolute_name = "net/ssl_session_cache"; 116 std::string absolute_name = "net/ssl_session_cache";
116 base::trace_event::MemoryAllocatorDump* cache_dump = 117 base::trace_event::MemoryAllocatorDump* cache_dump =
117 pmd->GetAllocatorDump(absolute_name); 118 pmd->GetAllocatorDump(absolute_name);
118 // This method can be reached from different URLRequestContexts. Since this is 119 // This method can be reached from different URLRequestContexts. Since this is
119 // a singleton, only log memory stats once. 120 // a singleton, only log memory stats once.
120 // TODO(xunjieli): Change this once crbug.com/458365 is fixed. 121 // TODO(xunjieli): Change this once crbug.com/458365 is fixed.
121 if (cache_dump) 122 if (cache_dump)
122 return; 123 return;
123 cache_dump = pmd->CreateAllocatorDump(absolute_name); 124 cache_dump = pmd->CreateAllocatorDump(absolute_name);
124 base::AutoLock lock(lock_); 125 base::AutoLock lock(lock_);
125 size_t total_serialized_cert_size = 0; 126 size_t cert_size = 0;
126 size_t total_cert_count = 0; 127 size_t cert_count = 0;
128 size_t undeduped_cert_size = 0;
129 size_t undeduped_cert_count = 0;
130 for (const auto& pair : cache_) {
131 undeduped_cert_count +=
132 sk_CRYPTO_BUFFER_num(pair.second.session.get()->certs);
133 }
134 // Use a flat_set here to avoid malloc upon insertion.
135 base::flat_set<const CRYPTO_BUFFER*> crypto_buffer_set;
136 crypto_buffer_set.reserve(undeduped_cert_count);
127 for (const auto& pair : cache_) { 137 for (const auto& pair : cache_) {
128 const SSL_SESSION* session = pair.second.session.get(); 138 const SSL_SESSION* session = pair.second.session.get();
129 size_t cert_count = sk_CRYPTO_BUFFER_num(session->certs); 139 size_t pair_cert_count = sk_CRYPTO_BUFFER_num(session->certs);
130 total_cert_count += cert_count; 140 for (size_t i = 0; i < pair_cert_count; ++i) {
131 for (size_t i = 0; i < cert_count; ++i) {
132 const CRYPTO_BUFFER* cert = sk_CRYPTO_BUFFER_value(session->certs, i); 141 const CRYPTO_BUFFER* cert = sk_CRYPTO_BUFFER_value(session->certs, i);
133 total_serialized_cert_size += CRYPTO_BUFFER_len(cert); 142 // TODO(xunjieli): The multipler is added to account for the difference
143 // between the serialized form and real cert allocation. Remove after
144 // crbug.com/671420 is done.
145 size_t individual_cert_size = 4 * CRYPTO_BUFFER_len(cert);
146 undeduped_cert_size += individual_cert_size;
147 auto result = crypto_buffer_set.insert(cert);
148 if (!result.second)
149 continue;
150 cert_size += individual_cert_size;
151 cert_count++;
134 } 152 }
135 } 153 }
136 // This measures the lower bound of the serialized certificate. It doesn't 154 cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
137 // measure the actual memory used, which is 4x this amount (see
138 // crbug.com/671420 for more details).
139 cache_dump->AddScalar("serialized_cert_size",
140 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 155 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
141 total_serialized_cert_size); 156 cert_size);
157 cache_dump->AddScalar("cert_size",
158 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
159 cert_size);
142 cache_dump->AddScalar("cert_count", 160 cache_dump->AddScalar("cert_count",
143 base::trace_event::MemoryAllocatorDump::kUnitsObjects, 161 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
144 total_cert_count); 162 cert_count);
145 cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 163 cache_dump->AddScalar("undeduped_cert_size",
146 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 164 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
147 total_serialized_cert_size); 165 undeduped_cert_size);
166 cache_dump->AddScalar("undeduped_cert_count",
167 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
168 undeduped_cert_count);
148 } 169 }
149 170
150 SSLClientSessionCache::Entry::Entry() : lookups(0) {} 171 SSLClientSessionCache::Entry::Entry() : lookups(0) {}
151 SSLClientSessionCache::Entry::Entry(Entry&&) = default; 172 SSLClientSessionCache::Entry::Entry(Entry&&) = default;
152 SSLClientSessionCache::Entry::~Entry() = default; 173 SSLClientSessionCache::Entry::~Entry() = default;
153 174
154 void SSLClientSessionCache::FlushExpiredSessions() { 175 void SSLClientSessionCache::FlushExpiredSessions() {
155 time_t now = clock_->Now().ToTimeT(); 176 time_t now = clock_->Now().ToTimeT();
156 auto iter = cache_.begin(); 177 auto iter = cache_.begin();
157 while (iter != cache_.end()) { 178 while (iter != cache_.end()) {
(...skipping 17 matching lines...) Expand all
175 Flush(); 196 Flush();
176 break; 197 break;
177 } 198 }
178 } 199 }
179 200
180 void SSLClientSessionCache::OnPurgeMemory() { 201 void SSLClientSessionCache::OnPurgeMemory() {
181 Flush(); 202 Flush();
182 } 203 }
183 204
184 } // namespace net 205 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | net/ssl/ssl_client_session_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698