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

Side by Side Diff: content/common/discardable_shared_memory_heap.h

Issue 807303002: base: Add free list implementation to browser-wide discardable memory system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@discardable-shared-memory-ashmem
Patch Set: add comment Created 6 years 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
7
8 #include <bitset>
9
10 #include "base/containers/hash_tables.h"
11 #include "base/containers/linked_list.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "content/common/content_export.h"
16
17 namespace base {
18 class DiscardableSharedMemory;
19 }
20
21 namespace content {
22
23 // Implements a heap of discardable shared memory. A free list is used to keep
24 // track of free blocks.
25 class CONTENT_EXPORT DiscardableSharedMemoryHeap {
26 public:
27 class Span : public base::LinkNode<Span> {
28 public:
29 ~Span();
30
31 base::DiscardableSharedMemory* shared_memory() {
32 return shared_memory_.get();
33 }
34 size_t start() const { return start_; }
35 size_t length() const { return length_; }
36
37 private:
38 friend class DiscardableSharedMemoryHeap;
39
40 Span(linked_ptr<base::DiscardableSharedMemory> shared_memory,
41 size_t start,
42 size_t length);
43
44 linked_ptr<base::DiscardableSharedMemory> shared_memory_;
45 size_t start_;
46 size_t length_;
47
48 DISALLOW_COPY_AND_ASSIGN(Span);
49 };
50
51 explicit DiscardableSharedMemoryHeap(size_t block_size);
52 ~DiscardableSharedMemoryHeap();
53
54 // Grow heap using |memory| and return a span for this new memory.
55 // |memory| must be aligned to the block size and |size| must be a
56 // multiple of the block size.
57 scoped_ptr<Span> Grow(scoped_ptr<base::DiscardableSharedMemory> memory,
58 size_t size);
59
60 // Merge |span| into the free list. This will coalesced |span| with
Avi (use Gerrit) 2014/12/18 20:49:06 coalesce
reveman 2014/12/18 21:30:44 Done.
61 // neighboring spans in free list when possible.
62 void MergeIntoFreeList(scoped_ptr<Span> span);
63
64 // Split an allocated span into two spans. One of length |blocks| followed
Avi (use Gerrit) 2014/12/18 20:49:06 "... into two spans, one of length ..."
reveman 2014/12/18 21:30:44 Done.
65 // by another span of length "span->length - blocks" blocks. Modifies |span|
66 // to point to the first span of length |blocks|. Return second span.
67 scoped_ptr<Span> Split(Span* span, size_t blocks);
68
69 // Search free list for span that satisfies the request for |blocks| of
70 // memory. If found, the span is removed from the free list and returned.
71 scoped_ptr<Span> SearchFreeList(size_t blocks);
72
73 // Delete span and release memory if possible.
74 void DeleteSpan(scoped_ptr<Span> span);
75
76 private:
77 scoped_ptr<Span> RemoveFromFreeList(Span* span);
78 scoped_ptr<Span> Carve(Span* span, size_t blocks);
79 void RegisterSpan(Span* span);
80
81 size_t block_size_;
82
83 // Mapping from first/last block of span to Span instance.
84 typedef base::hash_map<size_t, Span*> SpanMap;
85 SpanMap spans_;
86
87 // Linked-list of free discardable memory regions.
88 base::LinkedList<Span> free_spans_;
89
90 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap);
91 };
92
93 } // namespace content
94
95 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
OLDNEW
« no previous file with comments | « content/child/child_discardable_shared_memory_manager.cc ('k') | content/common/discardable_shared_memory_heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698