ruby-changes:63398
From: Jacob <ko1@a...>
Date: Wed, 21 Oct 2020 11:44:33 +0900 (JST)
Subject: [ruby-changes:63398] 73834b5fc9 (master): Calculate transient heap block usable size at compile time
https://git.ruby-lang.org/ruby.git/commit/?id=73834b5fc9 From 73834b5fc9d83180820de120db4350fa208cf743 Mon Sep 17 00:00:00 2001 From: Jacob Matthews <jacobmatthews@h...> Date: Tue, 6 Oct 2020 20:31:25 +1300 Subject: Calculate transient heap block usable size at compile time diff --git a/transient_heap.c b/transient_heap.c index 391dd59..444f4fd 100644 --- a/transient_heap.c +++ b/transient_heap.c @@ -62,6 +62,7 @@ https://github.com/ruby/ruby/blob/trunk/transient_heap.c#L62 #define TRANSIENT_HEAP_TOTAL_SIZE (1024 * 1024 * 32) /* 32 MB */ #define TRANSIENT_HEAP_ALLOC_MAX (1024 * 2 ) /* 2 KB */ #define TRANSIENT_HEAP_BLOCK_NUM (TRANSIENT_HEAP_TOTAL_SIZE / TRANSIENT_HEAP_BLOCK_SIZE) +#define TRANSIENT_HEAP_USABLE_SIZE TRANSIENT_HEAP_BLOCK_SIZE - sizeof(struct transient_heap_block_header) #define TRANSIENT_HEAP_ALLOC_MAGIC 0xfeab #define TRANSIENT_HEAP_ALLOC_ALIGN RUBY_ALIGNOF(void *) @@ -77,13 +78,12 @@ enum transient_heap_status { https://github.com/ruby/ruby/blob/trunk/transient_heap.c#L78 struct transient_heap_block { struct transient_heap_block_header { - int16_t size; /* sizeof(block) = TRANSIENT_HEAP_BLOCK_SIZE - sizeof(struct transient_heap_block_header) */ int16_t index; int16_t last_marked_index; int16_t objects; struct transient_heap_block *next_block; } info; - char buff[TRANSIENT_HEAP_BLOCK_SIZE - sizeof(struct transient_heap_block_header)]; + char buff[TRANSIENT_HEAP_USABLE_SIZE]; }; struct transient_heap { @@ -240,7 +240,6 @@ static void https://github.com/ruby/ruby/blob/trunk/transient_heap.c#L240 reset_block(struct transient_heap_block *block) { __msan_allocated_memory(block, sizeof block); - block->info.size = TRANSIENT_HEAP_BLOCK_SIZE - sizeof(struct transient_heap_block_header); block->info.index = 0; block->info.objects = 0; block->info.last_marked_index = TRANSIENT_HEAP_ALLOC_MARKING_LAST; @@ -345,9 +344,9 @@ transient_heap_allocatable_header(struct transient_heap* theap, size_t size) https://github.com/ruby/ruby/blob/trunk/transient_heap.c#L344 struct transient_heap_block *block = theap->using_blocks; while (block) { - TH_ASSERT(block->info.size >= block->info.index); + TH_ASSERT(block->info.index <= TRANSIENT_HEAP_USABLE_SIZE); - if (block->info.size - block->info.index >= (int32_t)size) { + if (TRANSIENT_HEAP_USABLE_SIZE - block->info.index >= size) { struct transient_alloc_header *header = (void *)&block->buff[block->info.index]; block->info.index += size; block->info.objects++; @@ -470,7 +469,7 @@ blocks_alloc_header_to_block(struct transient_heap *theap, struct transient_heap https://github.com/ruby/ruby/blob/trunk/transient_heap.c#L469 struct transient_heap_block *block = blocks; while (block) { - if (block->buff <= (char *)header && (char *)header < block->buff + block->info.size) { + if (block->buff <= (char *)header && (char *)header < block->buff + TRANSIENT_HEAP_USABLE_SIZE) { return block; } block = block->info.next_block; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/