diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2534cd9284d5..914d690107ae 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10194,6 +10194,8 @@ static void btrfs_free_swapfile_pins(struct inode *inode) struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; struct btrfs_swapfile_pin *sp; struct rb_node *node, *next; + u64 bg_bytes_released = 0; + u32 bg_nr_released = 0; spin_lock(&fs_info->swapfile_pins_lock); node = rb_first(&fs_info->swapfile_pins); @@ -10203,15 +10205,24 @@ static void btrfs_free_swapfile_pins(struct inode *inode) if (sp->inode == inode) { rb_erase(&sp->node, &fs_info->swapfile_pins); if (sp->is_block_group) { - btrfs_dec_block_group_swap_extents(sp->ptr, + struct btrfs_block_group *bg = sp->ptr; + + bg_bytes_released += bg->length; + bg_nr_released++; + btrfs_dec_block_group_swap_extents(bg, sp->bg_extent_count); - btrfs_put_block_group(sp->ptr); + btrfs_put_block_group(bg); } kfree(sp); } node = next; } spin_unlock(&fs_info->swapfile_pins_lock); + btrfs_info(fs_info, +"swapfile deactivated on root %llu ino %llu, released %llu bytes from %u block group(s)", + btrfs_root_id(BTRFS_I(inode)->root), + btrfs_ino(BTRFS_I(inode)), bg_bytes_released, + bg_nr_released); } struct btrfs_swap_info { @@ -10289,8 +10300,10 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, struct btrfs_backref_share_check_ctx *backref_ctx = NULL; struct btrfs_path *path = NULL; int ret = 0; + u32 pinned_bg_nr = 0; u64 isize; u64 prev_extent_end = 0; + u64 pinned_bg_size = 0; /* * Acquire the inode's mmap lock to prevent races with memory mapped @@ -10540,6 +10553,9 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, ret = 0; else goto out; + } else { + pinned_bg_size += bg->length; + pinned_bg_nr++; } if (bsi.block_len && @@ -10587,6 +10603,14 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, if (ret) return ret; + btrfs_info(fs_info, +"swapfile activated on root %llu ino %llu, pinned down %llu bytes from %u block group(s)", + btrfs_root_id(BTRFS_I(inode)->root), + btrfs_ino(BTRFS_I(inode)), + pinned_bg_size, pinned_bg_nr); + btrfs_warn(fs_info, +"block groups with swapfile extents will not be scrubbed or balanced"); + if (device) sis->bdev = device->bdev; *span = bsi.highest_ppage - bsi.lowest_ppage + 1; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 6eab4cc73ce4..2d132c827913 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4588,7 +4588,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) if (ret == -ENOSPC) { enospc_errors++; } else if (ret == -ETXTBSY) { - btrfs_info(fs_info, + btrfs_warn(fs_info, "skipping relocation of block group %llu due to active swapfile", found_key.offset); ret = 0;