WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
171289
Call bmalloc scavenger first when handling a memory pressure event
https://bugs.webkit.org/show_bug.cgi?id=171289
Summary
Call bmalloc scavenger first when handling a memory pressure event
Michael Saboff
Reported
2017-04-25 14:04:43 PDT
When we are responding to a memory pressure notification, we free up invoke the release memory handlers for various subsystems and then call the bmalloc scavenger synchronously to free pages back to the OS. There is a very good chance that when we receieve the low memory event that we already have physical free pages that we can immediately return to the OS for use. Therefore we should invoke the bmalloc scavenger first in the release memory handler as well as at the end as we currently do. <
rdar://problem/31820242
>
Attachments
Patch
(1.37 KB, patch)
2017-04-25 14:09 PDT
,
Michael Saboff
ggaren
: review-
Details
Formatted Diff
Diff
Updated Patch
(3.23 KB, patch)
2017-04-25 16:07 PDT
,
Michael Saboff
ggaren
: review+
Details
Formatted Diff
Diff
Speculative build fix for EWS - added #include
(3.27 KB, patch)
2017-04-25 16:29 PDT
,
Michael Saboff
no flags
Details
Formatted Diff
Diff
Another EWS build fix
(3.30 KB, patch)
2017-04-25 16:35 PDT
,
Michael Saboff
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Michael Saboff
Comment 1
2017-04-25 14:09:31 PDT
Created
attachment 308142
[details]
Patch
Geoffrey Garen
Comment 2
2017-04-25 14:47:26 PDT
I think we need a handler in bmalloc. Otherwise, stand-alone JavaScriptCore clients won't get the benefit. Here's roughly the code we need (in a Darwin-only file): dispatch_async(dispatch_get_main_queue(), ^{ m_cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue()); dispatch_source_set_event_handler(m_cache_event_source, ^{ scavenge(); }); dispatch_resume(m_cache_event_source); });
Geoffrey Garen
Comment 3
2017-04-25 14:58:52 PDT
(In reply to Geoffrey Garen from
comment #2
)
> I think we need a handler in bmalloc. Otherwise, stand-alone JavaScriptCore > clients won't get the benefit. Here's roughly the code we need (in a > Darwin-only file): > > dispatch_async(dispatch_get_main_queue(), ^{ > m_cache_event_source = > dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, > DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue()); > dispatch_source_set_event_handler(m_cache_event_source, ^{ > scavenge(); > }); > dispatch_resume(m_cache_event_source); > });
...actually, we want to schedule our source on a custom queue, so it can run on any thread.
Geoffrey Garen
Comment 4
2017-04-25 15:08:10 PDT
... we can also add this line in WebCore, to double-super guarantee WebCore behavior. There's no cost to scavenging twice: the second scavenge will be a cheap no-op.
Michael Saboff
Comment 5
2017-04-25 16:07:58 PDT
Created
attachment 308158
[details]
Updated Patch
Build Bot
Comment 6
2017-04-25 16:09:08 PDT
Attachment 308158
[details]
did not pass style-queue: ERROR: Source/bmalloc/bmalloc/Heap.cpp:27: Alphabetical sorting problem. [build/include_order] [4] Total errors found: 1 in 4 files If any of these errors are false positives, please file a bug against check-webkit-style.
Geoffrey Garen
Comment 7
2017-04-25 16:10:29 PDT
Comment on
attachment 308158
[details]
Updated Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=308158&action=review
r=me
> Source/bmalloc/bmalloc/Heap.cpp:54 > + auto queue = dispatch_queue_create("WebKit Malloc Memory Pressure Handler", DISPATCH_QUEUE_CONCURRENT);
It's a very minor point, but this should be DISPATCH_QUEUE_SERIAL, because we don't intend to handle multiple concurrent pressure events.
Michael Saboff
Comment 8
2017-04-25 16:13:23 PDT
(In reply to Geoffrey Garen from
comment #7
)
> Comment on
attachment 308158
[details]
> > Source/bmalloc/bmalloc/Heap.cpp:54 > > + auto queue = dispatch_queue_create("WebKit Malloc Memory Pressure Handler", DISPATCH_QUEUE_CONCURRENT); > > It's a very minor point, but this should be DISPATCH_QUEUE_SERIAL, because > we don't intend to handle multiple concurrent pressure events.
I made that change locally.
Michael Saboff
Comment 9
2017-04-25 16:29:49 PDT
Created
attachment 308164
[details]
Speculative build fix for EWS - added #include
Michael Saboff
Comment 10
2017-04-25 16:35:57 PDT
Created
attachment 308165
[details]
Another EWS build fix
Michael Saboff
Comment 11
2017-04-25 17:39:24 PDT
Committed
r215775
: <
http://trac.webkit.org/changeset/215775
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug