@@ -75,7 +75,7 @@ INTERNAL_HIDDEN void create_canary_chunks(iso_alloc_zone_t *zone) {
7575 const bitmap_index_t max_bitmap_idx = GET_MAX_BITMASK_INDEX (zone ) - 1 ;
7676
7777 /* Roughly %1 of the chunks in this zone will become a canary */
78- const uint64_t canary_count = (zone -> chunk_count / CANARY_COUNT_DIV );
78+ const uint64_t canary_count = (zone -> chunk_count >> CANARY_COUNT_DIV );
7979
8080 /* This function is only ever called during zone
8181 * initialization so we don't need to check the
@@ -683,11 +683,12 @@ INTERNAL_HIDDEN iso_alloc_zone_t *_iso_new_zone(size_t size, bool internal) {
683683 new_zone -> is_full = false;
684684 new_zone -> chunk_size = size ;
685685
686- size_t chunk_count = (ZONE_USER_SIZE / new_zone -> chunk_size );
686+ new_zone -> chunk_size_pow2 = _log2 (new_zone -> chunk_size );
687+ new_zone -> chunk_count = (ZONE_USER_SIZE >> new_zone -> chunk_size_pow2 );
687688
688689 /* If a caller requests an allocation that is >=(ZONE_USER_SIZE/2)
689690 * then we need to allocate a minimum size bitmap */
690- uint32_t bitmap_size = (chunk_count << BITS_PER_CHUNK_SHIFT ) >> BITS_PER_BYTE_SHIFT ;
691+ uint32_t bitmap_size = (new_zone -> chunk_count << BITS_PER_CHUNK_SHIFT ) >> BITS_PER_BYTE_SHIFT ;
691692 new_zone -> bitmap_size = (bitmap_size > sizeof (bitmap_index_t )) ? bitmap_size : sizeof (bitmap_index_t );
692693
693694 /* All of the following fields are immutable
@@ -716,7 +717,6 @@ INTERNAL_HIDDEN iso_alloc_zone_t *_iso_new_zone(size_t size, bool internal) {
716717#endif
717718
718719 size_t total_size = ZONE_USER_SIZE + (_root -> system_page_size << 1 );
719- new_zone -> chunk_count = chunk_count ;
720720
721721#if MEMORY_TAGGING
722722 /* Each tag is 1 byte in size and the start address
@@ -1731,7 +1731,7 @@ INTERNAL_HIDDEN void iso_free_chunk_from_zone(iso_alloc_zone_t *zone, void *rest
17311731 p , zone -> index , zone -> chunk_size , (chunk_offset & (zone -> chunk_size - 1 )));
17321732 }
17331733
1734- const size_t chunk_number = (chunk_offset / zone -> chunk_size );
1734+ const size_t chunk_number = (chunk_offset >> zone -> chunk_size_pow2 );
17351735 const bit_slot_t bit_slot = (chunk_number << BITS_PER_CHUNK_SHIFT );
17361736 const bit_slot_t dwords_to_bit_slot = (bit_slot >> BITS_PER_QWORD_SHIFT );
17371737
@@ -2010,7 +2010,7 @@ INTERNAL_HIDDEN void _iso_free_internal_unlocked(void *p, bool permanent, iso_al
20102010 void * user_pages_start = UNMASK_USER_PTR (zone );
20112011 uint8_t * _mtp = (user_pages_start - _root -> system_page_size - ROUND_UP_PAGE (zone -> chunk_count * MEM_TAG_SIZE ));
20122012 uint64_t chunk_offset = (uint64_t ) (p - user_pages_start );
2013- _mtp += (chunk_offset / zone -> chunk_size );
2013+ _mtp += (chunk_offset >> zone -> chunk_size_pow2 );
20142014
20152015 /* Generate and write a new tag for this chunk */
20162016 uint8_t mem_tag = (uint8_t ) rand_uint64 ();
0 commit comments