Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Btrfs: make shrink_delalloc a little friendlier

Xfstests 224 will just sit there and spin for ever until eventually we give up
flushing delalloc and exit. On my box this took several hours. I could not
interrupt this process either, even though we use INTERRUPTIBLE. So do 2 things

1) Keep us from looping over and over again without reclaiming anything
2) If we get interrupted exit the loop

I tested this and the test now exits in a reasonable amount of time, and can be
interrupted with ctrl+c. Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>

authored by

Josef Bacik and committed by
Chris Mason
b1953bce 7adf5dfb

+14 -3
+14 -3
fs/btrfs/extent-tree.c
··· 3345 3345 u64 reserved; 3346 3346 u64 max_reclaim; 3347 3347 u64 reclaimed = 0; 3348 + long time_left; 3348 3349 int pause = 1; 3349 3350 int nr_pages = (2 * 1024 * 1024) >> PAGE_CACHE_SHIFT; 3351 + int loops = 0; 3350 3352 3351 3353 block_rsv = &root->fs_info->delalloc_block_rsv; 3352 3354 space_info = block_rsv->space_info; ··· 3361 3359 3362 3360 max_reclaim = min(reserved, to_reclaim); 3363 3361 3364 - while (1) { 3362 + while (loops < 1024) { 3365 3363 /* have the flusher threads jump in and do some IO */ 3366 3364 smp_mb(); 3367 3365 nr_pages = min_t(unsigned long, nr_pages, ··· 3369 3367 writeback_inodes_sb_nr_if_idle(root->fs_info->sb, nr_pages); 3370 3368 3371 3369 spin_lock(&space_info->lock); 3372 - if (reserved > space_info->bytes_reserved) 3370 + if (reserved > space_info->bytes_reserved) { 3371 + loops = 0; 3373 3372 reclaimed += reserved - space_info->bytes_reserved; 3373 + } else { 3374 + loops++; 3375 + } 3374 3376 reserved = space_info->bytes_reserved; 3375 3377 spin_unlock(&space_info->lock); 3376 3378 ··· 3385 3379 return -EAGAIN; 3386 3380 3387 3381 __set_current_state(TASK_INTERRUPTIBLE); 3388 - schedule_timeout(pause); 3382 + time_left = schedule_timeout(pause); 3383 + 3384 + /* We were interrupted, exit */ 3385 + if (time_left) 3386 + break; 3387 + 3389 3388 pause <<= 1; 3390 3389 if (pause > HZ / 10) 3391 3390 pause = HZ / 10;