@@ -240,18 +240,33 @@ INTERNAL_HIDDEN INLINE void fill_free_bit_slot_cache(iso_alloc_zone_t *zone) {
240240 return ;
241241 }
242242
243- bit_slot_t bmt = bm [bm_idx ];
244-
245- for (uint64_t j = 0 ; j < BITS_PER_QWORD ; j += BITS_PER_CHUNK ) {
246- if ((GET_BIT (bmt , j )) == 0 ) {
247- zone -> free_bit_slot_cache [free_bit_slot_cache_index ] = (bm_idx << BITS_PER_QWORD_SHIFT ) + j ;
243+ bit_slot_t bts = bm [bm_idx ];
244+ bitmap_index_t bm_idx_shf = bm_idx << BITS_PER_QWORD_SHIFT ;
245+
246+ /* If the byte is 0 then its faster to add each
247+ * bitslot without checking each bit value */
248+ if (bts == 0x0 ) {
249+ for (uint64_t z = 0 ; z < BITS_PER_QWORD ; z += BITS_PER_CHUNK ) {
250+ zone -> free_bit_slot_cache [free_bit_slot_cache_index ] = (bm_idx_shf + z );
248251 free_bit_slot_cache_index ++ ;
249252
250253 if (free_bit_slot_cache_index >= BIT_SLOT_CACHE_SZ ) {
251254 zone -> free_bit_slot_cache_index = free_bit_slot_cache_index ;
252255 return ;
253256 }
254257 }
258+ } else {
259+ for (uint64_t j = 0 ; j < BITS_PER_QWORD ; j += BITS_PER_CHUNK ) {
260+ if ((GET_BIT (bts , j )) == 0 ) {
261+ zone -> free_bit_slot_cache [free_bit_slot_cache_index ] = (bm_idx_shf + j );
262+ free_bit_slot_cache_index ++ ;
263+
264+ if (free_bit_slot_cache_index >= BIT_SLOT_CACHE_SZ ) {
265+ zone -> free_bit_slot_cache_index = free_bit_slot_cache_index ;
266+ return ;
267+ }
268+ }
269+ }
255270 }
256271 }
257272
@@ -850,21 +865,18 @@ INTERNAL_HIDDEN bit_slot_t iso_scan_zone_free_slot(iso_alloc_zone_t *zone) {
850865
851866/* This function scans an entire bitmap bit-by-bit
852867 * and returns the first free bit position. In a heavily
853- * used zone this function will be slow to search. We
854- * speed it up by looking for a constant ALLOCATED_BITSLOTS
855- * that indicates there is at least 1 free bit slot */
868+ * used zone this function will be slow to search. */
856869INTERNAL_HIDDEN bit_slot_t iso_scan_zone_free_slot_slow (iso_alloc_zone_t * zone ) {
857870 const bitmap_index_t * bm = (bitmap_index_t * ) zone -> bitmap_start ;
858871
859872 for (bitmap_index_t i = 0 ; i < zone -> max_bitmap_idx ; i ++ ) {
860873 bit_slot_t bts = bm [i ];
874+
861875 for (int64_t j = 0 ; j < BITS_PER_QWORD ; j += BITS_PER_CHUNK ) {
862876 /* We can easily check if every bitslot represented by
863877 * this qword is allocated with or without canaries */
864- if (bts < ALLOCATED_BITSLOTS ) {
865- if ((GET_BIT (bts , j )) == 0 ) {
866- return ((i << BITS_PER_QWORD_SHIFT ) + j );
867- }
878+ if ((GET_BIT (bts , j )) == 0 ) {
879+ return ((i << BITS_PER_QWORD_SHIFT ) + j );
868880 }
869881 }
870882 }
0 commit comments