WorkerPool(s) use memory in browser after tabs are closed |
||||||||
Issue descriptionBackground context:go/memory-infra: memory profiling in chrome://tracing After opening and closing tabs, the WorkerPool(s) are not evicted even after 1 minute wait time after closing tabs. This uses a lot of memory in chrome. When Chrome is started and left with just new tab page there are 3-5 Worker threads alive after 2 minutes. But in the same 2 minutes if few tabs are opened and closed, the number of worker threads is 6-8, and most of these threads retain the memory allocated. The difference in malloc usage in browser is 20Mib and 8-9Mib are due to extra WorkerPool threads. Memory is allocated from WorkerThread::ThreadMain::Run. These trace file shows which thread use extra memory in browser. You will find WorkerPool/n multiple times in the heap details. Trace file with actions: https://drive.google.com/open?id=0B7f4beGia2iHM3l5dVlPZmtYM3M Trace file without actions: https://drive.google.com/open?id=0B7f4beGia2iHbXZiM3ZTQWFUTFk Instructions for opening the trace. Use recent Chrome build. Open chrome://tracing and load the json file. Click on the red dot in the first row. Click on "malloc" column on Browser process. See the "Heap details" section. Sort with "size" column for easy reading. See https://goo.gl/QNq8Mx for how the traces were taken and where the information comes from. This tool is experimental and not yet available for developers.
,
Mar 10 2016
I'm no longer working on Chromium. I've removed myself from the cc list. Some comments though. The original constant was set as a magic number when we were porting Chromium to Linux. It was meant to mimic the Windows system thread pool, which IIRC, kept idle threads around for minutes too. This was more important for Windows where thread creation is costlier. Reaping worker threads more aggressively seems reasonable to me. Cheers.
,
Mar 10 2016
+Lei who reviewed the last CL in this file. WDYT?
,
Mar 10 2016
+some folks working on simplify task management to see whether they have some insight.
,
Mar 10 2016
I am not sure about the performance, but the malloc usage reduces by 10% (private_dirty by 6-7%) in benchmarks if the idle thread is exited in 3 secs instead of 600. See results of running a page cycler, better if I run it more number of times since the malloc usage usually keeps increasing. Check the metrics "malloc_browser" and "private_dirty_browser".
,
Mar 10 2016
It seems 1_run is better, but 5_run is worse. Also can you get the data from an Android device too? Thanks.
,
Mar 10 2016
Some speculation: It would be surprising to me if the worker threads inherently allocated this memory. The problem might not be so much that the threads are running (it would be good if they go away sooner) but rather that when the tab is closed, resources are not reclaimed in a timely fashion and should be decoupled from the thread lifetime.
,
Mar 10 2016
Agreed with Rob that the issue seems to be that the memory and thread lifetime should be decoupled. However good news is we're refactoring the worker task model in Chrome right now and WorkerPool will be one of the first candidates for deprecation. If the issue is improper memory vs thread lifetime though, the new framework may also not be able to do much about that (besides having control on unused thread termination).
,
Mar 10 2016
@klobag I think you got confused since the one with 3 seconds comes first. Killing the threads aggressively saves some memory. Yes, I understand that the memory allocated itself is not fully coupled with the thread's lifetime. Investigating more I found that the worker threads were created for network certificate verification. But there is already a bug filed for this crbug.com/593486 . Yes, I think the main problem left here is to termite the unused threads. Especially on android which is good even if it just saves few hundred Kib needed to keep an idle thread alive. wdyt? Could you please share a design doc or bug for the new worker thread model and timeline? I do not fully understand how the unused threads can be terminated in the current model. Can it be?
,
Mar 10 2016
Design Doc (chromium.org): https://docs.google.com/a/chromium.org/document/d/1S2AAeoo1xa_vsLbDYBsDHCqhrkfiMgoIPlyRi6kxa5k/edit?usp=sharing Agreed that cleaning up an idle thread would be good, but as you say it's inherently only a few KiB. The larger issue here is coupling of the memory lifetime with the thread. The worker threads may be reused for other purposes, and so this separate cleanup should happen independent on the thread lifetime.
,
Nov 25 2016
,
Jan 4 2017
,
Aug 2 2017
This bug is available, yet hasn't been updated in >180 days. Dropping the priority.
,
Aug 2 2017
WorkerPool is going away in favor of TaskScheduler (which does properly reclaim inactive threads). We are working on the last few edge cases right now and expect full deprecation this quarter as such efforts on WorkerPool are not worth it. |
||||||||
►
Sign in to add a comment |
||||||||
Comment 1 by ssid@chromium.org
, Mar 9 2016