From 8be60821bbbce6bff6847c2476051f95a05a2b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= <tomusdrw@users.noreply.github.com> Date: Tue, 22 Jun 2021 13:20:29 +0200 Subject: [PATCH] Fix allocator waste assessment in docs (#9167) * Fix allocator comment. * Add explanations where this comes from. * Clarify absolute values. --- substrate/primitives/allocator/src/freeing_bump.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/allocator/src/freeing_bump.rs b/substrate/primitives/allocator/src/freeing_bump.rs index 64ba136f9a3..e2a6b19e4a7 100644 --- a/substrate/primitives/allocator/src/freeing_bump.rs +++ b/substrate/primitives/allocator/src/freeing_bump.rs @@ -60,8 +60,11 @@ //! fail. //! //! - Sizes of allocations are rounded up to the nearest order. That is, an allocation of 2,00001 MiB -//! will be put into the bucket of 4 MiB. Therefore, typically more than half of the space in allocation -//! will be wasted. This is more pronounced with larger allocation sizes. +//! will be put into the bucket of 4 MiB. Therefore, any allocation of size `(N, 2N]` will take +//! up to `2N`, thus assuming a uniform distribution of allocation sizes, the average amount in use +//! of a `2N` space on the heap will be `(3N + ε) / 2`. So average utilisation is going to be around +//! 75% (`(3N + ε) / 2 / 2N`) meaning that around 25% of the space in allocation will be wasted. +//! This is more pronounced (in terms of absolute heap amounts) with larger allocation sizes. use crate::Error; use sp_std::{mem, convert::{TryFrom, TryInto}, ops::{Range, Index, IndexMut}}; -- GitLab