MPS issue job003924

TitleUnnecessary allocation during arena creation
Statusopen
Prioritynice
Assigned userGareth Rees
OrganizationRavenbrook
DescriptionDuring ArenaCreate, there are the following allocations via ControlAlloc:

1. arena.enabledMessageTypes
2. arena.tsMessage[i]
3. arena.tMessage[i]
4. arena.globals.lock
5. arena.globals.defaultChain
6. arena.globals.defaultChain->gens[i]

The sizes of these structures are known at compile time, so they could be inlined in ArenaStruct, avoiding allocation during arena creation. This would also reduce the memory usage, since ArenaStruct is 2216 bytes on 64-bit platforms, and it gets a whole 4096-byte page to itself, so there are 1880 bytes that go unused, easily enough for the above structures.

Note that arena.globals.defaultChain is not needed unless a pool is created that uses this chain, so possibly its allocation could be deferred until then. Similarly, the trace messages are not needed unless there is a garbage collection in progress, so possibly its allocation could be deferred until then.
AnalysisInlining these structures into ArenaStruct would break abstraction: currently TraceStartMessageStruct and TraceMessageStruct are declared in traceanc.c, and ChainStruct and GenDescStruct are declared in chain.h. LockStruct is platform-dependent.

Note that it might be a bad idea to defer allocation of the trace structures until a collection starts because at that point there might be no memory available. Deferring their allocation until the first automatically managed pool is created would be fine, however.
How foundinspection
EvidenceNone
Created byGareth Rees
Created on2015-08-10 15:54:56
Last modified byGareth Rees
Last modified on2015-08-10 15:54:56
History2015-08-10 GDR Created.