Commit Graph
2192 Commits
Author SHA1 Message Date
Paul Bone dd55553325 Bug 1898647 - p2. Insert fresh runs in the middle of a size class list r=glandium
Further refine the order runs are returned by inserting fresh and other
runs in the middle of a size class' list leaving only decommitted and
madvised runs to be inserted at the end.

Differential Revision: https://phabricator.services.mozilla.com/D288828
2026-06-10 07:08:12 +00:00
Paul Bone 69268eb3ec Bug 1898647 - p1. Prefer to allocate dirty runs r=glandium
We can prefer to allocate from dirty runs by inserting dirty runs at the
head of a size class' list and other runs at the end.

Differential Revision: https://phabricator.services.mozilla.com/D288827
2026-06-10 07:08:09 +00:00
Paul Bone 2352e84e33 Bug 2042112 - Fix some comments r=glandium DONTBUILD
Differential Revision: https://phabricator.services.mozilla.com/D302301
2026-06-04 08:26:14 +00:00
Paul Bone 09a0e3b980 Bug 2039732 - Remove an assertion that's not always true r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D302687
2026-06-01 01:01:53 +00:00
Paul Bone 54dc24578f Bug 2014781 - gPageSize follows gRealPageSize r=glandium
This effectively backs out Bug 1980056 part 5 for a performance
regression.  It also adds a comment about the performance regression.

This might be temporary depending on more testing, but for now we can
have some faster performance.

Differential Revision: https://phabricator.services.mozilla.com/D297236
2026-05-31 23:27:26 +00:00
Paul Bone 1879025654 Bug 2014781 - Restore the sub-page size class r=glandium
This reverts Bug 1980056 part 6.

Differential Revision: https://phabricator.services.mozilla.com/D297237
2026-05-31 23:27:24 +00:00
Paul Bone 2bc9538e25 Bug 2042123 - Add theoratical best run overhead to mozjemalloc_info r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D302303
2026-05-28 05:17:59 +00:00
Paul Bone e866695139 Bug 2042123 - Add run header size to mozjemalloc_info r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D302302
2026-05-28 05:17:56 +00:00
Paul Bone 821450ba1c Bug 2004187 - Fix --enable-project=memory r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D275164
2026-05-27 06:40:40 +00:00
Paul Bone 9bb5296e61 Bug 2035696 - Set a minimum run size r=glandium
The more regions (cells) in a run the more allocations can stay on the
"hot path".  This can have a performance improvment on Linux and Windows
that corresponds to the larger page size on MacOS.  On MacOS the larger
page size already implies more regions in a run.

Differential Revision: https://phabricator.services.mozilla.com/D297242
2026-05-27 01:36:17 +00:00
serge-sans-paille 03b0f2574c Bug 2040876 - Activate modernize-use-bool-literals clang-tidy check r=emilio,webrtc-reviewers,cookie-reviewers,places-reviewers,layout-reviewers,mak,bwc
Differential Revision: https://phabricator.services.mozilla.com/D301473
2026-05-25 21:13:49 +00:00
Silaghi 688b962a0b Revert "Bug 2014781 - gPageSize follows gRealPageSize r=glandium" for causing mochitests failures at toolkit/content
This reverts commit 3c629953cf.

Revert "Bug 2014781 - Restore the sub-page size class r=glandium"

This reverts commit 606f7ea614.
2026-05-14 07:39:36 +00:00
Paul Bone 3c629953cf Bug 2014781 - gPageSize follows gRealPageSize r=glandium
This effectively backs out Bug 1980056 part 5 for a performance
regression.  It also adds a comment about the performance regression.

This might be temporary depending on more testing, but for now we can
have some faster performance.

Differential Revision: https://phabricator.services.mozilla.com/D297236
2026-05-14 03:15:37 +00:00
Paul Bone 606f7ea614 Bug 2014781 - Restore the sub-page size class r=glandium
This reverts Bug 1980056 part 6.

Differential Revision: https://phabricator.services.mozilla.com/D297237
2026-05-14 03:15:33 +00:00
Jens Stutte ac8a8d1849 Bug 2037545 - Defer base_chunk_dealloc out of BaseAlloc::free's locked region. r=pbone
base_chunk_dealloc transitively re-enters BaseAlloc::alloc via chunk_record's
extent_node_t allocation. Since Mutex is non-recursive (Linux pthread adaptive,
macOS os_unfair_lock), this self-deadlocks on Linux and traps with SIGILL on
macOS. Capture the chunk under the lock and dealloc after dropping it; the
alloc path already takes the symmetric precaution via base_chunk_alloc.

Differential Revision: https://phabricator.services.mozilla.com/D299319
2026-05-08 11:55:23 +00:00
Paul Bone 7dcfcde206 Bug 1932624 - p3. Use a hint to avoid a linear scan r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D288826
2026-05-06 06:30:19 +00:00
Paul Bone e6ea5591fc Bug 1932624 - p2. Replace the mRunsAvail RedBlackTree with an array of lists r=glandium
Replace the  mRunsAvail RedBlackTree with a new class that uses an array
of linked lists.  Inserting and removing runs are now constant time.
Searching for a run is linear with respect to the number of possible
sizes. The next patch will amortise that cost.

The previous RedBlackTree would bias towards returning runs with lower
memory addresses (when size is equal).  That would make a slight
improvement to fragmentation.  This patch may slightly increase
fragmentation, but the constant time operations on the tree makes up for
it.

Differential Revision: https://phabricator.services.mozilla.com/D288825
2026-05-06 06:30:16 +00:00
Paul Bone beb98e529c Bug 1932624 - p1. Fix an incorrect variable name in a comment r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D288824
2026-05-06 06:30:13 +00:00
serge-sans-paille 18c0b122d9 Bug 2034832 - Make memory/ headers compatible with current static analysis r=pbone
- use = default when relevant

This matches the clang-tidy rules:

- https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-default.html

While we're at it, also harmonize use of size_t vs std::size_t.

That we already use on source files

Differential Revision: https://phabricator.services.mozilla.com/D296630
2026-04-29 06:20:46 +00:00
serge-sans-paille c68e95f4d0 Bug 2033987 - Remove unused include of <inttypes.h> r=dom-storage-reviewers,firefox-style-system-reviewers,emilio,jari
Differential Revision: https://phabricator.services.mozilla.com/D295778
2026-04-25 07:08:07 +00:00
Alexandru Marc 19014ac847 Revert "Bug 2033987 - Remove unused include of <inttypes.h> r=dom-storage-reviewers,firefox-style-system-reviewers,emilio,jari"
This reverts commit 07304c9f26.
2026-04-24 15:08:59 +00:00
serge-sans-paille 07304c9f26 Bug 2033987 - Remove unused include of <inttypes.h> r=dom-storage-reviewers,firefox-style-system-reviewers,emilio,jari
Differential Revision: https://phabricator.services.mozilla.com/D295778
2026-04-24 14:18:42 +00:00
Paul Bone a9d015d3b8 Bug 2023471 - Move the array implementation to a new header r=glandium
TLS and other features will need an array implementation.  We can take
the one from PHC rename it and move it to a new header file.

Differential Revision: https://phabricator.services.mozilla.com/D279246
2026-04-15 05:10:07 +00:00
Abhishek Sharma f95f91ba58 Bug 2029736 - pt 4. Introduce chunk allocators that abstract over Arena page operations r=pbone
The chunk_allocator_t type is added to the public API of jemalloc and can
be set at the time of arena creation for private arenas. This type is
basically a virtual table that provides implementations for memory
map, unmap, commit and decommit. All arena chunk/page manipulations
now use the functions provided by its chunk allocator. By default this is a
global system allocator that preserves existing functionality.

The way this is currently implemented, an arena with a custom chunk allocator
will not have it's chunks recorded/recycled as before and would need to re-implement
that logic.

Differential Revision: https://phabricator.services.mozilla.com/D292240
2026-04-15 05:02:53 +00:00
Abhishek Sharma 24304b2c39 Bug 2029736 - pt 3. Make arena_chunk_dealloc independent of ChunkType r=pbone
chunk_record/chunk_recycle logic does not distinguish between
ARENA_CHUNK or HUGE_CHUNK in a meaningful way. It only checks
whether an incoming chunk is already ZEROED or not. So we can
treat all chunks passed to arena_chunk_dealloc as ARENA_CHUNK.

This change is mainly to allow the chunk allocator interface
introduced in the next change to not have to care about ChunkType
and avoid making ChunkType public.

Differential Revision: https://phabricator.services.mozilla.com/D292239
2026-04-15 05:02:49 +00:00
Abhishek Sharma c2e6a43a37 Bug 2029736 - pt 2. Refactor to separate base chunk and arena chunk alloc/dealloc r=pbone
Introduce base_chunk_alloc and arena_chunk_alloc for base/arena chunk
allocations respectively. base_chunk_alloc skips the chunk recycling and
gChunkRTree insertion code paths as before.

Split up chunk deallocation into arena_chunk_dealloc and base_chunk_dealloc.
base_chunk_dealloc is used for both base chunks and arena chunks that have been
removed from gChunkRTree.

Differential Revision: https://phabricator.services.mozilla.com/D292238
2026-04-15 05:02:45 +00:00
Abhishek Sharma fc35367060 Bug 2029736 - pt 1. Cleanup pages_purge to remove unused argument and constant return value. r=pbone
The force_zero argument is unused. It is assumed that pages_purge
always zeroes pages so doesn't need to return a result anymore.

Besides the small cleanup this allows a future change that allows
arena chunk deallocs to be oblivious to the ARENA vs HUGE chunk distinction.

Differential Revision: https://phabricator.services.mozilla.com/D292236
2026-04-15 05:02:42 +00:00
rperta 8cb5b59dd9 Revert "Bug 2029736 - pt 4. Introduce chunk allocators that abstract over Arena page operations r=pbone" for causing hazard bustages
This reverts commit d4f2835e1e.

This reverts commit a1fbd3a9b5.

This reverts commit 0993024c1b.

This reverts commit 2a0f068975.
2026-04-14 11:16:37 +00:00
Abhishek Sharma d4f2835e1e Bug 2029736 - pt 4. Introduce chunk allocators that abstract over Arena page operations r=pbone
The chunk_allocator_t type is added to the public API of jemalloc and can
be set at the time of arena creation for private arenas. This type is
basically a virtual table that provides implementations for memory
map, unmap, commit and decommit. All arena chunk/page manipulations
now use the functions provided by its chunk allocator. By default this is a
global system allocator that preserves existing functionality.

The way this is currently implemented, an arena with a custom chunk allocator
will not have it's chunks recorded/recycled as before and would need to re-implement
that logic.

Differential Revision: https://phabricator.services.mozilla.com/D292240
2026-04-14 10:06:48 +00:00
Abhishek Sharma a1fbd3a9b5 Bug 2029736 - pt 3. Make arena_chunk_dealloc independent of ChunkType r=pbone
chunk_record/chunk_recycle logic does not distinguish between
ARENA_CHUNK or HUGE_CHUNK in a meaningful way. It only checks
whether an incoming chunk is already ZEROED or not. So we can
treat all chunks passed to arena_chunk_dealloc as ARENA_CHUNK.

This change is mainly to allow the chunk allocator interface
introduced in the next change to not have to care about ChunkType
and avoid making ChunkType public.

Differential Revision: https://phabricator.services.mozilla.com/D292239
2026-04-14 10:06:45 +00:00
Abhishek Sharma 0993024c1b Bug 2029736 - pt 2. Refactor to separate base chunk and arena chunk alloc/dealloc r=pbone
Introduce base_chunk_alloc and arena_chunk_alloc for base/arena chunk
allocations respectively. base_chunk_alloc skips the chunk recycling and
gChunkRTree insertion code paths as before.

Split up chunk deallocation into arena_chunk_dealloc and base_chunk_dealloc.
base_chunk_dealloc is used for both base chunks and arena chunks that have been
removed from gChunkRTree.

Differential Revision: https://phabricator.services.mozilla.com/D292238
2026-04-14 10:06:41 +00:00
Abhishek Sharma 2a0f068975 Bug 2029736 - pt 1. Cleanup pages_purge to remove unused argument and constant return value. r=pbone
The force_zero argument is unused. It is assumed that pages_purge
always zeroes pages so doesn't need to return a result anymore.

Besides the small cleanup this allows a future change that allows
arena chunk deallocs to be oblivious to the ARENA vs HUGE chunk distinction.

Differential Revision: https://phabricator.services.mozilla.com/D292236
2026-04-14 10:06:37 +00:00
Paul Bone 84251af3d5 Bug 2001241 - Allocation during PHC initalisation is fallible r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D275406
2026-04-14 09:00:12 +00:00
Paul Bone b45428c197 Bug 1976185 - PHC now uses BaseAlloc r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D270991
2026-04-13 01:45:03 +00:00
Paul Bone f2c2c66634 Bug 1976184 - pt 22. Release whole cells when freeing if possible r=glandium
When freeing cells, if the cell has no neighbours after merging then it
is an entire chunk.  Release the whole chunk to the OS.

Differential Revision: https://phabricator.services.mozilla.com/D287069
2026-04-10 08:28:47 +00:00
Paul Bone 761f542c7c Bug 1976184 - pt 21. Try to satisfy an allocation by merging decommitted cells r=glandium
When cells are freed they are merged with their free neighbours, unless
those neighbours are decommitted which can lead to fragmentation.
Merging these cells during free() would mean committing one or
decommitting the other.  Instead if an allocation can't be satisfied by
the normal or oversize free lists, process the decommited free list (a
tree) to commit then merge small decommitted cells with their neighbours
until a cell large enough to satisfy the allocation is made available.

This solves a test failure on Windows.

Differential Revision: https://phabricator.services.mozilla.com/D287068
2026-04-10 08:28:43 +00:00
Paul Bone 93af61cf80 Bug 1976184 - pt 20. Add internal validation to BaseAlloc r=sergesanspaille
Differential Revision: https://phabricator.services.mozilla.com/D275177
2026-04-10 08:28:39 +00:00
Paul Bone 92b91439e4 Bug 1976184 - pt 19. Make more memory around decommitted memory usable r=glandium
When decommitting memory split cells of the beginning and end of the
decommitted region so that the maximum amount of committed memory is
available.

Differential Revision: https://phabricator.services.mozilla.com/D270990
2026-04-10 08:28:35 +00:00
Paul Bone 0f8656aef8 Bug 1976184 - pt 18. Decommit remainder of new chunks in BaseAlloc r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D270989
2026-04-10 08:28:31 +00:00
Paul Bone ae941d2b62 Bug 1976184 - pt 17. Implement BaseAlloc::realloc r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D269187
2026-04-10 08:28:28 +00:00
Paul Bone 1863cc628d Bug 1976184 - pt 16. Remove wilderness allocation from BaseAlloc r=glandium
Instead when BaseAlloc needs more memory from the system it converts a
whole chunk into a cell then splits it.  This will make it easier to
release whole chunks later without needing to manage "wilderness".

This has the side-effect of always keeping all memory committed.  A
later patch will add the ability to decommit memory.

Differential Revision: https://phabricator.services.mozilla.com/D270988
2026-04-10 08:28:24 +00:00
Paul Bone b97546aa35 Bug 1976184 - pt 15. Refactor alloc path r=glandium
+ The internal allocation functions now return BaseAllocCell pointers.
 * The alloc size checks and allocation state are now done in one
   place, when alloc_cell() returns control to alloc().
 + The old wilderness_alloc function is removed and
   wilderness_alloc_inplace is renamed to wilderness_alloc
 + Add log messages to alloc and free functions.

Differential Revision: https://phabricator.services.mozilla.com/D270987
2026-04-10 08:28:20 +00:00
Paul Bone a435cabeab Bug 1976184 - pt 14. Add logging to the BaseAllocator r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D270986
2026-04-10 08:28:16 +00:00
Paul Bone be1d259161 Bug 1976184 - pt 13. Support cell splitting r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D268994
2026-04-10 08:28:12 +00:00
Paul Bone af5b782d6f Bug 1976184 - pt 12. Support cell merging r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D268993
2026-04-10 08:28:09 +00:00
Paul Bone 0f4d82ae09 Bug 1976184 - pt 11. Add the previous cells size to the metadata r=glandium
This is necessary to make the heap parseable which is required to
support splitting and merging.

Differential Revision: https://phabricator.services.mozilla.com/D268992
2026-04-10 08:28:05 +00:00
Paul Bone de7c563bd1 Bug 1976184 - pt 10. Make the size to free list mapping more efficient r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D287061
2026-04-10 08:28:01 +00:00
Paul Bone 960c47a816 Bug 1976184 - pt 9. Improve free list organisation r=glandium
Introduce a "quantum" cell size so that free lists only ever contain
objects of the same size which improves cell reuse.

Differential Revision: https://phabricator.services.mozilla.com/D268991
2026-04-10 08:27:58 +00:00
Paul Bone cad8915c5c Bug 1976184 - pt 8. Use a RB tree for the oversize free list r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D268990
2026-04-10 08:27:54 +00:00
Paul Bone 678c4c64ec Bug 1976184 - pt 7. Move some BaseAlloc structures to a new header r=glandium
The next patch will need to access some of these structures from
BaseAlloc.h, rather than adding them there and making the interface less
obvious, create a new header.

Differential Revision: https://phabricator.services.mozilla.com/D268989
2026-04-10 08:27:50 +00:00