Closed
Bug 675226
Opened 13 years ago
Closed 13 years ago
Provide "round up to actual allocation size" function in jemalloc
Categories
(Core :: Memory Allocator, defect)
Core
Memory Allocator
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: justin.lebar+bug, Unassigned)
Details
+++ This bug was initially created as a clone of Bug 675136 comment 5 +++
> Some kind of "round up block size" function or macro as part of the mem
> reporter implementation would be nice. I don't know how other memory reporters
> work, but the CC one tracks the number of each kind of block that are allocated
> and freed, then does: |numBlock * sizeOf(myBlockType)|. With some kind of
> function, this could be changed to |numBlock *
> ROUND_UP_BLOCK_SIZE(sizeOf(myBlockType))| which make accounting for this much
> easier for memory reporter writers, and would also make it possible to change
> this in a central place depending on the specifics of the memory allocator.
Reporter | ||
Comment 1•13 years ago
|
||
This sounds like a good idea.
If we can't provide similar functionality without jemalloc, the function can always be a nop.
Comment 2•13 years ago
|
||
This would also be nice to have to check that various block sizes are power of two, after we fix up thing like Bug 675150 to be "power of two aware".
Reporter | ||
Comment 3•13 years ago
|
||
I was thinking you could even write code like
size = ROUND_UP(42);
malloc(size); // I need at least 42 bytes.
Reporter | ||
Comment 4•13 years ago
|
||
Of course you could always do
ptr = malloc(42);
size = malloc_usable_size(ptr).
I was thinking that might be too slow, but maybe we should test it before making a premature optimization.
Reporter | ||
Comment 5•13 years ago
|
||
...but I guess if it was a macro, or maybe an inline function, you could say at compile time
#define CHUNK_SIZE ROUND_UP(600)
which would be helpful.
Comment 6•13 years ago
|
||
It would be useful to put these functions in memory/mozalloc, so that we can keep them all in the same place, and move towards a richer library there. It is also easier to consider the jemalloc/non-jemalloc cases there.
Comment 7•13 years ago
|
||
(In reply to comment #2)
> This would also be nice to have to check that various block sizes are power
> of two, after we fix up thing like Bug 675150 to be "power of two aware".
Based on njn's logs, it looks like it doesn't round up to the next power of two for "large" allocations, whatever those are. So the function is a little more complex then I thought.
Reporter | ||
Comment 8•13 years ago
|
||
Yes. The function is detailed here:
http://hg.mozilla.org/mozilla-central/file/8fb752f5e1fa/memory/jemalloc/jemalloc.c#l47
Reporter | ||
Comment 9•13 years ago
|
||
> Based on njn's logs, it looks like it doesn't round up to the next power of two
> for "large" allocations, whatever those are.
Indeed, according to the comment, only a few of the quanta are powers of 2.
Comment 10•13 years ago
|
||
I don't think this is the best way to measure rounding up space in memory reporters. See bug 675136 comment 8.
Reporter | ||
Comment 11•13 years ago
|
||
Is there anywhere we'd want to use this right now? If not, maybe we should say YAGNI and wontfix. We can always reopen if we want it for something.
You need to log in
before you can comment on or make changes to this bug.
Description
•