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

Issue 24988003: Refactor DiscardableMemory for the upcoming DiscardableMemoryAllocator. (Closed)

Created:
7 years, 2 months ago by Philippe
Modified:
7 years, 2 months ago
CC:
chromium-reviews, erikwright+watch_chromium.org, darin-cc_chromium.org, gavinp+memory_chromium.org, Ian Vollick, reveman
Visibility:
Public.

Description

Refactor DiscardableMemory for the upcoming DiscardableMemoryAllocator. DiscardableMemory has the current limitation on Android that it's file-based thus uses file descriptor thus is a limited resource. This will be worked around in a future CL by adding DiscardMemoryAllocator operating on large pieces of discardable memory (thus using less file descriptors) and allowing the clients to operate on specific chunks. This CL prepares this addition by refactoring the existing DiscardableMemory implementation. It makes it a pure interface to allow the upcoming DiscardableMemoryAllocator to create instances of its own implementation of DiscardableMemory. This implementation won't be backed by files, only the allocator will. This also fixes some issues with the previous interface/implementation: - The fact that initialization happened through an Init() method which must be called only once. The only benefit of this design is to allow objects to be constructed on the stack. In practice all the current clients are allocating instances in the heap anyway (although not doing so would be a simple change). This also made the interface hard to use correctly but easy to use incorrectly. Implementation also systematically had to check that the object was correctly initialized. - The fact that unlock() did an munmap() while the class was providing a Memory() accessor. If the client stored the pointer returned by Memory(), did an Unlock(), then a Lock() (doing an mmap()) and accessed the memory through the previously saved pointer, he could have ended up doing uses after free. unmap() is not needed as part of memory unpinning AFAICT. - Some error code paths contained resource (e.g. fd) leaks. BUG=299828 TBR=tomhudson@chromium.org, darin@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=229838

Patch Set 1 : #

Patch Set 2 : Update base.gypi #

Patch Set 3 : #

Patch Set 4 : Add calls to mprotect() in DEBUG mode #

Total comments: 8

Patch Set 5 : Address William's comments #

Patch Set 6 : Update Mac implementation #

Patch Set 7 : Fix Mac build (hopefully) #

Patch Set 8 : Speculative fix for Mac unit test #

Total comments: 4

Patch Set 9 : Address Avi's comments #

Patch Set 10 : Add death unit test + fix Android implementation #

Total comments: 4

Patch Set 11 : Address Avi's comments #

Patch Set 12 : Fix linux clang build #

Unified diffs Side-by-side diffs Delta from patch set Stats (+246 lines, -287 lines) Patch
M base/memory/discardable_memory.h View 3 chunks +10 lines, -43 lines 0 comments Download
M base/memory/discardable_memory.cc View 1 chunk +5 lines, -32 lines 0 comments Download
M base/memory/discardable_memory_android.cc View 1 2 3 4 5 6 7 8 9 2 chunks +101 lines, -97 lines 0 comments Download
M base/memory/discardable_memory_mac.cc View 1 2 3 4 5 6 7 9 10 3 chunks +62 lines, -53 lines 0 comments Download
M base/memory/discardable_memory_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 2 chunks +29 lines, -19 lines 0 comments Download
M skia/ext/SkDiscardableMemory_chrome.h View 1 chunk +5 lines, -7 lines 0 comments Download
M skia/ext/SkDiscardableMemory_chrome.cc View 2 chunks +11 lines, -16 lines 0 comments Download
M webkit/child/web_discardable_memory_impl.h View 2 chunks +7 lines, -7 lines 0 comments Download
M webkit/child/web_discardable_memory_impl.cc View 2 chunks +15 lines, -8 lines 0 comments Download
M webkit/child/webkitplatformsupport_child_impl.cc View 1 chunk +1 line, -5 lines 0 comments Download

Messages

Total messages: 31 (0 generated)
Philippe
What do you guys think? I intend to polish the CL and update the Mac ...
7 years, 2 months ago (2013-09-27 17:28:05 UTC) #1
Philippe
On 2013/09/27 17:28:05, Philippe wrote: > What do you guys think? > > I intend ...
7 years, 2 months ago (2013-09-30 09:23:27 UTC) #2
willchan no longer on Chromium
Have you guys spoken? Is this CL going to have to change? Do we have ...
7 years, 2 months ago (2013-09-30 16:16:35 UTC) #3
Philippe
On 2013/09/30 16:16:35, willchan wrote: > Have you guys spoken? Is this CL going to ...
7 years, 2 months ago (2013-09-30 16:29:44 UTC) #4
willchan no longer on Chromium
Sorry, I won't be able to look at this for the next two days most ...
7 years, 2 months ago (2013-10-02 14:20:52 UTC) #5
Philippe
No worries, thanks for the update :) By the way, will we need also some ...
7 years, 2 months ago (2013-10-02 14:23:21 UTC) #6
willchan no longer on Chromium
I haven't looked, but I'm not in OWNERS for skia and webkit. So you'll need ...
7 years, 2 months ago (2013-10-02 14:26:39 UTC) #7
Philippe
Yes indeed, thanks. On Wed, Oct 2, 2013 at 4:26 PM, William Chan (陈智昌) <willchan@chromium.org>wrote: ...
7 years, 2 months ago (2013-10-02 14:32:31 UTC) #8
willchan no longer on Chromium
Can you explain the design choice in using a DiscardableMemory static factory method to construct ...
7 years, 2 months ago (2013-10-09 22:47:37 UTC) #9
Philippe
On 2013/10/09 22:47:37, willchan wrote: > Can you explain the design choice in using a ...
7 years, 2 months ago (2013-10-14 09:22:56 UTC) #10
willchan no longer on Chromium
On 2013/10/14 09:22:56, Philippe wrote: > On 2013/10/09 22:47:37, willchan wrote: > > Can you ...
7 years, 2 months ago (2013-10-14 18:03:44 UTC) #11
Philippe
On 2013/10/14 18:03:44, willchan wrote: > On 2013/10/14 09:22:56, Philippe wrote: > > On 2013/10/09 ...
7 years, 2 months ago (2013-10-15 09:05:12 UTC) #12
willchan no longer on Chromium
To be clear, I'm just asking about your design choices. If one of your goals ...
7 years, 2 months ago (2013-10-15 16:21:41 UTC) #13
Philippe
On 2013/10/15 16:21:41, willchan wrote: > To be clear, I'm just asking about your design ...
7 years, 2 months ago (2013-10-15 17:02:18 UTC) #14
Philippe
On 2013/10/15 17:02:18, Philippe wrote: > On 2013/10/15 16:21:41, willchan wrote: > > To be ...
7 years, 2 months ago (2013-10-16 11:47:40 UTC) #15
willchan no longer on Chromium
https://codereview.chromium.org/24988003/diff/12001/base/memory/discardable_memory_android.cc File base/memory/discardable_memory_android.cc (right): https://codereview.chromium.org/24988003/diff/12001/base/memory/discardable_memory_android.cc#newcode140 base/memory/discardable_memory_android.cc:140: HANDLE_EINTR(close(fd)); Please drop this HANDLE_EINTR: https://code.google.com/p/chromium/issues/detail?id=269623. https://codereview.chromium.org/24988003/diff/12001/base/memory/discardable_memory_android.cc#newcode143 base/memory/discardable_memory_android.cc:143: return ...
7 years, 2 months ago (2013-10-17 01:21:37 UTC) #16
Philippe
https://codereview.chromium.org/24988003/diff/12001/base/memory/discardable_memory_android.cc File base/memory/discardable_memory_android.cc (right): https://codereview.chromium.org/24988003/diff/12001/base/memory/discardable_memory_android.cc#newcode140 base/memory/discardable_memory_android.cc:140: HANDLE_EINTR(close(fd)); On 2013/10/17 01:21:37, willchan wrote: > Please drop ...
7 years, 2 months ago (2013-10-17 08:56:24 UTC) #17
Philippe
Adding Avi for the Mac side at least.
7 years, 2 months ago (2013-10-17 11:05:24 UTC) #18
Avi (use Gerrit)
I have issues with the ordering. https://codereview.chromium.org/24988003/diff/48001/base/memory/discardable_memory_mac.cc File base/memory/discardable_memory_mac.cc (right): https://codereview.chromium.org/24988003/diff/48001/base/memory/discardable_memory_mac.cc#newcode38 base/memory/discardable_memory_mac.cc:38: DCHECK_EQ(0, mprotect(memory_, size_, ...
7 years, 2 months ago (2013-10-17 15:09:37 UTC) #19
Avi (use Gerrit)
Also, the mprotect looks like a useful debug feature. We should have a death test ...
7 years, 2 months ago (2013-10-17 15:10:56 UTC) #20
willchan no longer on Chromium
FYI, I'm getting an old chunk mismatch on the current patchset, so I can't view ...
7 years, 2 months ago (2013-10-17 15:46:19 UTC) #21
Philippe
Yeah, I will upload a patch set very shortly that will address Avi's comments (that ...
7 years, 2 months ago (2013-10-17 15:57:49 UTC) #22
Philippe
Thanks Avi! Please ignore patch set 9. You can diff against patch set 8 or ...
7 years, 2 months ago (2013-10-17 16:20:35 UTC) #23
Avi (use Gerrit)
lgtm I didn't know that about the mprotect deal. Gotcha. Nice new test. https://codereview.chromium.org/24988003/diff/80001/base/memory/discardable_memory_mac.cc File ...
7 years, 2 months ago (2013-10-17 17:58:54 UTC) #24
Avi (use Gerrit)
https://codereview.chromium.org/24988003/diff/80001/base/memory/discardable_memory_unittest.cc File base/memory/discardable_memory_unittest.cc (right): https://codereview.chromium.org/24988003/diff/80001/base/memory/discardable_memory_unittest.cc#newcode59 base/memory/discardable_memory_unittest.cc:59: TEST(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) { Actually, can we ifdef this whole ...
7 years, 2 months ago (2013-10-17 18:00:26 UTC) #25
Philippe
Thanks Avi! https://codereview.chromium.org/24988003/diff/80001/base/memory/discardable_memory_mac.cc File base/memory/discardable_memory_mac.cc (right): https://codereview.chromium.org/24988003/diff/80001/base/memory/discardable_memory_mac.cc#newcode47 base/memory/discardable_memory_mac.cc:47: return state & VM_PURGABLE_EMPTY ? DISCARDABLE_MEMORY_PURGED On ...
7 years, 2 months ago (2013-10-18 08:25:21 UTC) #26
willchan no longer on Chromium
LGTM, but just a comment on your assertion in the CL description. You've claimed the ...
7 years, 2 months ago (2013-10-19 00:45:48 UTC) #27
Philippe
On 2013/10/19 00:45:48, willchan wrote: > LGTM, but just a comment on your assertion in ...
7 years, 2 months ago (2013-10-21 13:19:55 UTC) #28
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/pliard@chromium.org/24988003/381001
7 years, 2 months ago (2013-10-21 13:20:10 UTC) #29
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/pliard@chromium.org/24988003/381001
7 years, 2 months ago (2013-10-21 14:03:16 UTC) #30
commit-bot: I haz the power
7 years, 2 months ago (2013-10-21 16:54:10 UTC) #31
Message was sent while issue was closed.
Change committed as 229838

Powered by Google App Engine
This is Rietveld 408576698