Bug 222097 - Reloading web page with Wasm causes Wasm to have less and less Wasm memory available
Summary: Reloading web page with Wasm causes Wasm to have less and less Wasm memory av...
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebAssembly (show other bugs)
Version: Safari 13
Hardware: iPhone / iPad Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-18 01:48 PST by jujjyl
Modified: 2024-06-25 08:33 PDT (History)
11 users (show)

See Also:


Attachments
Screenshot of Instruments memory profile of MobileSafari (iOS 17.5.1) (294.55 KB, image/png)
2024-06-13 12:12 PDT, Alex Suzuki
no flags Details
Reproduction repository; Refresh a dozen or so times and it triggers the OOM condition, and does not recover. (60 bytes, text/plain)
2024-06-18 02:16 PDT, Alex Suzuki
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description jujjyl 2021-02-18 01:48:00 PST
STR:

1. Visit http://clb.confined.space/wasm_grow.html (you can download this for local examination, the file is standalone/self-contained)
2. Click on "new WebAssembly.Memory({ initial: 1 });" button
3. Click on "Grow Wasm" button repeatedly, until "wasm.buffer.byteLength == " field is no longer able to grow.
4. Observe the amount of memory that was possible to be reached.
5. Click on Reload and go to step 2.

Observed:

On subsequent page reloads, there is less and less memory available for the Wasm heap to grow. E.g. in one such test, max heap went from 768 MB -> 544 MB -> 512 MB on each page reload.
Comment 1 Alexey Proskuryakov 2021-02-19 18:34:03 PST
Which version of Safari are you seeing this with? Safari 13 as set in Version field is very old, and thus bugs in it are not relevant unless also happening with the latest version.
Comment 2 jujjyl 2021-02-20 01:07:21 PST
This was tested on iPhoneXS on iOS 13.3.1. My apologies for not testing a newer version, but iOS refuses to update itself on my phone. It is stuck in a "Update Available -> Install Update -> Verifying Update -> Unable to Install Update, An error occurred when installing iOS 14.4" sequence when attempting to install iOS 14.4, and I do not have another iOS device to test.

Based on reports from this thread https://forum.unity.com/threads/android-chromium-unable-to-grow-allocated-memory-above-256mb-confirmed.1014475/ , and the conversation in this thread, https://github.com/WebAssembly/design/issues/1397 I believe that the issues are still current.

However please close if this is not actionable to investigate further. Thanks!
Comment 3 Radar WebKit Bug Importer 2021-02-25 01:48:12 PST
<rdar://problem/74735924>
Comment 4 Smoley 2021-03-03 16:03:01 PST
Still reproduces on the latest iOS 14.5 beta.
Comment 5 Justin Michaud 2023-01-26 10:23:48 PST
I cannot reproduce this on 13.3/M1 Macbook. We always get the full 4.0000 GB.

On iOS 16.4, iPhone Xs, I similarly always get 1.9062gb if we ask for it from the beginning.

On the other hand, if we ask for a fixed smaller amount, we are often unable to grow the memory. Reloading doesn't seem to matter here, this has more to do with our heap layout.

I also get "this page is reloaded because it is using significant memory," even though I have 32gb of ram. We should tune that heuristic.
Comment 6 goldwaving 2023-12-18 07:41:04 PST
It is frustrating that this issue still has not been resolved.  Reload of our audio editing app triggers this bug.  You can test it here:  https://goldwave.com/editor.

Reloading the page (usually just 2 or 3 times) fails on Safari version 17.2 with a memory range error, but Firefox and Chrome work fine (on non-iOS devices).  The error continues for every reload until Safari is terminated.
Comment 7 Ivan Čurić 2024-01-31 03:41:59 PST
This issue is even more apparent in iOS 17.3.

Our product (https://demo.microblink.com/blinkid-extract) no longer works on iOS 17.3 as any memory allocation request gets denied after an initial size of 200mb.

Using a fixed memory size without grow calls can also trigger this issue.

If using shared memory, closing the tab won't fix the issue. You need to restart the entire browser.
Comment 8 Ivan Čurić 2024-01-31 05:40:59 PST
Additionally, here are my test results using http://clb.confined.space/wasm_grow.html on iOS 17.3:

1. Probing will return 815mb - grow fails
2. Clicking "reload" and probing will then return 0.99gb - grow fails
3. Reloading and allocating 1 page, and pressing grow will error out at only 4mb
4. Doing a page reload, allocating 1 page and then growing errors out at 768mb
5. Reloading page + probe returns 1.4678gb
6. Reloading page + initial size of 524mb fails initial allocation.
7. Reloading + initial size of 384 works. Grow fails.
8. Reloading + initial size of 800mb works. Grow works.
9. Reloading + initial size of 181 mb fails.

It's completely unpredictable and therefore unusable in production. Depending on the conditions you can error out at 2gb or at 4mb, asking upfront or growing.

This has been an issue for 3 years now and seems to be getting worse.
Comment 9 Ahmad Saleem 2024-03-21 02:11:19 PDT
@Justin & @Yusuke - does Gigacage commit - https://github.com/WebKit/WebKit/commit/416a9ccb3e0c77d9dccdf2d10689ba7c98b1738b

will help this?
Comment 10 Alex Suzuki 2024-06-13 11:55:08 PDT
I am seeing this issue manifest as well, seemingly more often in recent iOS versions (17.4 and 17.5), when testing a barcode scanning library that uses WASM.
Only killing Safari resolves the issue.
Comment 11 Alex Suzuki 2024-06-13 12:12:14 PDT
Created attachment 471670 [details]
Screenshot of Instruments memory profile of MobileSafari (iOS 17.5.1)

Instruments screenshot of MobileSafari process when issue occurs. On iOS 17.5.1, on an iPhone 15 Pro (MTV63ZD/A) the issue starts happening when memory usage of MobileSafari hits 6.0 GB.
Comment 12 Alex Suzuki 2024-06-18 02:13:04 PDT
Reproduction repository: https://github.com/pixelverse-llc/safari-wasm-oom-reproducer

Repeatedly reloading index.html triggers the issue after an unknown number of refreshes (~a dozen in my experiment)
Comment 13 Alex Suzuki 2024-06-18 02:16:30 PDT
Created attachment 471697 [details]
Reproduction repository; Refresh a dozen or so times and it triggers the OOM condition, and does not recover.
Comment 14 Alex Suzuki 2024-06-18 02:28:37 PDT
Note: I can not reproduce this issue in the Safari iOS 18 Developer Beta (22A5282m).
Comment 15 Alex Suzuki 2024-06-19 23:57:41 PDT
I can also no longer reproduce this in Safari on iOS 17.6 Beta.
Comment 16 Alexey Proskuryakov 2024-06-25 08:33:52 PDT
Thank you for following up!