Bug 233401 - Avoid allocating and copy memory from a SharedMemory into a SharedBuffer
Summary: Avoid allocating and copy memory from a SharedMemory into a SharedBuffer
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on: 230329
Blocks: 233030
  Show dependency treegraph
 
Reported: 2021-11-20 15:19 PST by Jean-Yves Avenard [:jya]
Modified: 2021-12-01 18:12 PST (History)
3 users (show)

See Also:


Attachments
Patch (11.44 KB, patch)
2021-11-21 02:20 PST, Jean-Yves Avenard [:jya]
no flags Details | Formatted Diff | Diff
Patch (12.46 KB, patch)
2021-11-21 14:09 PST, Jean-Yves Avenard [:jya]
no flags Details | Formatted Diff | Diff
Patch (12.44 KB, patch)
2021-12-01 17:24 PST, Jean-Yves Avenard [:jya]
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2021-11-20 15:19:21 PST
In bug 230329 ; we added the possibility to wrap a SharedMemory into a SharedBuffer with the method SharedMemory::createSharedBuffer() : it avoid having to allocate memory and perform a new copy.

It also helps in decreasing the amount of memory allocated in the GPU Process (limited to 200MB) as the memory is counted by jetsam as being linked to the content process.

So rather than doing:

```
    auto buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), bufferSize);
```

which will copy the SharedMemory into a vector inside the SharedBuffer we can do:
```
    auto buffer = sharedMemoryBuffer->createSharedBuffer(bufferSize);
```

and kill two birds with one store.
Comment 1 Radar WebKit Bug Importer 2021-11-20 15:20:01 PST
<rdar://problem/85637721>
Comment 2 Jean-Yves Avenard [:jya] 2021-11-21 02:20:47 PST
Created attachment 444920 [details]
Patch
Comment 3 Jean-Yves Avenard [:jya] 2021-11-21 14:09:45 PST
Created attachment 444932 [details]
Patch

make ShareableResource use thread-safe refcount. Previously CFAllocatorContext’s would have always called the deallocator on the main thread
Comment 4 Eric Carlson 2021-12-01 15:52:18 PST
Comment on attachment 444932 [details]
Patch

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

> Source/WebKit/ChangeLog:10
> +        SharedMemory::createSharedBuffer instead.

Nit: using SharedMemory::createSharedBuffer instead of ...?
Comment 5 Jean-Yves Avenard [:jya] 2021-12-01 17:24:49 PST
Created attachment 445643 [details]
Patch
Comment 6 EWS 2021-12-01 18:12:46 PST
Committed r286408 (244754@main): <https://commits.webkit.org/244754@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 445643 [details].