From 7d5af692d642df4f7ca9f177368d5a782fa1905a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 22 Jun 2021 09:26:09 +0200 Subject: [PATCH 1/3] Fix allocator comment. --- primitives/allocator/src/freeing_bump.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/primitives/allocator/src/freeing_bump.rs b/primitives/allocator/src/freeing_bump.rs index 64ba136f9a354..017fe57b392aa 100644 --- a/primitives/allocator/src/freeing_bump.rs +++ b/primitives/allocator/src/freeing_bump.rs @@ -60,8 +60,8 @@ //! 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, on average 25% of the space in allocation +//! will be wasted. This is more pronounced in absolute values with larger allocation sizes. use crate::Error; use sp_std::{mem, convert::{TryFrom, TryInto}, ops::{Range, Index, IndexMut}}; From 73d50c2b972d594a55afcce178e7e3a6b59443af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 22 Jun 2021 09:51:40 +0200 Subject: [PATCH 2/3] Add explanations where this comes from. --- primitives/allocator/src/freeing_bump.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/primitives/allocator/src/freeing_bump.rs b/primitives/allocator/src/freeing_bump.rs index 017fe57b392aa..5b7277adbdb34 100644 --- a/primitives/allocator/src/freeing_bump.rs +++ b/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, on average 25% of the space in allocation -//! will be wasted. This is more pronounced in absolute values 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 absolute values with larger allocation sizes. use crate::Error; use sp_std::{mem, convert::{TryFrom, TryInto}, ops::{Range, Index, IndexMut}}; From 467dd934186398bb48509a3222c3ff705e4c0da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 22 Jun 2021 09:55:01 +0200 Subject: [PATCH 3/3] Clarify absolute values. --- primitives/allocator/src/freeing_bump.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/allocator/src/freeing_bump.rs b/primitives/allocator/src/freeing_bump.rs index 5b7277adbdb34..e2a6b19e4a7f1 100644 --- a/primitives/allocator/src/freeing_bump.rs +++ b/primitives/allocator/src/freeing_bump.rs @@ -64,7 +64,7 @@ //! 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 absolute values with larger allocation sizes. +//! 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}};