* [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages()
@ 2020-10-14 14:55 Goldwyn Rodrigues
2020-10-14 14:55 ` [PATCH] btrfs: Set EXTENT_NORESERVE bits " Goldwyn Rodrigues
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Goldwyn Rodrigues @ 2020-10-14 14:55 UTC (permalink / raw)
To: linux-btrfs; +Cc: Goldwyn Rodrigues
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
round_down looks prettier than the bit mask operations.
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
fs/btrfs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 0ff659455b1e..6e52e2360d8e 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -514,7 +514,7 @@ int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
loff_t isize = i_size_read(&inode->vfs_inode);
unsigned int extra_bits = 0;
- start_pos = pos & ~((u64) fs_info->sectorsize - 1);
+ start_pos = round_down(pos, fs_info->sectorsize);
num_bytes = round_up(write_bytes + pos - start_pos,
fs_info->sectorsize);
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] btrfs: Set EXTENT_NORESERVE bits in btrfs_dirty_pages()
2020-10-14 14:55 [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages() Goldwyn Rodrigues
@ 2020-10-14 14:55 ` Goldwyn Rodrigues
2020-10-15 6:22 ` Nikolay Borisov
2020-10-14 17:49 ` [PATCH] btrfs: Use round_down while calculating start position " Nikolay Borisov
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Goldwyn Rodrigues @ 2020-10-14 14:55 UTC (permalink / raw)
To: linux-btrfs; +Cc: Goldwyn Rodrigues
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
Set the extent bits EXTENT_NORESERVE in btrfs_dirty_pages() as opposed
to calling set_extent_bits again later.
Fold check for written length within the function.
Note: EXTENT_NORESERVE is set before unlocking extents.
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
fs/btrfs/ctree.h | 2 +-
fs/btrfs/file.c | 26 ++++++++++----------------
fs/btrfs/free-space-cache.c | 2 +-
3 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index aac3d6f4e35b..42e9ac0fb641 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3109,7 +3109,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
int btrfs_release_file(struct inode *inode, struct file *file);
int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
size_t num_pages, loff_t pos, size_t write_bytes,
- struct extent_state **cached);
+ struct extent_state **cached, bool noreserve);
int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
size_t *write_bytes);
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 6e52e2360d8e..6b4114a5fd92 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -502,7 +502,7 @@ static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode,
*/
int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
size_t num_pages, loff_t pos, size_t write_bytes,
- struct extent_state **cached)
+ struct extent_state **cached, bool noreserve)
{
struct btrfs_fs_info *fs_info = inode->root->fs_info;
int err = 0;
@@ -514,6 +514,12 @@ int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
loff_t isize = i_size_read(&inode->vfs_inode);
unsigned int extra_bits = 0;
+ if (write_bytes == 0)
+ return 0;
+
+ if (noreserve)
+ extra_bits |= EXTENT_NORESERVE;
+
start_pos = round_down(pos, fs_info->sectorsize);
num_bytes = round_up(write_bytes + pos - start_pos,
fs_info->sectorsize);
@@ -1787,10 +1793,9 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
release_bytes = round_up(copied + sector_offset,
fs_info->sectorsize);
- if (copied > 0)
- ret = btrfs_dirty_pages(BTRFS_I(inode), pages,
- dirty_pages, pos, copied,
- &cached_state);
+ ret = btrfs_dirty_pages(BTRFS_I(inode), pages,
+ dirty_pages, pos, copied,
+ &cached_state, only_release_metadata);
/*
* If we have not locked the extent range, because the range's
@@ -1815,17 +1820,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
if (only_release_metadata)
btrfs_check_nocow_unlock(BTRFS_I(inode));
- if (only_release_metadata && copied > 0) {
- lockstart = round_down(pos,
- fs_info->sectorsize);
- lockend = round_up(pos + copied,
- fs_info->sectorsize) - 1;
-
- set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
- lockend, EXTENT_NORESERVE, NULL,
- NULL, GFP_NOFS);
- }
-
btrfs_drop_pages(pages, num_pages);
cond_resched();
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index af0013d3df63..5ea36a06e514 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1332,7 +1332,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
/* Everything is written out, now we dirty the pages in the file. */
ret = btrfs_dirty_pages(BTRFS_I(inode), io_ctl->pages,
io_ctl->num_pages, 0, i_size_read(inode),
- &cached_state);
+ &cached_state, false);
if (ret)
goto out_nospc;
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages()
2020-10-14 14:55 [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages() Goldwyn Rodrigues
2020-10-14 14:55 ` [PATCH] btrfs: Set EXTENT_NORESERVE bits " Goldwyn Rodrigues
@ 2020-10-14 17:49 ` Nikolay Borisov
2020-10-15 7:26 ` Qu Wenruo
2020-10-16 15:22 ` David Sterba
3 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2020-10-14 17:49 UTC (permalink / raw)
To: Goldwyn Rodrigues, linux-btrfs; +Cc: Goldwyn Rodrigues
On 14.10.20 г. 17:55 ч., Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
>
> round_down looks prettier than the bit mask operations.
>
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] btrfs: Set EXTENT_NORESERVE bits in btrfs_dirty_pages()
2020-10-14 14:55 ` [PATCH] btrfs: Set EXTENT_NORESERVE bits " Goldwyn Rodrigues
@ 2020-10-15 6:22 ` Nikolay Borisov
0 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2020-10-15 6:22 UTC (permalink / raw)
To: Goldwyn Rodrigues, linux-btrfs; +Cc: Goldwyn Rodrigues
On 14.10.20 г. 17:55 ч., Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
>
> Set the extent bits EXTENT_NORESERVE in btrfs_dirty_pages() as opposed
> to calling set_extent_bits again later.
>
> Fold check for written length within the function.
>
> Note: EXTENT_NORESERVE is set before unlocking extents.
>
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages()
2020-10-14 14:55 [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages() Goldwyn Rodrigues
2020-10-14 14:55 ` [PATCH] btrfs: Set EXTENT_NORESERVE bits " Goldwyn Rodrigues
2020-10-14 17:49 ` [PATCH] btrfs: Use round_down while calculating start position " Nikolay Borisov
@ 2020-10-15 7:26 ` Qu Wenruo
2020-10-16 15:22 ` David Sterba
3 siblings, 0 replies; 6+ messages in thread
From: Qu Wenruo @ 2020-10-15 7:26 UTC (permalink / raw)
To: Goldwyn Rodrigues, linux-btrfs; +Cc: Goldwyn Rodrigues
[-- Attachment #1.1: Type: text/plain, Size: 912 bytes --]
On 2020/10/14 下午10:55, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
>
> round_down looks prettier than the bit mask operations.
>
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/file.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 0ff659455b1e..6e52e2360d8e 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -514,7 +514,7 @@ int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
> loff_t isize = i_size_read(&inode->vfs_inode);
> unsigned int extra_bits = 0;
>
> - start_pos = pos & ~((u64) fs_info->sectorsize - 1);
> + start_pos = round_down(pos, fs_info->sectorsize);
> num_bytes = round_up(write_bytes + pos - start_pos,
> fs_info->sectorsize);
>
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages()
2020-10-14 14:55 [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages() Goldwyn Rodrigues
` (2 preceding siblings ...)
2020-10-15 7:26 ` Qu Wenruo
@ 2020-10-16 15:22 ` David Sterba
3 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2020-10-16 15:22 UTC (permalink / raw)
To: Goldwyn Rodrigues; +Cc: linux-btrfs, Goldwyn Rodrigues
On Wed, Oct 14, 2020 at 09:55:44AM -0500, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
>
> round_down looks prettier than the bit mask operations.
>
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
1 and 2 added to misc-next, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-10-16 15:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 14:55 [PATCH] btrfs: Use round_down while calculating start position in btrfs_dirty_pages() Goldwyn Rodrigues
2020-10-14 14:55 ` [PATCH] btrfs: Set EXTENT_NORESERVE bits " Goldwyn Rodrigues
2020-10-15 6:22 ` Nikolay Borisov
2020-10-14 17:49 ` [PATCH] btrfs: Use round_down while calculating start position " Nikolay Borisov
2020-10-15 7:26 ` Qu Wenruo
2020-10-16 15:22 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.