diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index 0b41e1db4de99b69acb226b39827c82caa3d6259..4016d2c191cedf9bdc756489bead9bb3fa7b34d7 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -63,6 +63,8 @@ #define LIST_DIRTY 1 #define LIST_SIZE 2 +#define SCAN_RESCHED_CYCLE 16 + /* * Linking of buffers: * All buffers are linked to cache_hash with their hash_list field. @@ -1599,7 +1601,12 @@ static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan, freed++; if (!--nr_to_scan || ((count - freed) <= retain_target)) return freed; - cond_resched(); + + if (unlikely(freed % SCAN_RESCHED_CYCLE == 0)) { + dm_bufio_unlock(c); + cond_resched(); + dm_bufio_lock(c); + } } } return freed;