bitset: Fix large runs

This commit is contained in:
nick
2013-07-24 17:42:08 +01:00
parent 5c59a412af
commit bed8959d47
5 changed files with 31 additions and 7 deletions

View File

@@ -74,7 +74,7 @@ static inline void bit_clear_range(char* b, uint64_t from, uint64_t len)
* up to a maximum number of bits ''len''. Returns the number of contiguous
* bits that are the same as the first one specified.
*/
static inline int bit_run_count(char* b, uint64_t from, uint64_t len) {
static inline uint64_t bit_run_count(char* b, uint64_t from, uint64_t len) {
uint64_t* current_block;
uint64_t count = 0;
int first_value = bit_is_set(b, from);
@@ -138,8 +138,8 @@ static inline struct bitset_mapping* bitset_alloc(
#define INT_FIRST_AND_LAST \
uint64_t first = from/set->resolution, \
last = (from+len-1)/set->resolution, \
bitlen = last-first+1
last = ((from+len)-1)/set->resolution, \
bitlen = (last-first)+1
#define BITSET_LOCK \
FATAL_IF_NEGATIVE(pthread_mutex_lock(&set->lock), "Error locking bitset")
@@ -214,10 +214,12 @@ static inline uint64_t bitset_run_count(
len = ( len + from ) > set->size ? ( set->size - from ) : len;
INT_FIRST_AND_LAST;
BITSET_LOCK;
run = (bit_run_count(set->bits, first, bitlen) * set->resolution) -
(from % set->resolution);
run = bit_run_count(set->bits, first, bitlen) * set->resolution;
run -= (from % set->resolution);
BITSET_UNLOCK;
return run;
}

View File

@@ -140,7 +140,7 @@ void write_not_zeroes(struct client* client, uint64_t from, uint64_t len)
char zerobuffer[block_allocation_resolution];
/* not allocated, read in block_allocation_resoution */
while (run > 0) {
int blockrun = block_allocation_resolution -
uint64_t blockrun = block_allocation_resolution -
(from % block_allocation_resolution);
if (blockrun > run)
blockrun = run;

View File

@@ -270,7 +270,7 @@ int fd_is_closed( int fd_in )
}
static inline int io_errno_permanent()
static inline int io_errno_permanent(void)
{
return ( errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR );
}

View File

@@ -106,6 +106,10 @@ void mirror_reset( struct mirror * mirror )
NULLCHECK( mirror->dirty_map );
mirror_set_state( mirror, MS_INIT );
bitset_set(mirror->dirty_map);
uint64_t run = bitset_run_count(mirror->dirty_map, 0, mirror->dirty_map->size);
warn( "bitset_run_count: %"PRIu64, run);
}