Commit Graph
120 Commits
Author SHA1 Message Date
Daniel Holbert c8723c0549 Bug 2044510: Pass already_AddRefed types by-value instead of by rvalue reference, in xpcom/. r=xpcom-reviewers,emilio
See https://bugzilla.mozilla.org/show_bug.cgi?id=2044510#c0 for more details.

Differential Revision: https://phabricator.services.mozilla.com/D304349
2026-06-05 21:06:31 +00:00
Daniel Holbert ac764635e4 Bug 2043772: Use MakeRefPtr to do allocation for various RefPtr variables in xpcom/threads/. r=xpcom-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D303524
2026-05-30 14:29:48 +00:00
Sylvestre Ledru 6149f49299 Bug 2023419 - Remove Emacs/Vim modelines from xpcom/ r=emilio
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287878
2026-03-16 17:22:07 +00:00
Jens Stutte be381ad8ad Bug 2019024 - Part 1: Defer post-GC/CC jemalloc purge to idle scheduling. r=smaug
After GC/CC completion, jemalloc_free_dirty_pages() synchronously purges
every arena on the main thread. This is redundant when the idle purge
infrastructure (memory.lazypurge.*) is enabled, since arenas are already
queued for deferred purge during GC by the allocation path.

Add TaskController::RequestIdleMemoryCleanup() which kicks the idle purge
runner without the pending-task guard that MayScheduleIdleMemoryCleanup
has, and falls back to synchronous purge when lazy purge is disabled.
Replace the two jemalloc_free_dirty_pages() calls in nsJSEnvironment.cpp
(GC and CC completion) with this new method.

Differential Revision: https://phabricator.services.mozilla.com/D284731
2026-03-05 16:43:32 +00:00
Damien Carver a510771d0e Bug 1992695 - Add missing hidden fields to profiler marker schemas. r=necko-reviewers,profiler-reviewers,canaltinova
Differential Revision: https://phabricator.services.mozilla.com/D281397
2026-02-11 09:46:02 +00:00
Damien Carver d4d96c1939 Bug 1979356 - Remove the "searchable" flag from marker schema fields r=necko-reviewers,profiler-reviewers,toolkit-telemetry-reviewers,canaltinova,jesup
Differential Revision: https://phabricator.services.mozilla.com/D281769
2026-02-06 14:49:32 +00:00
Jens Stutte 7267ee8b9a Bug 1997924 - Avoid memory allocations in ProcessUpdatedPriorityModifier. r=bas
We can leverage std::set's extract / insert to avoid allocations when updating task priorities.
It is assumed that this is always better, also for a small number of tasks.

Differential Revision: https://phabricator.services.mozilla.com/D269142
2025-11-03 15:14:47 +00:00
uniqueident 5b80575fda Bug 1957059 - Removed the "{marker.name} - " from all TableLabel and SetTableLabel calls in order to clean up existing marcher schemas in the profiler. r=canaltinova,profiler-reviewers,win-reviewers,toolkit-telemetry-reviewers,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D263049
2025-09-16 13:51:07 +00:00
Jeff Muizelaar 572e5cfd9f Bug 1988021 - Conditionally capture stacks on runnable dispatch. r=smaug
This captures stacks during runnable dispatch which is really
helpful for understanding what's going on and debugging flows.

It's conditional on the Flows profiler feature so that we don't
take the performance cost all the time.

Differential Revision: https://phabricator.services.mozilla.com/D264474
2025-09-15 14:21:47 +00:00
Nika Layzell 7d39c30b5b Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot
This avoids the small overhead and potential for bugs from the previous
approach of assuming all `const char*` arguments passed to `nsITimer`
initializers are string literals, by instead requiring the argument to be a
`const nsACString&`. This involves changing all callsites to pass a `""_ns`
string literal down instead of a bare string literal.

It appears that while there were currently no buggy callers which
would've provided a dynamic string, there was at least one piece of code
(nsRepeatService::Start) which did pass down a raw char* which may be
dynamically allocated (all callers pass down `nsLiteralCString` so we're
actually OK here right now, but this was a footgun).

Differential Revision: https://phabricator.services.mozilla.com/D261032
2025-08-29 16:18:25 +00:00
iulian moraru f5d6849317 Revert "Bug 1979013: apply code formatting via Lando" for causing windows build bustages on MFTEncoder.cpp.
This reverts commit 8c929cc018.

Revert "Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot"

This reverts commit e01c0a6a32.

Revert "Bug 1979013 - Part 1: Eagerly fetch name for timer callbacks, r=xpcom-reviewers,mccr8"

This reverts commit 9f8e73c163.
2025-08-27 23:00:09 +00:00
Nika Layzell e01c0a6a32 Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot
This avoids the small overhead and potential for bugs from the previous
approach of assuming all `const char*` arguments passed to `nsITimer`
initializers are string literals, by instead requiring the argument to be a
`const nsACString&`. This involves changing all callsites to pass a `""_ns`
string literal down instead of a bare string literal.

It appears that while there were currently no buggy callers which
would've provided a dynamic string, there was at least one piece of code
(nsRepeatService::Start) which did pass down a raw char* which may be
dynamically allocated (all callers pass down `nsLiteralCString` so we're
actually OK here right now, but this was a footgun).

Differential Revision: https://phabricator.services.mozilla.com/D261032
2025-08-27 22:04:15 +00:00
Jens Stutte 4066a08908 Bug 1982199 - Improve ScheduleWantsLaterTimer error handling. r=smaug
Normally we expect timer creation/initialization to be infallible, but there appear to be rare cases where it fails.
It would be good to understand the cause, but first of all we should honor the return value in case of error.
Note that allocations during timer init are infallible since bug 1961386, so most likely the cause is not running low on memory.

Differential Revision: https://phabricator.services.mozilla.com/D262593
2025-08-27 07:14:18 +00:00
Paul Bone a38955e390 Bug 1928254 - pt 8. Improve the idle purge markers r=jstutte
* Group the two kinds of markers for an idle purge into one.  Previously
   one delimited the operation and another one marked the result.  Now the
   result is a field in marker for the whole operation.
 * Rename the RunIdleMemoryCleanup marker to IdlePurge.
 * Rename the marker for peeking at the status to IdlePurgePeek.
 * Move all markers to the GCCC type.

Differential Revision: https://phabricator.services.mozilla.com/D241938
2025-05-27 08:04:31 +00:00
Paul Bone 8c7e40623b Bug 1928254 - pt 5. Rename purge_result_t to avoid confusion with PurgeResult r=jstutte
Differential Revision: https://phabricator.services.mozilla.com/D242667
2025-05-27 08:04:20 +00:00
Serban Stanca 72ddd15355 Revert "Bug 1928254 - pt 8. Improve the idle purge markers r=jstutte" for causing multiple failures.
This reverts commit 1de23dc2a6.

This reverts commit dc7de1e170.

This reverts commit 0891965b10.

This reverts commit 52c855715a.

This reverts commit fcdc85d6b4.

This reverts commit 1fa61503c2.

This reverts commit df279eb40e.

This reverts commit dd4278a7d5.
2025-05-16 08:52:29 +00:00
Paul Bone 1de23dc2a6 Bug 1928254 - pt 8. Improve the idle purge markers r=jstutte
* Group the two kinds of markers for an idle purge into one.  Previously
   one delimited the operation and another one marked the result.  Now the
   result is a field in marker for the whole operation.
 * Rename the RunIdleMemoryCleanup marker to IdlePurge.
 * Rename the marker for peeking at the status to IdlePurgePeek.
 * Move all markers to the GCCC type.

Differential Revision: https://phabricator.services.mozilla.com/D241938
2025-05-16 07:33:13 +00:00
Paul Bone 52c855715a Bug 1928254 - pt 5. Rename purge_result_t to avoid confusion with PurgeResult r=jstutte
Differential Revision: https://phabricator.services.mozilla.com/D242667
2025-05-16 07:33:02 +00:00
Atila Butkovits 77ba9a0aeb Revert "Bug 1928254 - pt 8. Improve the idle purge markers r=jstutte"
This reverts commit 990a75a96b.

Revert "Bug 1928254 - pt 7. Add more details to the Purge marker r=jstutte,profiler-reviewers,canaltinova"

This reverts commit c4b8597e6e.

Revert "Bug 1928254 - pt 6. Move PurgeResult to mozjemalloc_types.h r=jstutte"

This reverts commit 3f6a9d0a98.

Revert "Bug 1928254 - pt 5. Rename purge_result_t to avoid confusion with PurgeResult r=jstutte"

This reverts commit 5a56d09f72.

Revert "Bug 1928254 - pt 4. Add profiler markers for mozjemalloc's Purge() r=florian,profiler-reviewers"

This reverts commit e699aa7901.

Revert "Bug 1928254 - pt 3. Time the purge operation in mozjemalloc r=glandium"

This reverts commit 3b891ccfc3.

Revert "Bug 1928254 - pt 2. Add profiler callbacks for mozjemalloc r=glandium"

This reverts commit 362172ca5b.

Revert "Bug 1928254 - pt 1. Label arenas for the profiler r=glandium"

This reverts commit b1f31febeb.
2025-05-15 05:33:53 +00:00
Paul Bone 990a75a96b Bug 1928254 - pt 8. Improve the idle purge markers r=jstutte
* Group the two kinds of markers for an idle purge into one.  Previously
   one delimited the operation and another one marked the result.  Now the
   result is a field in marker for the whole operation.
 * Rename the RunIdleMemoryCleanup marker to IdlePurge.
 * Rename the marker for peeking at the status to IdlePurgePeek.
 * Move all markers to the GCCC type.

Differential Revision: https://phabricator.services.mozilla.com/D241938
2025-05-15 04:46:27 +00:00
Paul Bone 5a56d09f72 Bug 1928254 - pt 5. Rename purge_result_t to avoid confusion with PurgeResult r=jstutte
Differential Revision: https://phabricator.services.mozilla.com/D242667
2025-05-15 04:46:17 +00:00
Paul Bone 5f1366d65b Bug 1947687 - pt 8. Perform multiple purge steps without checking the list r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D238003
2025-03-13 00:42:35 +00:00
Paul Bone de0e8ed051 Bug 1947687 - pt 4. Simplify some code with a do-while loop r=jstutte
Differential Revision: https://phabricator.services.mozilla.com/D238002
2025-03-13 00:42:33 +00:00
Butkovits Atila fda0bb1a5c Backed out 6 changesets (bug 1947687) for causing SM bustages. CLOSED TREE
Backed out changeset 9012bfccb2cd (bug 1947687)
Backed out changeset 816244cab3f5 (bug 1947687)
Backed out changeset c13b82d1c924 (bug 1947687)
Backed out changeset 0f2a907ba40a (bug 1947687)
Backed out changeset e128af5f021f (bug 1947687)
Backed out changeset 589e781f35c2 (bug 1947687)
2025-03-06 09:42:44 +02:00
Paul Bone b320220434 Bug 1947687 - pt 6. Perform multiple purge steps without checking the list r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D238003
2025-03-06 07:11:56 +00:00
Paul Bone ebd1992045 Bug 1947687 - pt 4. Simplify some code with a do-while loop r=jstutte
Differential Revision: https://phabricator.services.mozilla.com/D238002
2025-03-06 07:11:55 +00:00
Jens Stutte ad5ec08465 Bug 1920451 - Introduce a concept of last significant re-use to decide when to purge. r=pbone,smaug
We want to better predict when it is a good moment to purge. D220616 answered well the question, when to best process a purge when it is needed (that is, during main thread idle time), but that does not necessarily mean it is a good idea for a single arena, to purge in that moment as arenas can be used on other threads intensely while the main thread is idle.

If we saw a recent re-use in an arena we can most likely expect to come more of that and wait with purge a little more. So whenever we are able to re-use a dirty page, we assume that this is a sign of a significant re-use that avoided an allocation of new memory.

We can record a timestamp of when this happened. Unless forced, purge requests are only executed, if their grace period wrt the last significant re-use expired.

Finally we introduce the third result `WantsLater` for a single purge step, which indicates that there are purge requests that wait for their grace period to expire and the main thread should do some later extra spin to process those.

***
Default Atomic

Differential Revision: https://phabricator.services.mozilla.com/D223709
2025-02-19 07:21:15 +00:00
Nika Layzell 52793098be Bug 1945252 - Part 2: Avoid stack sizes which are not a multiple of the system page size, r=glandium
The page size on arm64 macOS and iOS is 16k, yet we try to create stacks with
sizes which are not a multiple of 16k in some situations. Unify these stack
size calculations, and ensure they are always a multiple of the system page
size.

On arm64 macOS, the posix threads implementation is detecting stack sizes which
are a multiple of 4k, and rounding them up to a multiple of 16k to improve
compatibility, but that is not done on iOS.

Differential Revision: https://phabricator.services.mozilla.com/D236402
2025-02-18 21:19:19 +00:00
Jens Stutte 3ddb18be5c Bug 1948736 - Let TaskController::MayScheduleIdleMemoryCleanup bail out on AppShutdown::IsShutdownImpending(). r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D238523
2025-02-18 09:56:46 +00:00
Jeff Muizelaar 52a79d9c33 Bug 1947266 - Use PROFILER_MARKER instead of profiler_add_marker
This cleans up the callsite a little.

Differential Revision: https://phabricator.services.mozilla.com/D237609
2025-02-11 14:29:51 +00:00
Jens Stutte 00d84f5344 Bug 1903758 - Make mozjemalloc have a lazy purge for all arenas via idle processing on the main thread. r=smaug
We can defer the purging of arenas to happen during idle processing on the main thread.

We already have the following prerequisites thanks to bug 1488780:

- The (often) expensive OS functions to give back memory pages are not blocking the use of the arena on other threads anymore.

- A single call to moz_may_purge_one_now (D232083) wraps just arena_t::Purge() that will just do "some work on one chunk" and tell if more is needed, giving us a fine grained control.

Synchronous purging can block the caller of a memory freeing function for an unexpectedly long time. Furthermore, memory that might be reclaimed very soon can be madvised early and thus its reuse can lead to frequent page faults.

We thus use moz_enable_deferred_purge (see D232083) to queue purge requests and execute them on the main thread only if it is about to become idle. We do this using an IdleTaskRunner that ensures we won't purge too often or never.

We believe that the main thread being idle is probably the best easy indicator we have to tell if the process is idle enough to purge without performance regrets.

We expect the peak memory usage of a single arena to not be affected significantly by this during normal use, but the time that this peak holds up might extend. This means the peak sum of all memory from all running processes may rise for short periods of time until enough purges happened on potentially several processes.

There is a chance to mitigate this effect by lowering the settings of allowed dirty pages for arenas, as there should be less churn in general with this patch, potentially resulting in a lower memory usage in average.

Differential Revision: https://phabricator.services.mozilla.com/D220616
2025-01-17 16:13:33 +00:00
Jeff Muizelaar 4735114349 Bug 1933329 - Annotate Task profiler markers with flows r=bas,profiler-reviewers,mstange
Differential Revision: https://phabricator.services.mozilla.com/D230171
2024-11-28 22:15:25 +00:00
Cristina Horotan 3bda16b8c0 Backed out changeset ecaa0a4f3a37 (bug 1933329) for causing crashes at Perfetto.h CLOSED TREE 2024-11-28 04:02:32 +02:00
Jeff Muizelaar 8d73a561c3 Bug 1933329 - Annotate Task profiler markers with flows r=bas,profiler-reviewers,mstange
Differential Revision: https://phabricator.services.mozilla.com/D230171
2024-11-28 01:23:16 +00:00
Jeff Muizelaar 90382b26a5 Bug 1933001 - Add the ability to add the isStackBased property to markers. r=mstange,profiler-reviewers
Setting this property to true is a promise that the the marker will nest
properly.  i.e. it can't have a partially overlapping time range with any other
stack based markers on the same thread.

Differential Revision: https://phabricator.services.mozilla.com/D230006
2024-11-23 03:23:22 +00:00
Olli Pettay f3ce6b3d70 Bug 1923595, don't use GetHeterogeneousCpuInfo on Windows to control the number of TaskController's background threads r=bas
Differential Revision: https://phabricator.services.mozilla.com/D226974
2024-10-26 19:48:59 +00:00
Bas Schouten 378e5333ae Bug 1904957: Implement GetHeterogeneousCpuInfo on Windows and use for TaskController pool size. r=cmartin,smaug
Differential Revision: https://phabricator.services.mozilla.com/D215035
2024-10-02 17:27:32 +00:00
Mike Hommey b62300fe17 Bug 1916883 - Add missing thread safety annotations. r=jesup
that now make clang trunk trip.

Differential Revision: https://phabricator.services.mozilla.com/D221580
2024-09-26 06:23:06 +00:00
Jon Coppeard 987403de0c Bug 1904782 - Part 2: Make TaskController select threads for tasks deterministically r=xpcom-reviewers,nika
This replaces TaskController::mThreadPoolCV with an individual condition
variable for each thread, and uses these to wake individual threads. The task
for each thread is assigned beforehand by setting mCurrentTask.

The counter mIdleThreadCount is used to quickly tell if there are any threads
free.

This splits TaskController::RunPoolThread to move the task selection part to
SelectTaskToRun. MaybeDispatchOneTask is called whenever there may be a new
task to dispatch (this runs from both the main thread and pool threads).

I tried to keep the same behaviour with mEffectiveTaskPriority but I don't
fully understand what this is being used for.

Differential Revision: https://phabricator.services.mozilla.com/D214958
2024-07-11 08:56:13 +00:00
Jon Coppeard dd6eedfbda Bug 1904782 - Part 1: Pass current thread pointer to TaskController::RunPoolThread and refactor r=xpcom-reviewers,nika
This passes a pointer to the current pool thread to RunPoolThread, removing the
need for thread local storage. It also does some refactoring, moving the
PoolThread definition out of the header file.

This also changes the thread vector to use UniquePtr is necessary for the next
patch which adds a CondVar to PoolThread.

Differential Revision: https://phabricator.services.mozilla.com/D214957
2024-07-11 08:56:13 +00:00
Denis Palmeiro 5c062218b6 Bug 1887068: Add perfetto event traces for taskcontroller tasks and dom performance measurement markers. r=smaug
Depends on D205662

Differential Revision: https://phabricator.services.mozilla.com/D205663
2024-04-15 15:34:04 +00:00
Cristina Horotan 886fe5f5a4 Backed out 4 changesets (bug 1887068, bug 1890934) on request by causing build bustages
Backed out changeset 68a7a8a3bb0f (bug 1890934)
Backed out changeset 658f4b57b8ec (bug 1887068)
Backed out changeset 61a9d3a1e592 (bug 1887068)
Backed out changeset efbf5c7065e3 (bug 1887068)
2024-04-12 02:14:44 +03:00
Denis Palmeiro a63122839e Bug 1887068: Add perfetto event traces for taskcontroller tasks and dom performance measurement markers. r=smaug
Depends on D205662

Differential Revision: https://phabricator.services.mozilla.com/D205663
2024-04-10 17:48:08 +00:00
Cristian Tuns d9503794a6 Backed out 3 changesets (bug 1887068) for causing build bustages in toolkit/* CLOSED TREE
Backed out changeset c6863f012b03 (bug 1887068)
Backed out changeset 3a4d2b74219e (bug 1887068)
Backed out changeset 90a702920d77 (bug 1887068)
2024-04-09 18:19:08 -04:00
Denis Palmeiro f61b8829df Bug 1887068: Add perfetto event traces for taskcontroller tasks and dom performance measurement markers. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D205663
2024-04-09 19:05:36 +00:00
Tooru Fujisawa 6381a13f47 Bug 1860969 - Add testcase for incomplete task and rescheduling in TaskController. r=bas
Also fix the null-check.

Differential Revision: https://phabricator.services.mozilla.com/D198504
2024-03-19 03:59:15 +00:00
Olli Pettay e5b50f825f Bug 1874969 - Consider to use GetHeterogeneousCpuInfo when deciding how many background threads TaskController should have, r=mstange
Differential Revision: https://phabricator.services.mozilla.com/D198745
2024-01-17 16:44:08 +00:00
Bas Schouten c185db056d Bug 1869835 - Part 4: Convert TaskMarker to the new MarkerSchema so it gets full ETW support. r=smaug,canaltinova
Differential Revision: https://phabricator.services.mozilla.com/D196375
2023-12-21 18:17:42 +00:00
Olli Pettay 08316ea706 Bug 1869298 - try to insert normal priority main thread tasks to the end, r=bas
Differential Revision: https://phabricator.services.mozilla.com/D196122
2023-12-18 12:26:00 +00:00
Tooru Fujisawa 0b409e3235 Bug 1846407 - Use enum class for Task::Run return value. r=bas,win-reviewers,rkraesig
Differential Revision: https://phabricator.services.mozilla.com/D185043
2023-10-18 15:23:29 +00:00