OSX does not quickly reclaim unused memory

RESOLVED WONTFIX

Status

()

Core
Memory Allocator
RESOLVED WONTFIX
2 years ago
2 years ago

People

(Reporter: Michal K, Unassigned)

Tracking

45 Branch
x86_64
Mac OS X
Points:
---

Firefox Tracking Flags

(e10s+)

Details

(Whiteboard: [MemShrink:P2])

Attachments

(3 attachments)

(Reporter)

Description

2 years ago
Created attachment 8722667 [details]
start.png

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Firefox/45.0
Build ID: 20160221141421

Steps to reproduce:

I test the latest Firefox 45.0b8 with e10s with all addons disabled. I noticed that the garbage collection in "Firefox Web Content" process either doesn't perform / work or doesn't perform well. 

Here are the steps to reproduce it: 

1. Open at least 25 tabs, for example these: 

http://www.nytimes.com/?WT.z_jog=1&hF=f&vS=undefined
http://www.tomshardware.com/
http://edition.cnn.com/
https://www.mozilla.org/cs/
http://www.csfd.cz/
http://www.spiegel.de/
http://www.nytimes.com/
http://www.e15.cz/
http://ihned.cz/
http://www.macrumors.com/
http://www.macworld.com/
http://jablickar.cz/
http://appleinsider.com/
http://www.cnews.cz/hardware
http://www.apple.com/
http://www.mobilmania.cz/
http://f1sport.autorevue.cz/
https://www.youtube.com/
http://www.theverge.com/
http://techcrunch.com/
http://www.novinky.cz/
http://www.aktualne.cz/
http://www.lidovky.cz/
http://www.idnes.cz/
http://www.zive.cz/

2. Wait until all of them are loaded. Select one tab - for example: www.zive.cz 
Actual memory consumption of "Firefox Web Content" process is about 1 GB.  

3. Make right click on the selected tab (www.zive.cz) and click on "Close Other Tabs". After the action, only one tab is shown and memory consumption is still about 1 GB. Do not close the window with opened tab and wait 10 mins

4. Check the consumed memory of "Firefox Web Content" process after 10 mins. "Firefox Web Content" process still consumes around 980 MB with only one opened tab (www.zive.cz). Minimum of memory was released. 

Garbage collection almost did not release any memory despite of all tabs were closed except the one.
However if I open new tab with about:memory and click on "Minimize memory usage" and click on "Measure" after 1 min, then the memory is released and "Firefox Web Content" process consumes only about 370MB, which is good. So I assume that the garbage collection is not triggered? I attached the screenshots of consumed memory.

about:support output: 

Stručně o aplikaci
------------------

Název: Firefox
Verze: 45.0b8
Id buildu: 20160221141421
Kanál aktualizací: beta
Identifikace prohlížeče: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Firefox/45.0
Multiprocesová okna: 1/1 (výchozí: true)
Nouzový režim: false

Hlášení o pádech za poslední 3 dny
----------------------------------

Všechna hlášení o pádech

Rozšíření
---------

Název: Firefox Hello Beta
Verze: 0.1
Povoleno: true
Id: loop@mozilla.org

Název: ADB Helper
Verze: 0.8.6
Povoleno: false
Id: adbhelper@mozilla.org

Název: DownThemAll!
Verze: 2.0.18.1-signed.1-let-fixed
Povoleno: false
Id: {DDC359D1-844A-42a7-9AA1-88A850A938A8}

Název: Firebug
Verze: 2.0.13
Povoleno: false
Id: firebug@software.joehewitt.com

Název: Google Translator for Firefox
Verze: 2.1.0.5.1
Povoleno: false
Id: translator@zoli.bod

Název: uBlock Origin
Verze: 1.5.5
Povoleno: false
Id: uBlock0@raymondhill.net

Název: Valence
Verze: 0.3.4
Povoleno: false
Id: fxdevtools-adapters@mozilla.org

Grafika
-------

Asynchronní lupa/panning: nic
Grafická akcelerace oken: 1/1 OpenGL (OMTC)
Id výrobce: 0x8086
Id zařízení: 0x0166
Podporuje hardwarové dekódování H264: No;
windowLayerManagerRemote: true
Zobrazování WebGL: Intel Inc. -- Intel HD Graphics 4000 OpenGL Engine
AzureCanvasBackend: skia
AzureContentBackend: quartz
AzureFallbackCanvasBackend: none
AzureSkiaAccelerated: 1

Důležité změněné předvolby
--------------------------

accessibility.blockautorefresh: true
accessibility.browsewithcaret: true
accessibility.typeaheadfind: true
accessibility.typeaheadfind.flashBar: 0
browser.cache.disk.capacity: 358400
browser.cache.disk.filesystem_reported: 1
browser.cache.disk.smart_size.first_run: false
browser.cache.frecency_experiment: 4
browser.download.importedFromSqlite: true
browser.download.useDownloadDir: false
browser.places.smartBookmarksVersion: 7
browser.sessionstore.upgradeBackup.latestBuildID: 20160221141421
browser.startup.homepage: about:newtab
browser.startup.homepage_override.buildID: 20160221141421
browser.startup.homepage_override.mstone: 45.0
browser.tabs.loadInBackground: false
browser.tabs.remote.autostart: true
browser.tabs.remote.autostart.2: false
browser.urlbar.trimURLs: false
browser.urlbar.userMadeSearchSuggestionsChoice: true
browser.zoom.full: false
dom.apps.reset-permissions: true
dom.mozApps.used: true
extensions.lastAppVersion: 45.0
gfx.blacklist.direct2d: 3
gfx.crash-guard.glcontext.appVersion: 45.0
gfx.crash-guard.glcontext.deviceID: 0x0166
gfx.crash-guard.status.glcontext: 2
media.gmp-gmpopenh264.abi: x86_64-gcc3-u-i386-x86_64
media.gmp-gmpopenh264.enabled: true
media.gmp-gmpopenh264.lastUpdate: 1450806961
media.gmp-gmpopenh264.version: 1.5.3
media.gmp-manager.buildID: 20160221141421
media.gmp-manager.lastCheck: 1456261168
media.mediasource.webm.enabled: true
network.cookie.cookieBehavior: 3
network.cookie.lifetimePolicy: 2
network.cookie.prefsMigrated: true
network.predictor.cleaned-up: true
places.database.lastMaintenance: 1455829669
places.history.expiration.transient_current_max_pages: 104858
plugin.disable_full_page_plugin_for_types: application/pdf
plugin.importedState: true
plugin.state.default browser: 0
plugin.state.flash: 0
plugin.state.java: 0
print.print_bgcolor: false
print.print_bgimages: false
print.print_colorspace:
print.print_command:
print.print_downloadfonts: false
print.print_duplex: 1515870810
print.print_evenpages: true
print.print_in_color: true
print.print_margin_bottom: 0.5
print.print_margin_left: 0.5
print.print_margin_right: 0.5
print.print_margin_top: 0.5
print.print_oddpages: true
print.print_orientation: 0
print.print_page_delay: 50
print.print_paper_data: 0
print.print_paper_height: 11.00
print.print_paper_name:
print.print_paper_size_type: 1
print.print_paper_size_unit: 0
print.print_paper_width: 8.50
print.print_plex_name:
print.print_resolution: 1515870810
print.print_resolution_name:
print.print_reversed: false
print.print_scaling: 1.00
print.print_shrink_to_fit: true
print.print_to_file: false
print.print_unwriteable_margin_bottom: 57
print.print_unwriteable_margin_left: 25
print.print_unwriteable_margin_right: 25
print.print_unwriteable_margin_top: 25
print.printer_Canon_MG5200_series__069A8E000000.print_bgcolor: false
print.printer_Canon_MG5200_series__069A8E000000.print_bgimages: false
print.printer_Canon_MG5200_series__069A8E000000.print_duplex: 1515870810
print.printer_Canon_MG5200_series__069A8E000000.print_edge_bottom: 0
print.printer_Canon_MG5200_series__069A8E000000.print_edge_left: 0
print.printer_Canon_MG5200_series__069A8E000000.print_edge_right: 0
print.printer_Canon_MG5200_series__069A8E000000.print_edge_top: 0
print.printer_Canon_MG5200_series__069A8E000000.print_evenpages: true
print.printer_Canon_MG5200_series__069A8E000000.print_footercenter:
print.printer_Canon_MG5200_series__069A8E000000.print_footerleft: &PT
print.printer_Canon_MG5200_series__069A8E000000.print_footerright: &D
print.printer_Canon_MG5200_series__069A8E000000.print_headercenter:
print.printer_Canon_MG5200_series__069A8E000000.print_headerleft: &T
print.printer_Canon_MG5200_series__069A8E000000.print_headerright: &U
print.printer_Canon_MG5200_series__069A8E000000.print_in_color: true
print.printer_Canon_MG5200_series__069A8E000000.print_margin_bottom: 0.5
print.printer_Canon_MG5200_series__069A8E000000.print_margin_left: 0.5
print.printer_Canon_MG5200_series__069A8E000000.print_margin_right: 0.5
print.printer_Canon_MG5200_series__069A8E000000.print_margin_top: 0.5
print.printer_Canon_MG5200_series__069A8E000000.print_oddpages: true
print.printer_Canon_MG5200_series__069A8E000000.print_orientation: 0
print.printer_Canon_MG5200_series__069A8E000000.print_page_delay: 50
print.printer_Canon_MG5200_series__069A8E000000.print_paper_data: 0
print.printer_Canon_MG5200_series__069A8E000000.print_paper_height: 11.00
print.printer_Canon_MG5200_series__069A8E000000.print_paper_name:
print.printer_Canon_MG5200_series__069A8E000000.print_paper_size_type: 1
print.printer_Canon_MG5200_series__069A8E000000.print_paper_size_unit: 0
print.printer_Canon_MG5200_series__069A8E000000.print_paper_width: 8.50
print.printer_Canon_MG5200_series__069A8E000000.print_resolution: 1515870810
print.printer_Canon_MG5200_series__069A8E000000.print_reversed: false
print.printer_Canon_MG5200_series__069A8E000000.print_scaling: 1.00
print.printer_Canon_MG5200_series__069A8E000000.print_shrink_to_fit: true
print.printer_Canon_MG5200_series__069A8E000000.print_to_file: false
print.printer_Canon_MG5200_series__069A8E000000.print_unwriteable_margin_bottom: 20
print.printer_Canon_MG5200_series__069A8E000000.print_unwriteable_margin_left: 13
print.printer_Canon_MG5200_series__069A8E000000.print_unwriteable_margin_right: 13
print.printer_Canon_MG5200_series__069A8E000000.print_unwriteable_margin_top: 12
privacy.clearOnShutdown.downloads: false
privacy.clearOnShutdown.history: false
privacy.clearOnShutdown.offlineApps: true
privacy.cpd.extensions-dta: true
privacy.cpd.offlineApps: true
privacy.cpd.siteSettings: true
privacy.donottrackheader.enabled: true
privacy.sanitize.didShutdownSanitize: true
privacy.sanitize.migrateClearSavedPwdsOnExit: true
privacy.sanitize.migrateFx3Prefs: true
privacy.sanitize.sanitizeInProgress: ["cache","cookies","offlineApps","formdata","sessions"]
privacy.sanitize.sanitizeOnShutdown: true
services.sync.declinedEngines:
services.sync.engine.adblockplus: true
storage.vacuum.last.index: 0
storage.vacuum.last.places.sqlite: 1456261640

Důležité uzamčené předvolby
---------------------------

JavaScript
----------

Inkrementální GC: true

Přístupnost
-----------

Aktivována: false
Zakázána: 0

Verze knihoven
--------------

NSPR
Očekávaná minimální verze: 4.11
Používaná verze: 4.11

NSS
Očekávaná minimální verze: 3.21 Basic ECC
Používaná verze: 3.21 Basic ECC

NSSSMIME
Očekávaná minimální verze: 3.21 Basic ECC
Používaná verze: 3.21 Basic ECC

NSSSSL
Očekávaná minimální verze: 3.21 Basic ECC
Používaná verze: 3.21 Basic ECC

NSSUTIL
Očekávaná minimální verze: 3.21
Používaná verze: 3.21

Experimentální funkce
---------------------

Název: Multi-process Firefox A/B Test 45.2
Id: e10s-beta45-withoutaddons@experiments.mozilla.org
Popis: Measure the effect of multi-process Firefox
Aktivní: false
Koncové datum: 1455828486005
Domovská stránka:
Větev: user-disabled

Název: Multi-process Firefox A/B Test 45.1
Id: e10s-beta45-withaddons@experiments.mozilla.org
Popis: Measure the effect of multi-process Firefox
Aktivní: false
Koncové datum: 1454440428284
Domovská stránka:
Větev: user-disabled



Actual results:

Consumed memory by "Firefox Web Content" process is not released after all tabs are closed except the selected one.


Expected results:

Consumed memory by "Firefox Web Content" process should be significantly decreased. Similar to the situation of clicking on "Minimize memory usage".
(Reporter)

Comment 1

2 years ago
Created attachment 8722668 [details]
10_mins_later.png
(Reporter)

Comment 2

2 years ago
Created attachment 8722669 [details]
afer_minimization.png

Updated

2 years ago
Blocks: 516752

Updated

2 years ago
Component: Untriaged → JavaScript: GC
Product: Firefox → Core
Whiteboard: [MemShrink]
I will try to repro, it seems like AWSY would have caught something like this.
Flags: needinfo?(erahm)
Whiteboard: [MemShrink] → [MemShrink:P2]
One possibility is that we are somehow not properly triggering GCs on page close, but only on page load, so the way AWSY ends by loading about:blank would miss this.
I was unable to reproduce this with a Nightly build with a clean profile on OSX 10.11. I open all pages, measured memory, let it sit 10 minutes, closed all pages but one, waited a minute, measured memory again and saw a 1GB drop in explicit.

I can confirm that visually in activity monitor it looked like we were using a lot of memory (FWIW using activity monitor to measure memory is a bit tricky) prior to measuring the final time.

By measuring (I didn't minimize in this case) we invoke the double-purge path of jemalloc [1] which tells the OS to take back pages we've freed so that we get a more realistic measurement.

So to sum up: it may look like we're using a lot of memory, but the OS just hasn't reclaimed the memory we freed yet. Please see [1] for more details.

[1] https://dxr.mozilla.org/mozilla-central/rev/e7319545eb3819da67ffe1d4233022ae71e3a9a1/xpcom/base/nsMemoryReporterManager.cpp#430-455
Flags: needinfo?(erahm)
(Reporter)

Comment 6

2 years ago
(In reply to Eric Rahm [:erahm] (Out until 3/10) from comment #5)
> I was unable to reproduce this with a Nightly build with a clean profile on
> OSX 10.11. I open all pages, measured memory, let it sit 10 minutes, closed
> all pages but one, waited a minute, measured memory again and saw a 1GB drop
> in explicit.
> 
> I can confirm that visually in activity monitor it looked like we were using
> a lot of memory (FWIW using activity monitor to measure memory is a bit
> tricky) prior to measuring the final time.
> 
> By measuring (I didn't minimize in this case) we invoke the double-purge
> path of jemalloc [1] which tells the OS to take back pages we've freed so
> that we get a more realistic measurement.
> 
> So to sum up: it may look like we're using a lot of memory, but the OS just
> hasn't reclaimed the memory we freed yet. Please see [1] for more details.
> 
> [1]
> https://dxr.mozilla.org/mozilla-central/rev/
> e7319545eb3819da67ffe1d4233022ae71e3a9a1/xpcom/base/nsMemoryReporterManager.
> cpp#430-455

Thank you for your explanation. It is reasonable. Maybe one remark / wish:

Could be possible to invoke "double-purge path" after closing of tab (immediate or some time later), so that OS X will take back the freed memory and activity monitor will show more accurate memory's consumption? Because it is very strange for the common user to see in activity monitor consumed 1 GB with opened 1 tab for long time period. Common user doesn't know about things like about:memory.

Updated

2 years ago
Flags: needinfo?(twalker)
Following the steps in comment 0 (description), I see memory being held onto only on Mac as follows.

Windows 7 (VM), Nightly 48.0.a1, 20160324030447:
Memory usage at 1.1G,drops to ~418M shortly after "Close other tabs" (within a minute)

Ubuntu 14.04 (VM), Nightly 48.0a1, 20160324030447:
Memory usage at ~420M, drops to ~120M shortly after "Close other tabs" (within 30 seconds)

Mac 10.11, Nightly 48.0a1, 20160324030447:
Memory usage at ~870M, stays at that level long after "Close other tabs"
Flags: needinfo?(twalker)
It is almost as bad on release Firefox on Mac.

Firefox 45.0.1, 20160315153207:
Memory usage at 1.68G, drops to 1.44G after about a minute after "Close other tabs"

As such I don't think the bug e10s specific.
Status: UNCONFIRMED → NEW
tracking-e10s: --- → ?
Ever confirmed: true
OS: Unspecified → Mac OS X
Hardware: Unspecified → x86_64
Kyle, can you look into this?
tracking-e10s: ? → +
Flags: needinfo?(khuey)
Not really ... I have a bunch of other things to do and don't even have a Mac. mccr8? erahm?
Flags: needinfo?(khuey)
Flags: needinfo?(erahm)
Flags: needinfo?(continuation)
See comment 5.
Component: JavaScript: GC → Memory Allocator
Flags: needinfo?(erahm)
Flags: needinfo?(continuation)
Summary: [e10s] Garbage collection in "Firefox Web Content" process doesn't perform automatically / well → OSX does not quickly reclaim unused memory
(In reply to Michal K from comment #6)
> Common user doesn't know about things like about:memory.

I see where you are coming from, but the common user is not looking at the Activity Monitor either. :)
(In reply to Andrew McCreight [:mccr8] from comment #11)
> See comment 5.

Then should this be INVALID?
(Reporter)

Comment 14

2 years ago
(In reply to Andrew McCreight [:mccr8] from comment #12)
> (In reply to Michal K from comment #6)
> > Common user doesn't know about things like about:memory.
> 
> I see where you are coming from, but the common user is not looking at the
> Activity Monitor either. :)

(In reply to Andrew McCreight [:mccr8] from comment #12)
> (In reply to Michal K from comment #6)
> > Common user doesn't know about things like about:memory.
> 
> I see where you are coming from, but the common user is not looking at the
> Activity Monitor either. :)

You almost got me :-) But what about a browser's reviews in internet's media. Tech media usually makes browser's comparisons from time to time and they could write incorrect information about Firefox's memory's consumption - something like "memory hog" for example. Google Chrome is/was known for it.
It is public known, that e10s will spend about 20% more memory than single process version, so somebody could/will start to watch it especially when tech media will write about it.

At the end I think, that this problem/lack should not be omitted especially when you are doing hard work of GC's performance and improvements.
In case the history is not clear, we had clear metrics that double purging causes jank in bug 789975 and the decision was made to scrap the use of it in telemetry:

> (Justin Lebar (not reading bugmail) from bug 789975, comment #18)
> It pains me greatly to do it, but I think we should simply pref the purging off.  It's more important not to jank even 1% of users users than it is to get good memory metrics.

There's already been a fair amount of discussion around the tradeoff of making the perception of memory usage better vs causing jank. Adding jank each time you close a tab is certainly not desirable either.

I'm going to close this so as to avoid the misconception that this is an actual memory issue (in the potential for OOM sense, as bug 1259512 seems to imply).
Status: NEW → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → WONTFIX
(In reply to Michal K from comment #14)
> You almost got me :-) But what about a browser's reviews in internet's
> media. Tech media usually makes browser's comparisons from time to time and
> they could write incorrect information about Firefox's memory's consumption
> - something like "memory hog" for example. Google Chrome is/was known for it.
> It is public known, that e10s will spend about 20% more memory than single
> process version, so somebody could/will start to watch it especially when
> tech media will write about it.
> 
> At the end I think, that this problem/lack should not be omitted especially
> when you are doing hard work of GC's performance and improvements.

The solution is for us to be proactive and open about measuring our memory usage as well as other browsers. I've provided a (somewhat basic) open source framework for this with atsy [1] and posted results previously [2, 3].

[1] https://github.com/EricRahm/atsy
[2] http://www.erahm.org/2016/02/11/memory-usage-of-firefox-with-e10s-enabled/
[3] http://www.erahm.org/2016/02/12/are-they-slim-yet/
(Reporter)

Comment 17

2 years ago
(In reply to Eric Rahm [:erahm] from comment #16)
> (In reply to Michal K from comment #14)
> > You almost got me :-) But what about a browser's reviews in internet's
> > media. Tech media usually makes browser's comparisons from time to time and
> > they could write incorrect information about Firefox's memory's consumption
> > - something like "memory hog" for example. Google Chrome is/was known for it.
> > It is public known, that e10s will spend about 20% more memory than single
> > process version, so somebody could/will start to watch it especially when
> > tech media will write about it.
> > 
> > At the end I think, that this problem/lack should not be omitted especially
> > when you are doing hard work of GC's performance and improvements.
> 
> The solution is for us to be proactive and open about measuring our memory
> usage as well as other browsers. I've provided a (somewhat basic) open
> source framework for this with atsy [1] and posted results previously [2, 3].
> 
> [1] https://github.com/EricRahm/atsy
> [2]
> http://www.erahm.org/2016/02/11/memory-usage-of-firefox-with-e10s-enabled/
> [3] http://www.erahm.org/2016/02/12/are-they-slim-yet/

Thank you for the feedback and efforts. I'll look at the links. Anyway you are doing very well with e10s.
You need to log in before you can comment on or make changes to this bug.