From 94f8b886a0a3ae6a32e3bbbf88a0e970a273f3d6 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 18 Jan 2019 21:09:55 +0000 Subject: [PATCH] Remove union in metaslab The union in Metaslab provides no benefit in size, as the single byte it effectively saves will be removed due to padding. By removing the union, we get stronger properties over sizeclass, and remove an out-of-bounds access. --- src/mem/metaslab.h | 7 ++----- src/mem/superslab.h | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mem/metaslab.h b/src/mem/metaslab.h index 1d24fae..c94de3e 100644 --- a/src/mem/metaslab.h +++ b/src/mem/metaslab.h @@ -57,11 +57,8 @@ namespace snmalloc // doubly linked node into that size class's free list. uint16_t link; - union - { - uint8_t sizeclass; - uint8_t next; - }; + uint8_t sizeclass; + uint8_t next; void add_use() { diff --git a/src/mem/superslab.h b/src/mem/superslab.h index 5a1c901..fc2e4e8 100644 --- a/src/mem/superslab.h +++ b/src/mem/superslab.h @@ -194,6 +194,7 @@ namespace snmalloc uint8_t index = (uint8_t)slab_to_index(slab); uint8_t n = head - index - 1; + meta[index].sizeclass = 0; meta[index].next = n; head = index; bool was_almost_full = is_almost_full();