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

Unified Diff: base/memory/shared_memory_tracker.h

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Address on reviews Created 3 years, 11 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: base/memory/shared_memory_tracker.h
diff --git a/base/memory/shared_memory_tracker.h b/base/memory/shared_memory_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..afe51270e08e2e226b0d0dbb4b8d0e5d5755f1fc
--- /dev/null
+++ b/base/memory/shared_memory_tracker.h
@@ -0,0 +1,66 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
+#define BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
+
+#include "base/atomicops.h"
+#include "base/memory/shared_memory_handle.h"
+#include "base/memory/singleton.h"
+#include "base/trace_event/memory_dump_provider.h"
+
+namespace base {
+
+class SharedMemory;
+
+namespace trace_event {
+class ProcessMemoryDump;
+}
+
+// SharedMemoryTracker tracks shared memory usage.
+class BASE_EXPORT SharedMemoryTracker
+ : public base::trace_event::MemoryDumpProvider {
+ public:
+ // Returns a singleton instance.
+ static SharedMemoryTracker* GetInstance();
+
+ // base::trace_event::MemoryDumpProvider implementation.
+ bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) override;
+
+ // Records shared memory usage on mapping.
+ bool IncrementMemoryUsage(const SharedMemory& shared_memory);
Primiano Tucci (use gerrit) 2017/01/27 20:09:49 why this (and Decrement below) are bool? - it is n
hajimehoshi 2017/02/07 12:33:44 Done.
+
+ // Records shared memory usage on unmapping.
+ bool DecrementMemoryUsage(const SharedMemory& shared_memory);
+
+ private:
+ // TrackerBucket represents a group of shared memory handle ids and their
+ // usages. Shared memorys are split into these buckets instead of using one
+ // big unordered_map so that locking for exclusive control would occur much
+ // less often.
+ struct TrackerBucket {
+ TrackerBucket();
+ ~TrackerBucket();
+ base::Lock lock;
+ std::unordered_map<const SharedMemory*, size_t> usages;
+ };
+
+ friend struct base::DefaultSingletonTraits<SharedMemoryTracker>;
+
+ // TODO(hajimehoshi): Update this number based on actual performance
+ // measurements.
+ static const int kTrackerBucketNum = 1024;
+
+ SharedMemoryTracker();
+ ~SharedMemoryTracker() override;
+
+ TrackerBucket buckets_[kTrackerBucketNum];
Primiano Tucci (use gerrit) 2017/01/27 20:09:49 nit: this should go up to line 55. functions / ct
hajimehoshi 2017/02/07 12:33:44 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
+};
+
+} // namespace base
+
+#endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_

Powered by Google App Engine
This is Rietveld 408576698