diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index f5de8ab9787e..be2e20d163ef 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -304,6 +304,11 @@ static int __btrfs_run_defrag_inode(struct btrfs_fs_info *fs_info, sb_start_write(fs_info->sb); ret = btrfs_defrag_file(inode, NULL, &ctrl); sb_end_write(fs_info->sb); + trace_printk("defrag finish r/i=%lld/%llu ret=%d defragged=%llu last_scanned=%llu last_off=%llu cycled=%d\n", + BTRFS_I(inode)->root->root_key.objectid, + btrfs_ino(BTRFS_I(inode)), ret, ctrl.sectors_defragged, + ctrl.last_scanned, + defrag->last_offset, defrag->cycled); /* * if we filled the whole defrag batch, there * must be more work to do. Queue this defrag diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 133e3e2e2e79..a0501c88922b 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1420,6 +1420,11 @@ static int defrag_collect_targets(struct btrfs_inode *inode, add: last_is_target = true; range_len = min(extent_map_end(em), start + len) - cur; + + trace_printk("add target r/i=%lld/%llu start=%llu len=%llu em=%llu len=%llu gen=%lld newer=%llu\n", + inode->root->root_key.objectid, + btrfs_ino(inode), cur, range_len, em->start, em->len, + em->generation, ctrl->newer_than); /* * This one is a good target, check if it can be merged into * last range of the target list. @@ -1520,6 +1525,9 @@ static int defrag_one_locked_target(struct btrfs_inode *inode, EXTENT_DEFRAG, 0, 0, cached_state); set_extent_defrag(&inode->io_tree, start, start + len - 1, cached_state); + trace_printk("defrag target r/i=%lld/%llu start=%llu len=%llu\n", + inode->root->root_key.objectid, + btrfs_ino(inode), start, len); /* Update the page status */ for (i = start_index - first_index; i <= last_index - first_index; i++) { ClearPageChecked(pages[i]); @@ -1786,6 +1794,12 @@ int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra, if (start_index < inode->i_mapping->writeback_index) inode->i_mapping->writeback_index = start_index; + trace_printk("entry r/i=%lld/%llu start=%llu len=%llu newer=%llu thres=%u\n", + BTRFS_I(inode)->root->root_key.objectid, + btrfs_ino(BTRFS_I(inode)), + ctrl->last_scanned, last_byte + 1 - ctrl->last_scanned, + ctrl->newer_than, ctrl->extent_thresh); + while (ctrl->last_scanned < last_byte) { const unsigned long prev_sectors_defragged = ctrl->sectors_defragged; u64 cluster_end;