Bug 142443 - bmalloc: tryFastMalloc shouldn't crash
Summary: bmalloc: tryFastMalloc shouldn't crash
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Geoffrey Garen
URL:
Keywords:
Depends on: 142525
Blocks: 139868
  Show dependency treegraph
 
Reported: 2015-03-07 17:46 PST by Geoffrey Garen
Modified: 2015-03-10 15:51 PDT (History)
8 users (show)

See Also:


Attachments
Patch (10.39 KB, patch)
2015-03-07 17:55 PST, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (10.38 KB, patch)
2015-03-07 19:13 PST, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-mavericks (583.87 KB, application/zip)
2015-03-07 20:29 PST, Build Bot
no flags Details
Archive of layout-test-results from ews107 for mac-mavericks-wk2 (752.74 KB, application/zip)
2015-03-07 20:35 PST, Build Bot
no flags Details
Patch (10.66 KB, patch)
2015-03-08 15:28 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-mavericks (638.19 KB, application/zip)
2015-03-08 17:01 PDT, Build Bot
no flags Details
Patch (1.65 KB, patch)
2015-03-08 19:30 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (4.26 KB, patch)
2015-03-09 09:03 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (10.10 KB, patch)
2015-03-09 16:43 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (10.14 KB, patch)
2015-03-09 16:49 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (12.51 KB, patch)
2015-03-10 11:00 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2015-03-07 17:46:54 PST
bmalloc: tryFastMalloc shouldn't crash
Comment 1 Geoffrey Garen 2015-03-07 17:55:09 PST
Created attachment 248170 [details]
Patch
Comment 2 Geoffrey Garen 2015-03-07 19:13:49 PST
Created attachment 248173 [details]
Patch
Comment 3 Build Bot 2015-03-07 20:29:00 PST
Comment on attachment 248173 [details]
Patch

Attachment 248173 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/6160743829340160

New failing tests:
svg/custom/absolute-root-position-masking.xhtml
js/regress/exit-length-on-plain-object.html
Comment 4 Build Bot 2015-03-07 20:29:03 PST
Created attachment 248176 [details]
Archive of layout-test-results from ews101 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 5 Build Bot 2015-03-07 20:35:34 PST
Comment on attachment 248173 [details]
Patch

Attachment 248173 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6145023175294976

New failing tests:
fast/history/replacestate-nocrash.html
fast/multicol/newmulticol/multicol-inside-multicol.html
platform/mac-wk2/plugins/muted-state.html
Comment 6 Build Bot 2015-03-07 20:35:38 PST
Created attachment 248177 [details]
Archive of layout-test-results from ews107 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 7 Brent Fulgham 2015-03-08 12:27:22 PDT
Comment on attachment 248173 [details]
Patch

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

> Source/WTF/wtf/FastMalloc.cpp:192
> +    return bmalloc::api::malloc(size);

Would it make sense for these to be in the header so they could be inlined?
Comment 8 Geoffrey Garen 2015-03-08 15:03:12 PDT
> > Source/WTF/wtf/FastMalloc.cpp:192
> > +    return bmalloc::api::malloc(size);
> 
> Would it make sense for these to be in the header so they could be inlined?

Currently, WTF::fastMalloc is an out-of-line function, but bmalloc::api::malloc is fully inlined into it. That's pretty good.

We probably don't want to inline the whole malloc function -- it's a bit too big.

But we probably do want to inline the size class calculation eventually, since it's constant.
Comment 9 Geoffrey Garen 2015-03-08 15:28:11 PDT
Created attachment 248210 [details]
Patch
Comment 10 Build Bot 2015-03-08 17:01:20 PDT
Comment on attachment 248210 [details]
Patch

Attachment 248210 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/5808178553946112

New failing tests:
fast/multicol/newmulticol/multicol-inside-multicol.html
Comment 11 Build Bot 2015-03-08 17:01:23 PDT
Created attachment 248220 [details]
Archive of layout-test-results from ews101 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 12 Darin Adler 2015-03-08 19:23:52 PDT
Comment on attachment 248210 [details]
Patch

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

Tests seem to be failing on EWS. Please don’t land until you find out why.

> Source/WTF/ChangeLog:14
> +        * wtf/FastMalloc.cpp:
> +        (WTF::fastMalloc):
> +        (WTF::fastCalloc):
> +        (WTF::fastRealloc):
> +        (WTF::fastAlignedMalloc): Don't check for NULL; bmalloc will just crash
> +        for us if allocation fails, and we'd rather not pay the cost of an extra
> +        check.

Very interesting. I had no idea! (As you can tell since I wrote all that wrong code.)

> Source/WebKit2/Shared/ShareableBitmap.cpp:149
> +    char* data = 0;

nullptr

> Source/WebKit2/Shared/ShareableBitmap.cpp:155
> +    fastFree(m_data);

Seems unfortunate that we can’t free the old data before allocating the new data; one advantage of the old realloc code path is that it combined the new allocation with the old deallocation. We don’t want to reuse the data, but it would be nice to be able to reuse the memory. Perhaps my naiveté about malloc is showing, though.
Comment 13 Darin Adler 2015-03-08 19:25:23 PDT
I think it’s strange that bmalloc has an entry point named malloc that is “crash on fail” rather than “return null on fail”. That differs from the traditional meaning of the malloc C library function although it matches the behavior of our fastMalloc function.
Comment 14 Geoffrey Garen 2015-03-08 19:30:25 PDT
Created attachment 248224 [details]
Patch
Comment 15 Geoffrey Garen 2015-03-08 22:43:34 PDT
> Tests seem to be failing on EWS. Please don’t land until you find out why.

OK.

> > Source/WebKit2/Shared/ShareableBitmap.cpp:155
> > +    fastFree(m_data);
> 
> Seems unfortunate that we can’t free the old data before allocating the new
> data; one advantage of the old realloc code path is that it combined the new
> allocation with the old deallocation. We don’t want to reuse the data, but
> it would be nice to be able to reuse the memory. Perhaps my naiveté about
> malloc is showing, though.

Since realloc must copy the contents of the old buffer, it's not allowed to free the old buffer before allocating the new one.
Comment 16 Geoffrey Garen 2015-03-08 22:46:03 PDT
> I think it’s strange that bmalloc has an entry point named malloc that is
> “crash on fail” rather than “return null on fail”. That differs from the
> traditional meaning of the malloc C library function although it matches the
> behavior of our fastMalloc function.

Yeah. I never really thought through the crash vs return null behavior, and now that I think about it, it's probably not right to call the functions malloc and realloc -- it's more like mallocOrCrash and reallocOrCrash, or something.
Comment 17 Darin Adler 2015-03-09 00:08:18 PDT
Comment on attachment 248224 [details]
Patch

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

> Source/WebKit2/Shared/ShareableBitmap.cpp:149
> +    char* data = 0;

nullptr
Comment 18 Darin Adler 2015-03-09 00:09:30 PDT
(In reply to comment #15)
> > > Source/WebKit2/Shared/ShareableBitmap.cpp:155
> > > +    fastFree(m_data);
> > 
> > Seems unfortunate that we can’t free the old data before allocating the new
> > data; one advantage of the old realloc code path is that it combined the new
> > allocation with the old deallocation. We don’t want to reuse the data, but
> > it would be nice to be able to reuse the memory. Perhaps my naiveté about
> > malloc is showing, though.
> 
> Since realloc must copy the contents of the old buffer, it's not allowed to
> free the old buffer before allocating the new one.

Still seems like a missed opportunity here. Not something we were doing before, but something we could do. Again, not sure if it’s realistic to expect one free to help the other allocate to succeed.
Comment 19 Geoffrey Garen 2015-03-09 07:50:08 PDT
> Still seems like a missed opportunity here. Not something we were doing
> before, but something we could do.

Ah, I see. Yes, I think we could do it.
Comment 20 Geoffrey Garen 2015-03-09 09:03:55 PDT
Created attachment 248245 [details]
Patch
Comment 21 Geoffrey Garen 2015-03-09 11:43:33 PDT
Committed r181272: <http://trac.webkit.org/changeset/181272>
Comment 22 Geoffrey Garen 2015-03-09 16:43:51 PDT
Reopening to attach new patch.
Comment 23 Geoffrey Garen 2015-03-09 16:43:53 PDT
Created attachment 248289 [details]
Patch
Comment 24 Geoffrey Garen 2015-03-09 16:44:09 PDT
This time for sure!
Comment 25 Geoffrey Garen 2015-03-09 16:49:46 PDT
Created attachment 248290 [details]
Patch
Comment 26 Geoffrey Garen 2015-03-09 21:10:42 PDT
Committed r181307: <http://trac.webkit.org/changeset/181307>
Comment 27 Alexey Proskuryakov 2015-03-09 23:44:59 PDT
This seems to have somehow broken ASan tests, with a nondescript error. I'm going to try rolling out.

r181306 was fine, r181308 crashes on many tests.
Comment 28 WebKit Commit Bot 2015-03-09 23:47:30 PDT
Re-opened since this is blocked by bug 142525
Comment 29 Geoffrey Garen 2015-03-10 11:00:12 PDT
Created attachment 248336 [details]
Patch
Comment 30 Geoffrey Garen 2015-03-10 11:01:27 PDT
Committed r181329: <http://trac.webkit.org/changeset/181329>