owned this note
owned this note
Published
Linked with GitHub
### Simulator
TODO: create a repo with it with Jan permission, or ask him to upload it
### Results legend
- **peak allocation count**: number of live allocations made by the allocator (not deallocated at the moment of counting) during the simulation period
- **peak requested space**: space in bytes allocated by the allocator at maximum (while the memory is still in use and not deallocated)
- **peak wasted space on padding**: extra bytes required to manage the requested space
- **Final allocations**: what remains in terms of number of allocations (without a deallocation counterpart) at the end of the exercise
- **Final requested space**: what space is still occupied at the end of the exercise by previous allocations
- **Final wasted space on padding**: what space is used for padding/metadata at the end of the exercise by previous allocations
- **Extra bytes allocated**: once the simulation is over, we do some random trials of filling up the rest of the allocator heap, given the space left after all alloc/dealloc sequence is over. We can't tell exactly how much extra bytes could be allocated at the end because that space depends on the size of the allocation, which corresponds to some extra padding.
- **Physical memory used**: number of pages touched in physical memory * regular page size (4096) - which is the physical space in RAM consumed by the simulation, measured at the end of it. We compute this by looking into `/proc/self/pagemap`, which contains 64 bits for each virtual page. Bit 63 says if the virtual page is present in RAM.
### Allocation patterns on AHP
1. Used #9363 to build `polkadot-parachain` and start an AHP full node (with `-lruntime_host_allocator=debug`, which based on some later exercises in non-AHP context, might increase the allocations/deallocations sequence artificially to some extent). I used `polkadot-stable2506` branch and same commits.
2. Extracted both relaychain & parachain allocation logs.
3. I used a simulator from @koute (code should follow in a repo soon), updated to read trough a file with many host allocations for AHP runtime, from a full node which runs for an hour, synced to the tip at that time.
#### asset-hub-polkadot parachain allocation patterns
*Runtime: 6e20bc52aaaafd1de82ba7d2a3c0fa39193787e240b93608489cf72a4c46a584* (this the current on chain runtime on AHP)
```
Running with allocator: legacy
Peak allocation count: 5586
Peak requested space: 25214682
Peak wasted space on padding: 6788230
Final allocations (that were not yet deallocated): 4393
Final requested space (unallocated space): 25045617
Final wasted space on padding: 6693135
Physical memory used: 31035392
Bump allocator stats: AllocationStats { bytes_allocated: 31773896, bytes_allocated_peak: 32044136, bytes_allocated_sum: 571192664, address_space_used: 32248168 }
Extra bytes allocated: 378385375
Running with allocator: new
Peak allocation count: 5586
Peak requested space: 25214682
Peak wasted space on padding: 89283
Final allocations (that were not yet deallocated): 4393
Final requested space (unallocated space): 25045617
Final wasted space on padding: 68911
Physical memory used: 25538560
Bump allocator stats: AllocationStats { bytes_allocated: 0, bytes_allocated_peak: 0, bytes_allocated_sum: 0, address_space_used: 0 }
Extra bytes allocated: 394245905
```
*Runtime: e260d17fcfa34f10503c91148a7bc2fd820e356295d2e18f828b5fa4190d47f7* (I am not sure which runtime is this, maybe some older version which was used for some syncing?)
```
Running with allocator: legacy
Peak allocation count: 7852
Peak requested space: 32659186
Peak wasted space on padding: 23185710
Final allocations (that were not yet deallocated): 7801
Final requested space (unallocated space): 32604198
Final wasted space on padding: 23154330
Physical memory used: 36519936
Bump allocator stats: AllocationStats { bytes_allocated: 55820936, bytes_allocated_peak: 55907704, bytes_allocated_sum: 283346320, address_space_used: 55953104 }
Extra bytes allocated: 360474882
Running with allocator: new
Peak allocation count: 7852
Peak requested space: 32659186
Peak wasted space on padding: 147502
Final allocations (that were not yet deallocated): 7801
Final requested space (unallocated space): 32604198
Final wasted space on padding: 146394
Physical memory used: 39440384
Bump allocator stats: AllocationStats { bytes_allocated: 0, bytes_allocated_peak: 0, bytes_allocated_sum: 0, address_space_used: 0 }
Extra bytes allocated: 386472515
```
#### asset-hub-polkadot relaychain allocation patterns
*Runtime: e260d17fcfa34f10503c91148a7bc2fd820e356295d2e18f828b5fa4190d47f7*
```
Running with allocator: legacy
Peak allocation count: 27570
Peak requested space: 159710372
Peak wasted space on padding: 112773340
Final allocations: 7549
Final requested space: 159200521
Final wasted space on padding: 112562375
Physical memory used: 208474112
Bump allocator stats: AllocationStats { bytes_allocated: 271823288, bytes_allocated_peak: 272569888, bytes_allocated_sum: 20547290680, address_space_used: 292902856 }
Extra bytes allocated: 183737681
Running with allocator: new
Peak allocation count: 27570
Peak requested space: 159710372
Peak wasted space on padding: 64415644
Final allocations: 7549
Final requested space: 159200521
Final wasted space on padding: 64287543
Physical memory used: 195022848
Bump allocator stats: AllocationStats { bytes_allocated: 157230856, bytes_allocated_peak: 157558560, bytes_allocated_sum: 1364898648, address_space_used: 177034712 }
Extra bytes allocated: 219745053
```
### Heavy contract execution with host allocator debug logs: https://github.com/paritytech/memory_exhaustion
1. Used #9363 + #9267 (commit b86340a) to run `staging-node-cli`.
2. Once the node is up, with `runtime_host_allocator=debug` target enabled, I deployed the contract written here: https://github.com/paritytech/memory_exhaustion
#### Extracted allocations where `staging-node-cli` is started with logging directive `runtime_host_allocator=debug`
Got around 500 millions allocation/deallocation operations in sequence, and replayed them with same simulator from Jan. The extrinsic for the contract call (which recurses for 25 times) doesn't seem to end/get finalized, but allocations/deallocations are continously logged (let it run for more than 24hours and it was still logging). If the allocator log target captures the allocations logs on `debug`, contracts execution might be slow and strange things can happen (e.g. infinite allocations logged while executing an extrinsic related to a contract call - which I saw in practice). I would consider the bellow exercise not very representative for how the allocations happen, but it is still useful to be mentioned for future reference.
*Runtime 01cefa9c6e629d4cf67dc635e800c19ad7aea335333802af4945ada00dca1f0b*
```
Running with allocator: legacy
Peak allocation count: 16376
Peak requested space: 321974359
Peak wasted space on padding: 6350956
Final allocations: 2855
Final requested space: 317628029
Final wasted space on padding: 6350955
Physical memory used: 348807168
Bump allocator stats: AllocationStats { bytes_allocated: 324001824, bytes_allocated_peak: 328308656, bytes_allocated_sum: 13785237856, address_space_used: 351468928 }
Extra bytes allocated: 139785942
Running with allocator: new
Peak allocation count: 16376
Peak requested space: 321974359
Peak wasted space on padding: 5285723
Final allocations: 2855
Final requested space: 317628029
Final wasted space on padding: 5285443
Physical memory used: 350203904
Bump allocator stats: AllocationStats { bytes_allocated: 257951880, bytes_allocated_peak: 262277192, bytes_allocated_sum: 3068803176, address_space_used: 284035320 }
Extra bytes allocated: 140989127
```
### Heavy contract execution w/o custom logging directives: https://github.com/paritytech/memory_exhaustion
Setup is same as for the execution with debug logging directives, only that I used for polkadot-sdk branch of #9267 at 032e005.
#### Extracted allocations where `staging-node-cli` is started w/o logging directives and host allocator logs for allocations/deallocations are logged as `warn` - so they show up by default in node logs
Looks like when logging allocator logs on `warn` the exercise finishes successfully, and the allocations are much lower (e.g. ~55MB peak requested space and ~60/56MB phyisical memory used).
*Runtime: ead5ededbf9840660462ca27ae6d8008e827f902c6974d940b2cfee5d4be84f8*
```
Running with allocator: legacy
Peak allocation count: 16777
Peak requested space: 55185677
Peak wasted space on padding: 2580291
Final allocations: 968
Final requested space: 5131075
Final wasted space on padding: 506613
Physical memory used: 60407808
Bump allocator stats: AllocationStats { bytes_allocated: 5645432, bytes_allocated_peak: 57772736, bytes_allocated_sum: 6860640944, address_space_used: 61215344 }
Extra bytes allocated: 357079214
Running with allocator: new
Peak allocation count: 16777
Peak requested space: 55185677
Peak wasted space on padding: 207033
Final allocations: 968
Final requested space: 5131075
Final wasted space on padding: 19581
Physical memory used: 56799232
Bump allocator stats: AllocationStats { bytes_allocated: 0, bytes_allocated_peak: 0, bytes_allocated_sum: 0, address_space_used: 0 }
Extra bytes allocated: 414225157
```