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

Unified Diff: content/common/discardable_shared_memory_heap.h

Issue 981403002: content: Release all free discardable memory when idle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing include Created 5 years, 9 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: content/common/discardable_shared_memory_heap.h
diff --git a/content/common/discardable_shared_memory_heap.h b/content/common/discardable_shared_memory_heap.h
index 0c7f5a428c9b6fbba93042ea429fb8adeb2fd0e5..d32f3d6ccb90e4ac0085395d2a3dfbf659d47542 100644
--- a/content/common/discardable_shared_memory_heap.h
+++ b/content/common/discardable_shared_memory_heap.h
@@ -5,13 +5,12 @@
#ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
#define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
-#include <bitset>
+#include <vector>
#include "base/containers/hash_tables.h"
#include "base/containers/linked_list.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
#include "content/common/content_export.h"
namespace base {
@@ -50,10 +49,10 @@ class CONTENT_EXPORT DiscardableSharedMemoryHeap {
~DiscardableSharedMemoryHeap();
// Grow heap using |shared_memory| and return a span for this new memory.
- // |shared_memory| must be aligned to the block size and |size| must be a
+ // |shared_memory| must be aligned to the block size and size must be a
Avi (use Gerrit) 2015/03/09 16:03:37 What size?
reveman 2015/03/09 18:08:26 DiscardableSharedMemory::mapped_size(), but I rein
// multiple of the block size.
- scoped_ptr<Span> Grow(scoped_ptr<base::DiscardableSharedMemory> shared_memory,
- size_t size);
+ scoped_ptr<Span> Grow(
+ scoped_ptr<base::DiscardableSharedMemory> shared_memory);
// Merge |span| into the free list. This will coalesce |span| with
// neighboring spans in free list when possible.
@@ -68,21 +67,49 @@ class CONTENT_EXPORT DiscardableSharedMemoryHeap {
// memory. If found, the span is removed from the free list and returned.
scoped_ptr<Span> SearchFreeList(size_t blocks);
- // Release shared memory segments that have been purged. Returns bytes of
- // memory that were released.
- size_t ReleaseFreeMemory();
+ // Release free shared memory segments.
+ void ReleaseFreeMemory();
+
+ // Release shared memory segments that have been purged.
+ void ReleasePurgedMemory();
+
+ // Returns total bytes of memory in heap.
+ size_t GetSize() const;
+
+ // Returns bytes of memory currently in the free list.
+ size_t GetFreeListSize() const;
private:
+ class ScopedMemorySegment {
+ public:
+ ScopedMemorySegment(scoped_ptr<base::DiscardableSharedMemory> shared_memory,
+ DiscardableSharedMemoryHeap* heap);
+ ~ScopedMemorySegment();
+
+ bool IsUsed() const;
+ bool IsResident() const;
+
+ private:
+ scoped_ptr<base::DiscardableSharedMemory> shared_memory_;
+ DiscardableSharedMemoryHeap* heap_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment);
+ };
+
scoped_ptr<Span> RemoveFromFreeList(Span* span);
scoped_ptr<Span> Carve(Span* span, size_t blocks);
void RegisterSpan(Span* span);
void UnregisterSpan(Span* span);
- void ReleaseMemory(base::DiscardableSharedMemory* shared_memory);
+ bool IsMemoryUsed(const base::DiscardableSharedMemory* shared_memory);
+ bool IsMemoryResident(const base::DiscardableSharedMemory* shared_memory);
+ void ReleaseMemory(const base::DiscardableSharedMemory* shared_memory);
size_t block_size_;
+ size_t num_blocks_;
+ size_t num_free_blocks_;
- // Discardable shared memory instances.
- ScopedVector<base::DiscardableSharedMemory> shared_memory_segments_;
+ // Vector of memory segments.
+ std::vector<linked_ptr<ScopedMemorySegment>> memory_segments_;
Avi (use Gerrit) 2015/03/09 16:03:37 Why are you switching to linked_ptr? ScopedVector
Avi (use Gerrit) 2015/03/09 17:21:25 http://crbug.com/137767
reveman 2015/03/09 18:08:26 I used linked_ptr as it's not spec compliant to us
// Mapping from first/last block of span to Span instance.
typedef base::hash_map<size_t, Span*> SpanMap;

Powered by Google App Engine
This is Rietveld 408576698