Bug 106830 - Use MADV_FREE_REUSABLE to return JIT memory to OS
Summary: Use MADV_FREE_REUSABLE to return JIT memory to OS
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Pratik Solanki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-01-14 14:46 PST by Pratik Solanki
Modified: 2013-01-16 10:32 PST (History)
7 users (show)

See Also:


Attachments
Patch (1.64 KB, patch)
2013-01-14 14:52 PST, Pratik Solanki
ggaren: review-
webkit.review.bot: commit-queue-
Details | Formatted Diff | Diff
Patch (2.02 KB, patch)
2013-01-15 15:38 PST, Pratik Solanki
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pratik Solanki 2013-01-14 14:46:29 PST
On OS X versions that support it, use MADV_FREE_REUSABLE to return JIT memory back to OS.
Comment 1 Pratik Solanki 2013-01-14 14:46:59 PST
<rdar://problem/11437701>
Comment 2 Pratik Solanki 2013-01-14 14:49:03 PST
This basically undoes <http://trac.webkit.org/changeset/116593> made in <http://bugs.webkit.org/show_bug.cgi?id=86047>.
Comment 3 Pratik Solanki 2013-01-14 14:52:31 PST
Created attachment 182632 [details]
Patch
Comment 4 WebKit Review Bot 2013-01-14 16:30:07 PST
Comment on attachment 182632 [details]
Patch

Attachment 182632 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/15867662

New failing tests:
inspector-protocol/debugger-terminate-dedicated-worker-while-paused.html
Comment 5 Geoffrey Garen 2013-01-14 19:42:12 PST
Comment on attachment 182632 [details]
Patch

Thanks for tackling this.

This patch has a bug: notifyNeedPage() forgets to MADV_FREE_REUSE.

Let me suggest another approach, which also fixes the bug:

(a) Make a USE(MADV_FREE_FOR_JIT_MEMORY) Platform.h #define, with a comment about MADV_FREE_REUSABLE not working on older OS's.
(b) Set that to true on older OS's
(c) Change "#if OS(DARWIN)" to "#if USE(MADV_FREE_FOR_JIT_MEMORY)" in this file.
Comment 6 Pratik Solanki 2013-01-15 12:26:54 PST
(In reply to comment #5)
> (From update of attachment 182632 [details])
> Thanks for tackling this.
> 
> This patch has a bug: notifyNeedPage() forgets to MADV_FREE_REUSE.

Good catch. I'll fix this.

> Let me suggest another approach, which also fixes the bug:
> 
> (a) Make a USE(MADV_FREE_FOR_JIT_MEMORY) Platform.h #define, with a comment about MADV_FREE_REUSABLE not working on older OS's.
> (b) Set that to true on older OS's
> (c) Change "#if OS(DARWIN)" to "#if USE(MADV_FREE_FOR_JIT_MEMORY)" in this file.

Generally, I hate adding more ifdefs to Platform.h since they cause full world builds. And in this case it feels even more painful since the ifdef will be used only in one source file. Do we have a precedent for using #if local to just one source file? Otherwise I can add it in Platform.h like you suggest.
Comment 7 Geoffrey Garen 2013-01-15 13:03:00 PST
> Generally, I hate adding more ifdefs to Platform.h since they cause full world builds. And in this case it feels even more painful since the ifdef will be used only in one source file. Do we have a precedent for using #if local to just one source file?

I think putting the #if inside this file, instead of Platform.h, is probably fine in this case. There's a small precedent for that in FastMalloc.cpp. (Once things start to span multiple files, Platform.h is probably best, to avoid surprises.)

Also, let's USE(MADV_FREE_FOR_JIT_MEMORY) for PLATFORM(IOS) as well, as we discussed.
Comment 8 Pratik Solanki 2013-01-15 15:38:21 PST
Created attachment 182859 [details]
Patch
Comment 9 Geoffrey Garen 2013-01-15 17:20:22 PST
Comment on attachment 182859 [details]
Patch

r=me
Comment 10 Pratik Solanki 2013-01-15 17:35:04 PST
Committed r139812: <http://trac.webkit.org/changeset/139812>
Comment 11 Darin Adler 2013-01-16 09:18:22 PST
Comment on attachment 182859 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=182859&action=review

> Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp:44
> +// MADV_FREE_REUSABLE does not work for JIT memory on older OSes so use MADV_FREE in that case.

I don’t understand the mention of MADV_FREE_REUSABLE here. I don’t see any code in this file using MADV_FREE_REUSABLE!
Comment 12 Geoffrey Garen 2013-01-16 09:39:47 PST
> I don’t understand the mention of MADV_FREE_REUSABLE here. I don’t see any code in this file using MADV_FREE_REUSABLE!

MADV_FREE_REUSABLE is the default implementation of PageReservation::commit() and PageReservation::decommit(). Maybe the #ifdef should have been about those functions instead.
Comment 13 Pratik Solanki 2013-01-16 10:32:02 PST
(In reply to comment #12)
> > I don’t understand the mention of MADV_FREE_REUSABLE here. I don’t see any code in this file using MADV_FREE_REUSABLE!
> 
> MADV_FREE_REUSABLE is the default implementation of PageReservation::commit() and PageReservation::decommit(). Maybe the #ifdef should have been about those functions instead.

Thats right. I guess the comment could have been clearer. Maybe something like

"PageReservation::decommit() uses MADV_FREE_REUSABLE which does not work with JIT memory on older OSes. Use MADV_FREE in such cases."

I can make that change if that sounds good.