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

Issue 2525773002: Make GrMemoryPool play nice with bucketing allocators. (Closed)

Created:
4 years, 1 month ago by DmitrySkiba
Modified:
4 years ago
Reviewers:
herb_g, bsalomon, mtklein, reed1
CC:
reviews_skia.org
Target Ref:
refs/heads/master
Project:
skia
Visibility:
Public.

Description

Make GrMemoryPool play nice with bucketing allocators. Some memory allocators have very coarse size buckets, so for example on Android (jemalloc) an attempt to allocate 32 KiB + 1 byte will end up allocating 40 KiB, wasting 8 KiB. GrMemoryPool ctor takes two arguments that specify prealloc / block sizes, and then inflates them to accommodate some bookkeeping structures. Since most places create GrMemoryPools with pow2 numbers (which have buckets in most allocators) the inflation causes allocator to select next size bucket, wasting memory. This CL makes GrMemoryPool to stop inflating sizes it was created with, and allocate specified amounts exactly. Part of allocated memory is then used for bookkeeping structures. Additionally, GrObjectMemoryPool template is provided, which takes prealloc / block object counts (instead of sizes) and guarantees that specified number of objects will fit in prealloc / block spaces. BUG=651872 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2525773002 Committed: https://skia.googlesource.com/skia/+/e4cd00699167cefde9abedbd49ede64f82d552c7

Patch Set 1 #

Total comments: 4

Patch Set 2 : Proper naming; kill friend #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+284 lines, -30 lines) Patch
M src/gpu/GrMemoryPool.h View 1 4 chunks +94 lines, -11 lines 2 comments Download
M src/gpu/GrMemoryPool.cpp View 5 chunks +16 lines, -16 lines 0 comments Download
M src/gpu/instanced/InstancedRendering.h View 1 1 chunk +1 line, -1 line 0 comments Download
M src/gpu/instanced/InstancedRendering.cpp View 1 2 chunks +2 lines, -2 lines 0 comments Download
M tests/GrMemoryPoolTest.cpp View 1 2 chunks +171 lines, -0 lines 0 comments Download

Messages

Total messages: 19 (10 generated)
DmitrySkiba
4 years, 1 month ago (2016-11-22 22:11:22 UTC) #5
bsalomon
Thanks for looking at this and also for writing unit tests! Small stuff inline. https://codereview.chromium.org/2525773002/diff/1/src/gpu/GrMemoryPool.h ...
4 years ago (2016-11-28 16:03:31 UTC) #8
DmitrySkiba
https://codereview.chromium.org/2525773002/diff/1/src/gpu/GrMemoryPool.h File src/gpu/GrMemoryPool.h (right): https://codereview.chromium.org/2525773002/diff/1/src/gpu/GrMemoryPool.h#newcode117 src/gpu/GrMemoryPool.h:117: friend class GrObjectMemoryPool; On 2016/11/28 16:03:31, bsalomon wrote: > ...
4 years ago (2016-11-29 01:08:02 UTC) #9
bsalomon
lgtm
4 years ago (2016-11-29 14:18:38 UTC) #11
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2525773002/20001
4 years ago (2016-11-29 14:18:43 UTC) #12
commit-bot: I haz the power
Committed patchset #2 (id:20001) as https://skia.googlesource.com/skia/+/e4cd00699167cefde9abedbd49ede64f82d552c7
4 years ago (2016-11-29 14:50:38 UTC) #15
reed1
Can/should we look for ways to generalize this idea (avoiding wasted space in chunky allocations) ...
4 years ago (2016-11-29 17:51:48 UTC) #17
herb_g
SkFixedAlloc has 4 byte overhead, and squeezes additional space by taking alignment into account. Maybe ...
4 years ago (2016-11-29 18:31:14 UTC) #18
DmitrySkiba
4 years ago (2016-11-29 19:17:17 UTC) #19
Message was sent while issue was closed.
On 2016/11/29 18:31:14, herb_g wrote:
> SkFixedAlloc has 4 byte overhead, and squeezes additional space by taking
> alignment into account. Maybe you can use some of the ideas.
> 
> https://codereview.chromium.org/2525773002/diff/20001/src/gpu/GrMemoryPool.h
> File src/gpu/GrMemoryPool.h (right):
> 
>
https://codereview.chromium.org/2525773002/diff/20001/src/gpu/GrMemoryPool.h#...
> src/gpu/GrMemoryPool.h:27: *   1. they are are 8-byte aligned
> Generally , 8-byte alignment is not enough. You should consult
std::max_align_t.
> For example on the mac, 16-byte alignment is required for a general allocator.
> You could consult alignof() for the incoming type to make the right choice.

I think those are two different things: alignof() applies to all allocators that
want to allocate C++ objects, while 16-byte alignment requirement applies only
to allocators that want to replace standard macOS facilities
(malloc_default_zone(), CF allocators). 

But I agree that in some cases default alignment of 8 (which BTW was already
there, my CL just reflected it in the comment) might not be enough. It's easy to
check / change for alignment in GrObjectMemoryPool, but not in GrMemoryPool,
since it allocates just raw bytes.

>
https://codereview.chromium.org/2525773002/diff/20001/src/gpu/GrMemoryPool.h#...
> src/gpu/GrMemoryPool.h:162: T* allocate() { return
> static_cast<T*>(GrMemoryPool::allocate(sizeof(T))); }
> I think this is a very dangerous API. It is not RAII; therefore forces the
> client to manage the destruction and type of the object. Memory should not be
> returned with out being initialized, and ownership established.
> 
> Look at SkFixedAlloc one approach for doing this.

Created https://bugs.chromium.org/p/skia/issues/detail?id=6010 for further
discussion.

Powered by Google App Engine
This is Rietveld 408576698