Commit df480633 authored by Qu Wenruo's avatar Qu Wenruo Committed by Chris Mason

btrfs: extent-tree: Switch to new delalloc space reserve and release

Use new __btrfs_delalloc_reserve_space() and
__btrfs_delalloc_release_space() to reserve and release space for
delalloc.
Signed-off-by: default avatarQu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 1ada3a62
...@@ -1608,7 +1608,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, ...@@ -1608,7 +1608,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
btrfs_delalloc_release_metadata(inode, btrfs_delalloc_release_metadata(inode,
release_bytes); release_bytes);
else else
btrfs_delalloc_release_space(inode, __btrfs_delalloc_release_space(inode, pos,
release_bytes); release_bytes);
} }
...@@ -1661,7 +1661,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, ...@@ -1661,7 +1661,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
btrfs_end_write_no_snapshoting(root); btrfs_end_write_no_snapshoting(root);
btrfs_delalloc_release_metadata(inode, release_bytes); btrfs_delalloc_release_metadata(inode, release_bytes);
} else { } else {
btrfs_delalloc_release_space(inode, release_bytes); __btrfs_delalloc_release_space(inode, pos,
release_bytes);
} }
} }
......
...@@ -488,17 +488,17 @@ int btrfs_save_ino_cache(struct btrfs_root *root, ...@@ -488,17 +488,17 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
/* Just to make sure we have enough space */ /* Just to make sure we have enough space */
prealloc += 8 * PAGE_CACHE_SIZE; prealloc += 8 * PAGE_CACHE_SIZE;
ret = btrfs_delalloc_reserve_space(inode, prealloc); ret = __btrfs_delalloc_reserve_space(inode, 0, prealloc);
if (ret) if (ret)
goto out_put; goto out_put;
ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, prealloc, ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, prealloc,
prealloc, prealloc, &alloc_hint); prealloc, prealloc, &alloc_hint);
if (ret) { if (ret) {
btrfs_delalloc_release_space(inode, prealloc); __btrfs_delalloc_release_space(inode, 0, prealloc);
goto out_put; goto out_put;
} }
btrfs_free_reserved_data_space(inode, prealloc); __btrfs_free_reserved_data_space(inode, 0, prealloc);
ret = btrfs_write_out_ino_cache(root, trans, path, inode); ret = btrfs_write_out_ino_cache(root, trans, path, inode);
out_put: out_put:
......
...@@ -1769,7 +1769,8 @@ static void btrfs_clear_bit_hook(struct inode *inode, ...@@ -1769,7 +1769,8 @@ static void btrfs_clear_bit_hook(struct inode *inode,
if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
&& do_list && !(state->state & EXTENT_NORESERVE)) && do_list && !(state->state & EXTENT_NORESERVE))
btrfs_free_reserved_data_space(inode, len); __btrfs_free_reserved_data_space(inode, state->start,
len);
__percpu_counter_add(&root->fs_info->delalloc_bytes, -len, __percpu_counter_add(&root->fs_info->delalloc_bytes, -len,
root->fs_info->delalloc_batch); root->fs_info->delalloc_batch);
...@@ -1992,7 +1993,8 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) ...@@ -1992,7 +1993,8 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work)
goto again; goto again;
} }
ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); ret = __btrfs_delalloc_reserve_space(inode, page_start,
PAGE_CACHE_SIZE);
if (ret) { if (ret) {
mapping_set_error(page->mapping, ret); mapping_set_error(page->mapping, ret);
end_extent_writepage(page, ret, page_start, page_end); end_extent_writepage(page, ret, page_start, page_end);
...@@ -4638,14 +4640,17 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len, ...@@ -4638,14 +4640,17 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
if ((offset & (blocksize - 1)) == 0 && if ((offset & (blocksize - 1)) == 0 &&
(!len || ((len & (blocksize - 1)) == 0))) (!len || ((len & (blocksize - 1)) == 0)))
goto out; goto out;
ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); ret = __btrfs_delalloc_reserve_space(inode,
round_down(from, PAGE_CACHE_SIZE), PAGE_CACHE_SIZE);
if (ret) if (ret)
goto out; goto out;
again: again:
page = find_or_create_page(mapping, index, mask); page = find_or_create_page(mapping, index, mask);
if (!page) { if (!page) {
btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); __btrfs_delalloc_release_space(inode,
round_down(from, PAGE_CACHE_SIZE),
PAGE_CACHE_SIZE);
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
...@@ -4713,7 +4718,8 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len, ...@@ -4713,7 +4718,8 @@ int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,
out_unlock: out_unlock:
if (ret) if (ret)
btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); __btrfs_delalloc_release_space(inode, page_start,
PAGE_CACHE_SIZE);
unlock_page(page); unlock_page(page);
page_cache_release(page); page_cache_release(page);
out: out:
...@@ -7644,7 +7650,7 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, ...@@ -7644,7 +7650,7 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&BTRFS_I(inode)->lock);
} }
btrfs_free_reserved_data_space(inode, len); __btrfs_free_reserved_data_space(inode, start, len);
WARN_ON(dio_data->reserve < len); WARN_ON(dio_data->reserve < len);
dio_data->reserve -= len; dio_data->reserve -= len;
current->journal_info = dio_data; current->journal_info = dio_data;
...@@ -8434,7 +8440,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, ...@@ -8434,7 +8440,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
relock = true; relock = true;
} }
ret = btrfs_delalloc_reserve_space(inode, count); ret = __btrfs_delalloc_reserve_space(inode, offset, count);
if (ret) if (ret)
goto out; goto out;
dio_data.outstanding_extents = div64_u64(count + dio_data.outstanding_extents = div64_u64(count +
...@@ -8463,11 +8469,11 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, ...@@ -8463,11 +8469,11 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
current->journal_info = NULL; current->journal_info = NULL;
if (ret < 0 && ret != -EIOCBQUEUED) { if (ret < 0 && ret != -EIOCBQUEUED) {
if (dio_data.reserve) if (dio_data.reserve)
btrfs_delalloc_release_space(inode, __btrfs_delalloc_release_space(inode, offset,
dio_data.reserve); dio_data.reserve);
} else if (ret >= 0 && (size_t)ret < count) } else if (ret >= 0 && (size_t)ret < count)
btrfs_delalloc_release_space(inode, __btrfs_delalloc_release_space(inode, offset,
count - (size_t)ret); count - (size_t)ret);
} }
out: out:
if (wakeup) if (wakeup)
...@@ -8675,7 +8681,11 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -8675,7 +8681,11 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
u64 page_end; u64 page_end;
sb_start_pagefault(inode->i_sb); sb_start_pagefault(inode->i_sb);
ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); page_start = page_offset(page);
page_end = page_start + PAGE_CACHE_SIZE - 1;
ret = __btrfs_delalloc_reserve_space(inode, page_start,
PAGE_CACHE_SIZE);
if (!ret) { if (!ret) {
ret = file_update_time(vma->vm_file); ret = file_update_time(vma->vm_file);
reserved = 1; reserved = 1;
...@@ -8694,8 +8704,6 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -8694,8 +8704,6 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
again: again:
lock_page(page); lock_page(page);
size = i_size_read(inode); size = i_size_read(inode);
page_start = page_offset(page);
page_end = page_start + PAGE_CACHE_SIZE - 1;
if ((page->mapping != inode->i_mapping) || if ((page->mapping != inode->i_mapping) ||
(page_start >= size)) { (page_start >= size)) {
...@@ -8772,7 +8780,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -8772,7 +8780,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
} }
unlock_page(page); unlock_page(page);
out: out:
btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); __btrfs_delalloc_release_space(inode, page_start, PAGE_CACHE_SIZE);
out_noreserve: out_noreserve:
sb_end_pagefault(inode->i_sb); sb_end_pagefault(inode->i_sb);
return ret; return ret;
......
...@@ -1119,8 +1119,9 @@ static int cluster_pages_for_defrag(struct inode *inode, ...@@ -1119,8 +1119,9 @@ static int cluster_pages_for_defrag(struct inode *inode,
page_cnt = min_t(u64, (u64)num_pages, (u64)file_end - start_index + 1); page_cnt = min_t(u64, (u64)num_pages, (u64)file_end - start_index + 1);
ret = btrfs_delalloc_reserve_space(inode, ret = __btrfs_delalloc_reserve_space(inode,
page_cnt << PAGE_CACHE_SHIFT); start_index << PAGE_CACHE_SHIFT,
page_cnt << PAGE_CACHE_SHIFT);
if (ret) if (ret)
return ret; return ret;
i_done = 0; i_done = 0;
...@@ -1209,8 +1210,9 @@ static int cluster_pages_for_defrag(struct inode *inode, ...@@ -1209,8 +1210,9 @@ static int cluster_pages_for_defrag(struct inode *inode,
spin_lock(&BTRFS_I(inode)->lock); spin_lock(&BTRFS_I(inode)->lock);
BTRFS_I(inode)->outstanding_extents++; BTRFS_I(inode)->outstanding_extents++;
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&BTRFS_I(inode)->lock);
btrfs_delalloc_release_space(inode, __btrfs_delalloc_release_space(inode,
(page_cnt - i_done) << PAGE_CACHE_SHIFT); start_index << PAGE_CACHE_SHIFT,
(page_cnt - i_done) << PAGE_CACHE_SHIFT);
} }
...@@ -1235,7 +1237,9 @@ static int cluster_pages_for_defrag(struct inode *inode, ...@@ -1235,7 +1237,9 @@ static int cluster_pages_for_defrag(struct inode *inode,
unlock_page(pages[i]); unlock_page(pages[i]);
page_cache_release(pages[i]); page_cache_release(pages[i]);
} }
btrfs_delalloc_release_space(inode, page_cnt << PAGE_CACHE_SHIFT); __btrfs_delalloc_release_space(inode,
start_index << PAGE_CACHE_SHIFT,
page_cnt << PAGE_CACHE_SHIFT);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment