Bug 233401

Summary: Avoid allocating and copy memory from a SharedMemory into a SharedBuffer
Product: WebKit Reporter: Jean-Yves Avenard [:jya] <jean-yves.avenard>
Component: Page LoadingAssignee: Jean-Yves Avenard [:jya] <jean-yves.avenard>
Status: RESOLVED FIXED    
Severity: Normal CC: beidson, eric.carlson, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=233363
Bug Depends on: 230329    
Bug Blocks: 233030    
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

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].