Skip to content

Commit 5896210

Browse files
two-heartjvarela-jump
authored andcommitted
blockstore: round up shred_max to a power of two
nit, but it is easy to imagine an operator putting in a value that is not a power of two, which would lead to fd_buf_shred_map_footprint being 0.
1 parent 0aea95f commit 5896210

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/flamenco/runtime/fd_blockstore.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ fd_blockstore_new( void * shmem,
4242
return NULL;
4343
}
4444

45+
if( FD_UNLIKELY( !fd_ulong_is_pow2( shred_max ) ) ) {
46+
shred_max = fd_ulong_pow2_up( shred_max );
47+
FD_LOG_WARNING(( "blockstore implementation requires shred_max to be a power of two, rounding it up to %lu", shred_max ));
48+
}
49+
4550
fd_memset( blockstore_shmem, 0, fd_blockstore_footprint( shred_max, block_max, idx_max, txn_max ) );
4651

4752
int lg_idx_max = fd_ulong_find_msb( fd_ulong_pow2_up( idx_max ) );
@@ -51,7 +56,7 @@ fd_blockstore_new( void * shmem,
5156
void * shreds = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_buf_shred_t), sizeof(fd_buf_shred_t) * shred_max );
5257
void * shred_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_buf_shred_pool_align(), fd_buf_shred_pool_footprint() );
5358
void * shred_map = FD_SCRATCH_ALLOC_APPEND( l, fd_buf_shred_map_align(), fd_buf_shred_map_footprint( shred_max ) );
54-
void * blocks = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_block_info_t), sizeof(fd_block_info_t) * block_max );
59+
void * blocks = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_block_info_t), sizeof(fd_block_info_t) * block_max );
5560
void * block_map = FD_SCRATCH_ALLOC_APPEND( l, fd_block_map_align(), fd_block_map_footprint( block_max, lock_cnt, BLOCK_INFO_PROBE_CNT ) );
5661
void * block_idx = FD_SCRATCH_ALLOC_APPEND( l, fd_block_idx_align(), fd_block_idx_footprint( lg_idx_max ) );
5762
void * slot_deque = FD_SCRATCH_ALLOC_APPEND( l, fd_slot_deque_align(), fd_slot_deque_footprint( block_max ) );

0 commit comments

Comments
 (0)