Closed Bug 1895846 Opened 1 year ago Closed 10 hours ago

Make SharedThreadPool less volatile

Categories

(Core :: XPCOM, task)

task

Tracking

()

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: jstutte, Assigned: jstutte)

References

(Blocks 1 open bug)

Details

Attachments

(3 files, 5 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Currently SharedThreadPool shuts down a pool as soon as consumers do not hold a reference to it. In case of consumers acquiring a new reference frequently without keeping it across uses, this can lead to many thread shutdowns and re-creations. MediaPDecoder seems to be an example of such usage. It seems in WebRTC code we added some AddRef calls here and there to account for this.

It might be easier for consumers, if SharedThreadPool keeps an ever-used pool alive until shutdown. If it is really not used for a while, all its threads will be closed and we would just consume the thread pool's object memory.

Assignee: nobody → jstutte
Status: NEW → ASSIGNED
No longer depends on: 1891936

Looking at how SharedThreadPool manages its shutdown I came across:

nsThreadPool::PutEvent bails out on shutdown regardless of the source of an event.

if (NS_WARN_IF(mShutdown && !IsOnCurrentThreadInfallible())) might be a better choice, together with avoiding to spawn a new thread below when mShutdown (the one we are running on can just take the event).

which might deserve an own bug.

Duplicate of this bug: 1895165

We might also want to consider renaming SharedThreadPool.

See Also: → 1898040
Attachment #9400878 - Attachment is obsolete: true
Attachment #9501718 - Attachment description: WIP: Bug 1895846 - Have SharedThreadPoolHolder to avoid some fiddly AddRefs. r?#xpcom-reviewers → Bug 1895846 - Have SharedThreadPoolHolder to avoid some fiddly AddRefs. r?#xpcom-reviewers
Attachment #9501719 - Attachment description: WIP: Bug 1895846 - Have a grace timeout for SharedThreadPool. r?#xpcom-reviewers → Bug 1895846 - Have a grace timeout for SharedThreadPool. r?#xpcom-reviewers
See Also: → 1978758
Attachment #9501751 - Attachment description: Bug 1895846 - Ensure PostTimerEvent will not release anything important while holding the monitor's lock. r?#xpcom-reviewers → WIP: Bug 1895846 - Ensure PostTimerEvent will not release anything important while holding the monitor's lock. r?#xpcom-reviewers
Attachment #9501718 - Attachment is obsolete: true
Attachment #9501719 - Attachment is obsolete: true
Attachment #9501751 - Attachment description: WIP: Bug 1895846 - Ensure PostTimerEvent will not release anything important while holding the monitor's lock. r?#xpcom-reviewers → Bug 1895846 - Ensure PostTimerEvent will not release anything important while holding the monitor's lock. r?#xpcom-reviewers
Attachment #9519806 - Attachment description: WIP: Bug 1895846 - Keep SharedThreadPool instances until shutdown but close idle threads earlier. r?#xpcom-reviewers → Bug 1895846 - Keep SharedThreadPool instances until shutdown but close idle threads earlier. r?#xpcom-reviewers
Attachment #9520716 - Attachment is obsolete: true
Attachment #9519806 - Attachment description: Bug 1895846 - Keep SharedThreadPool instances until shutdown but close idle threads earlier. r?#xpcom-reviewers → WIP: Bug 1895846 - Keep SharedThreadPool instances until shutdown but close idle threads earlier. r?#xpcom-reviewers
Attachment #9519806 - Attachment description: WIP: Bug 1895846 - Keep SharedThreadPool instances until shutdown but close idle threads earlier. r?#xpcom-reviewers → Bug 1895846 - Keep SharedThreadPool instances until shutdown but close idle threads earlier. r?#xpcom-reviewers
Depends on: 1999508
Depends on: 1999509
No longer depends on: 1999509
See Also: → 1999509

Comment on attachment 9501751 [details]
Bug 1895846 - Ensure PostTimerEvent will not release anything important while holding the monitor's lock. r?#xpcom-reviewers

Revision D257966 was moved to bug 1999508. Setting attachment 9501751 [details] to obsolete.

Attachment #9501751 - Attachment is obsolete: true

Now that all SharedThreadPools are explicitly shutdown regardless of other objects still referencing them, we can leverage the shutdown tasks also here to shut down associated TaskQueues (and maybe other things registering in the future).

See Also: → 1824294
Blocks: 2011090
Pushed by jstutte@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/654244600cf5 https://hg.mozilla.org/integration/autoland/rev/e85d06f7dc60 Add SharedThreadPool logging. r=xpcom-reviewers,nika https://github.com/mozilla-firefox/firefox/commit/b4b3a6c71af6 https://hg.mozilla.org/integration/autoland/rev/6976ad06cf8d Keep SharedThreadPool instances until shutdown but close idle threads earlier. r=xpcom-reviewers,media-playback-reviewers,nika,karlt https://github.com/mozilla-firefox/firefox/commit/0fc599421fc2 https://hg.mozilla.org/integration/autoland/rev/dc866ea7c36b Forward Un/RegisterShutdownTask to the underlying pool in SharedThreadPool. r=xpcom-reviewers,nika
Status: ASSIGNED → RESOLVED
Closed: 10 hours ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: