summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorChris Mason2008-04-28 15:02:36 +0200
committerChris Mason2008-09-25 17:04:02 +0200
commit8e7bf94fd5f44fa585e29fbe6a1bfabc04aea7cf (patch)
treecf7ff2d942c5af49c43a8a7701b32267815c839f /fs/btrfs/inode.c
parentBtrfs: Avoid recursive chunk allocations (diff)
downloadkernel-qcow2-linux-8e7bf94fd5f44fa585e29fbe6a1bfabc04aea7cf.tar.gz
kernel-qcow2-linux-8e7bf94fd5f44fa585e29fbe6a1bfabc04aea7cf.tar.xz
kernel-qcow2-linux-8e7bf94fd5f44fa585e29fbe6a1bfabc04aea7cf.zip
Btrfs: Do more optimal file RA during shrinking and defrag
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4d12aa532c5b..ab707c0930df 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2814,14 +2814,12 @@ unsigned long btrfs_force_ra(struct address_space *mapping,
struct file_ra_state *ra, struct file *file,
pgoff_t offset, pgoff_t last_index)
{
- pgoff_t req_size;
+ pgoff_t req_size = last_index - offset + 1;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
- req_size = last_index - offset + 1;
offset = page_cache_readahead(mapping, ra, file, offset, req_size);
return offset;
#else
- req_size = min(last_index - offset + 1, (pgoff_t)128);
page_cache_sync_readahead(mapping, ra, file, offset, req_size);
return offset + req_size;
#endif
@@ -2833,7 +2831,8 @@ int btrfs_defrag_file(struct file *file) {
struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
struct page *page;
unsigned long last_index;
- unsigned long ra_index = 0;
+ unsigned long ra_pages = root->fs_info->bdi.ra_pages;
+ unsigned long total_read = 0;
u64 page_start;
u64 page_end;
unsigned long i;
@@ -2848,11 +2847,11 @@ int btrfs_defrag_file(struct file *file) {
mutex_lock(&inode->i_mutex);
last_index = inode->i_size >> PAGE_CACHE_SHIFT;
for (i = 0; i <= last_index; i++) {
- if (i == ra_index) {
- ra_index = btrfs_force_ra(inode->i_mapping,
- &file->f_ra,
- file, ra_index, last_index);
+ if (total_read % ra_pages == 0) {
+ btrfs_force_ra(inode->i_mapping, &file->f_ra, file, i,
+ min(last_index, i + ra_pages - 1));
}
+ total_read++;
page = grab_cache_page(inode->i_mapping, i);
if (!page)
goto out_unlock;