Bug 200807 - [JSC] WebAssembly BBQ should switch compile mode for size of modules
Summary: [JSC] WebAssembly BBQ should switch compile mode for size of modules
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
: 200686 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-08-15 23:18 PDT by Yusuke Suzuki
Modified: 2020-01-15 17:39 PST (History)
10 users (show)

See Also:


Attachments
Patch (9.19 KB, patch)
2019-08-16 02:49 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (9.73 KB, patch)
2019-08-16 18:57 PDT, Yusuke Suzuki
mark.lam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2019-08-15 23:18:28 PDT
On ARM devices, our fixed executable memory size is only 128MB, and it cannot be expanded further since 128MB is the maximum value of relative jump in ARM.
As a result, some of Wasm apps exhaust executable memory. Wasm interpreter should be a long term solution.
As a short term solution, we should have heuristics that switches compiler mode in BBQ: BBQ Air bloats simple code which takes much executable memory. Use BBQ B3 instead for significantly large wasm code on executable-memory-limited environments.
Comment 1 Yusuke Suzuki 2019-08-15 23:19:34 PDT
<rdar://problem/54275409>
Comment 2 Yusuke Suzuki 2019-08-16 02:49:04 PDT
Created attachment 376488 [details]
Patch
Comment 3 Mark Lam 2019-08-16 08:39:42 PDT
Comment on attachment 376488 [details]
Patch

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

r=me

> Source/JavaScriptCore/ChangeLog:10
> +        the sacrifice of start-up time, since BBQ Air bloats so lengthy code consuming large amount of executable memory.

I suggest /bloats so lengthy code consuming large/bloats such lengthy code, and thereby consumes a large/.

> Source/JavaScriptCore/runtime/Options.h:495
> +    v(size, webAssemblyBBQAirModeThreshold, isIOS() ? (10 << 20) : 0, Normal, "If 0, we always use BBQ Air. If Wasm module code size hits this threshold, we compile Wasm module with B3 BBQ mode.") \

I suggest using 10 * MB instead.

> Source/JavaScriptCore/wasm/WasmBBQPlan.cpp:144
> +    // FIXME: Some webpages use very large Wasm module, and it exhausts all executable memory in ARM64 devices since the size of executable memory region is 128MB.

/is 128MB/is only limited to 128MB/.

> Source/JavaScriptCore/wasm/WasmBBQPlan.cpp:145
> +    // The long term solution should be introducing Wasm interpreter. But as a short term solution, we introduce heuristics switching back to BBQ B3 at the sacrifice of start-up time,

/should be introducing Wasm interpreter/should be to introduce a Wasm interpreter/.
/heuristics switching back/heuristics to switch back/.

> Source/JavaScriptCore/wasm/WasmBBQPlan.cpp:146
> +    // since BBQ Air bloats so lengthy code consuming large amount of executable memory.

I suggest rephrasing as “as BBQ Air bloats such lengthy Wasm code and will consume a large ...”
Comment 4 Yusuke Suzuki 2019-08-16 18:03:15 PDT
Ah, oops. I need to change the fallback code to module information collecting part.
Comment 5 Yusuke Suzuki 2019-08-16 18:57:52 PDT
Created attachment 376574 [details]
Patch
Comment 6 Sam Weinig 2019-08-16 20:10:22 PDT
Comment on attachment 376574 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:12
> +        Currently, I picked 10MB since the reported website is using 11MB wasm module.

Since the amount of memory on iOS devices is likely to change over time, can this be made in terms of some runtime signal?
Comment 7 Yusuke Suzuki 2019-08-16 20:59:09 PDT
Comment on attachment 376574 [details]
Patch

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

>> Source/JavaScriptCore/ChangeLog:12
>> +        Currently, I picked 10MB since the reported website is using 11MB wasm module.
> 
> Since the amount of memory on iOS devices is likely to change over time, can this be made in terms of some runtime signal?

The problem is that we are exhausting executable-memory, not usual memory. In our JIT executable memory allocator, we allocate fixed-sized executable memory, and use it for JIT functions.
The size of this fixed-sized executable-memory region is the same in all the iOS devices, 128MB. And this size is not related to device's memory size. This is related to ARM64 instruction sets.
We cannot extend it further for now, since this 128MB size is derived from the maximum-relative-jump-offset in ARM64 instruction set.
In JSC, right now, we are assuming that any JIT code can be reachable from the other JIT code with relative-offset-jump. Since ARM64's relative-offset-jump is +- 128MB, this 128MB executable memory region is the maximum size in the current design.
Comment 8 Mark Lam 2019-08-17 17:43:53 PDT
Comment on attachment 376574 [details]
Patch

r=me
Comment 9 Yusuke Suzuki 2019-08-17 18:46:35 PDT
(In reply to Mark Lam from comment #8)
> Comment on attachment 376574 [details]
> Patch
> 
> r=me

Thanks, landing.
Comment 10 Yusuke Suzuki 2019-08-17 18:48:03 PDT
Committed r248824: <https://trac.webkit.org/changeset/248824>
Comment 11 Saam Barati 2019-08-19 22:13:26 PDT
Comment on attachment 376574 [details]
Patch

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

> Source/JavaScriptCore/wasm/WasmBBQPlan.cpp:273
> +        // FIXME: Some webpages use very large Wasm module, and it exhausts all executable memory in ARM64 devices since the size of executable memory region is only limited to 128MB.

what web pages?

Also, this falls down if you compile many modules, instead of one big module. This doesn't feel like a very robust solution to this problem.
Comment 12 Yusuke Suzuki 2019-08-20 00:16:03 PDT
Comment on attachment 376574 [details]
Patch

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

>> Source/JavaScriptCore/wasm/WasmBBQPlan.cpp:273
>> +        // FIXME: Some webpages use very large Wasm module, and it exhausts all executable memory in ARM64 devices since the size of executable memory region is only limited to 128MB.
> 
> what web pages?
> 
> Also, this falls down if you compile many modules, instead of one big module. This doesn't feel like a very robust solution to this problem.

The radar includes the information about this page.
This fix is not aiming at being the robust solution as described in this FIXME. This is short term solution until Wasm interpreter is introduced.
The motivation behind this fix is, it is better than having some pages working rather than completely not-working.
Comment 13 Alexey Proskuryakov 2019-09-03 20:40:44 PDT
*** Bug 200686 has been marked as a duplicate of this bug. ***
Comment 14 Walter Stumpf 2019-09-18 19:15:31 PDT
Hello,

Thanks for resolving this issue so quickly!  I was wondering if you guys knew ballpark when this patch will land in iOS.  I’m assuming it’s too late for 13.0 since the regression still occurs for me in 13.1 beta 4.  I don’t mean that as a complaint!  But I’m trying to get an appreciation for which versions of iOS we should be blocking for end users.  Thanks again for the help!
Comment 15 Keith Miller 2019-09-19 09:11:40 PDT
(In reply to Walter Stumpf from comment #14)
> Hello,
> 
> Thanks for resolving this issue so quickly!  I was wondering if you guys
> knew ballpark when this patch will land in iOS.  I’m assuming it’s too late
> for 13.0 since the regression still occurs for me in 13.1 beta 4.  I don’t
> mean that as a complaint!  But I’m trying to get an appreciation for which
> versions of iOS we should be blocking for end users.  Thanks again for the
> help!

Hi Walter,

First, sorry about the regression. Unfortunately, Apple has a policy of not commenting on future product releases, however, so we can't give a definitive timeline.
Comment 16 Walter Stumpf 2019-09-19 11:41:26 PDT
No problem, I completely understand.  We greatly appreciate the webkit team even working around the problem for us in the first place!  I will continue to cross my fingers when installing new iOS betas in the meantime! :)
Comment 17 Walter Stumpf 2019-10-02 12:00:31 PDT
Hey just wanted to confirm iOS 13.2 beta resolves the issue for us!  Thank you!!!