RESOLVED FIXED 205834
[bmalloc] Extract constants from Heap and share it among Heaps.
https://bugs.webkit.org/show_bug.cgi?id=205834
Summary [bmalloc] Extract constants from Heap and share it among Heaps.
Basuke Suzuki
Reported 2020-01-06 14:31:11 PST
The following member variables of Heap are dependent only for vmPageSize and calculating same value for each Heap. m_vmPageSizePhysical, m_smallLineMetadata and m_pageClasses Extract them as a separate class and access them from each Heap reduces sizeof(Heap) for m_pageClasses and Vector for m_smallLineMetadata.
Attachments
PATCH (23.17 KB, patch)
2020-01-07 10:37 PST, Basuke Suzuki
no flags
PATCH (23.48 KB, patch)
2020-01-07 10:50 PST, Basuke Suzuki
no flags
PATCH (23.78 KB, patch)
2020-01-08 17:08 PST, Basuke Suzuki
no flags
PATCH (21.56 KB, patch)
2020-01-09 13:15 PST, Basuke Suzuki
no flags
Basuke Suzuki
Comment 1 2020-01-07 10:37:36 PST
Created attachment 386991 [details] PATCH - Extracted member variables for metadata and initialization code of those. - Merge LineMetadata.h and Metadata.h - Add simple wrapper class to get metadata for specific sizeClass.
Basuke Suzuki
Comment 2 2020-01-07 10:50:50 PST
Created attachment 386995 [details] PATCH build fix
Basuke Suzuki
Comment 3 2020-01-07 10:51:37 PST
The style error is false positive and it will be solved by https://bugs.webkit.org/show_bug.cgi?id=205840 .
Basuke Suzuki
Comment 4 2020-01-07 15:06:31 PST
jsc fails because it uses old version of forwarding header. Heap.h doesn't include LineMetadata.h any more and the line doesn't exist.
Basuke Suzuki
Comment 5 2020-01-08 17:08:17 PST
Created attachment 387165 [details] PATCH Add ChangeLog description.
Yusuke Suzuki
Comment 6 2020-01-08 17:18:09 PST
(In reply to Basuke Suzuki from comment #4) > jsc fails because it uses old version of forwarding header. Heap.h doesn't > include LineMetadata.h any more and the line doesn't exist. I think the problem is that "bmalloc.h" and "Heap.h" are not copied correctly via CpHeader. Can you make it work?
Geoffrey Garen
Comment 7 2020-01-08 17:19:21 PST
What's the benefit here? Heap is a per-process singleton, so I don't understand the value of moving its data into another per-process singleton.
Geoffrey Garen
Comment 8 2020-01-08 17:20:28 PST
Side note: I think the word "metadata" is too generic. Can you think of a name that describes the data recorded here?
Basuke Suzuki
Comment 9 2020-01-08 17:28:55 PST
(In reply to Geoffrey Garen from comment #7) > What's the benefit here? > > Heap is a per-process singleton, so I don't understand the value of moving > its data into another per-process singleton. Heap is created as PerProcess<PerHeapKind>() singleton. So four copies of pageClass and smallLineMetadata tables are created. Also smallLineMetadata is a Vector, so it allocates another page for each Heap kind.
Basuke Suzuki
Comment 10 2020-01-08 17:31:07 PST
(In reply to Geoffrey Garen from comment #8) > Side note: I think the word "metadata" is too generic. Can you think of a > name that describes the data recorded here? How about HeapMetadata? Or I can merge them into Heap.(h|cpp) if that is more suitable.
Basuke Suzuki
Comment 11 2020-01-08 17:32:12 PST
(In reply to Yusuke Suzuki from comment #6) > (In reply to Basuke Suzuki from comment #4) > > jsc fails because it uses old version of forwarding header. Heap.h doesn't > > include LineMetadata.h any more and the line doesn't exist. > > I think the problem is that "bmalloc.h" and "Heap.h" are not copied > correctly via CpHeader. Can you make it work? Does jsc build use different path than other Xcode targets?
Basuke Suzuki
Comment 12 2020-01-08 17:33:35 PST
Just in case this is the goal of this patch. I'm working on making those values `constxpr`ed for specific VM page sizes. https://github.com/WebKit/webkit/compare/master...basuke:basuke/bmalloc-metadata-constexpr?expand=1#diff-590a267487c8ee077df1036f99e1c38cR75-R98
Yusuke Suzuki
Comment 13 2020-01-08 17:39:12 PST
Yes, Heap exists at least three due to Gigacage IIRC (Primitive, JSValue, FastMalloc). And IIRC, Metadata takes measurable size (I noticed that when doing memory reduction work. If we avoid Heap initialization completely when Malloc=1 is enabled (we use DebugHeap), we get large improvement in RAMification LuaJSFight).
Geoffrey Garen
Comment 14 2020-01-08 21:03:34 PST
Comment on attachment 387165 [details] PATCH View in context: https://bugs.webkit.org/attachment.cgi?id=387165&action=review > Source/bmalloc/bmalloc/Heap.cpp:284 > - size_t pageClass = m_pageClasses[sizeClass]; > + Metadata metadata { sizeClass }; > + size_t pageClass = metadata.pageClass(); This idiom surprised me. There's nothing about the Metadata class name that says to me "I will look up the right page class for a size class upon initialization". What do you think about "m_constants.pageClass(sizeClass)" instead? > Source/bmalloc/bmalloc/Metadata.hSource/bmalloc/bmalloc/LineMetadata.h:42 > +class MetadataStorage : public StaticPerProcess<MetadataStorage> { How about if we call this class "HeapConstants", since it's the factored out set of constants shared by all heaps -- and then keep a reference m_heapConstants in each Heap?
Basuke Suzuki
Comment 15 2020-01-09 10:10:30 PST
Comment on attachment 387165 [details] PATCH View in context: https://bugs.webkit.org/attachment.cgi?id=387165&action=review >> Source/bmalloc/bmalloc/Heap.cpp:284 >> + size_t pageClass = metadata.pageClass(); > > This idiom surprised me. There's nothing about the Metadata class name that says to me "I will look up the right page class for a size class upon initialization". > > What do you think about "m_constants.pageClass(sizeClass)" instead? I agree with that. Actually that was my first implementation. I saw lot of sizeClass passing to get value from metadata, so I decided to make helper class. But yes that idiom is not regular. >> Source/bmalloc/bmalloc/Metadata.hSource/bmalloc/bmalloc/LineMetadata.h:42 >> +class MetadataStorage : public StaticPerProcess<MetadataStorage> { > > How about if we call this class "HeapConstants", since it's the factored out set of constants shared by all heaps -- and then keep a reference m_heapConstants in each Heap? HeapConstants for class name and having a reference to that instance in Heap are good to me. I want to call it m_constants because it's already used in Heap object.
Basuke Suzuki
Comment 16 2020-01-09 13:15:39 PST
Geoffrey Garen
Comment 17 2020-01-09 13:40:09 PST
Comment on attachment 387259 [details] PATCH r=me
WebKit Commit Bot
Comment 18 2020-01-09 14:57:51 PST
Comment on attachment 387259 [details] PATCH Clearing flags on attachment: 387259 Committed r254303: <https://trac.webkit.org/changeset/254303>
WebKit Commit Bot
Comment 19 2020-01-09 14:57:53 PST
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 20 2020-01-09 14:58:18 PST
Note You need to log in before you can comment on or make changes to this bug.