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)

defect
Not set
normal

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.
This sounds like a good idea. If we can't provide similar functionality without jemalloc, the function can always be a nop.
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".
I was thinking you could even write code like size = ROUND_UP(42); malloc(size); // I need at least 42 bytes.
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.
...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.
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.
(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.
> 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.
I don't think this is the best way to measure rounding up space in memory reporters. See bug 675136 comment 8.
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.
YAGNI!
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.