From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 6/7] btrfs: Replace open-coded maths with DIV_ROUND_UP
Date: Thu, 3 Jan 2019 10:50:04 +0200 [thread overview]
Message-ID: <20190103085005.32053-7-nborisov@suse.com> (raw)
In-Reply-To: <20190103085005.32053-1-nborisov@suse.com>
In a couple of places it's required to calculate the number of pages
given a start and end offsets. Currently this is opencoded, unify the
code base by replacing all such sites with the DIV_ROUND_UP macro. Also,
current open-coded sites were buggy in that they were adding
'PAGE_SIZE', rather than 'PAGE_SIZE - 1'.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/extent_io.c | 7 +++----
fs/btrfs/inode.c | 8 +++-----
2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index b9b30e618378..0cd41ec8b698 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3189,8 +3189,8 @@ static noinline_for_stack int writepage_delalloc(struct inode *inode,
* delalloc_end is already one less than the total length, so
* we don't subtract one from PAGE_SIZE
*/
- delalloc_to_write += (delalloc_end - delalloc_start +
- PAGE_SIZE) >> PAGE_SHIFT;
+ delalloc_to_write += DIV_ROUND_UP(delalloc_end - delalloc_start,
+ PAGE_SIZE);
delalloc_start = delalloc_end + 1;
}
if (wbc->nr_to_write < delalloc_to_write) {
@@ -4001,8 +4001,7 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
struct address_space *mapping = inode->i_mapping;
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
struct page *page;
- unsigned long nr_pages = (end - start + PAGE_SIZE) >>
- PAGE_SHIFT;
+ unsigned long nr_pages = DIV_ROUND_UP(end - start, PAGE_SIZE);
struct extent_page_data epd = {
.bio = NULL,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 41ad0d06b3d4..32977174826b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -469,7 +469,7 @@ static noinline void compress_file_range(struct inode *inode,
actual_end = min_t(u64, i_size_read(inode), end + 1);
again:
will_compress = 0;
- nr_pages = (end >> PAGE_SHIFT) - (start >> PAGE_SHIFT) + 1;
+ nr_pages = DIV_ROUND_UP(end - start, PAGE_SIZE);
BUILD_BUG_ON((BTRFS_MAX_COMPRESSED % PAGE_SIZE) != 0);
nr_pages = min_t(unsigned long, nr_pages,
BTRFS_MAX_COMPRESSED / PAGE_SIZE);
@@ -1157,8 +1157,7 @@ static noinline void async_cow_submit(struct btrfs_work *work)
async_cow = container_of(work, struct async_cow, work);
fs_info = async_cow->fs_info;
- nr_pages = (async_cow->end - async_cow->start + PAGE_SIZE) >>
- PAGE_SHIFT;
+ nr_pages = DIV_ROUND_UP(async_cow->end - async_cow->start, PAGE_SIZE);
/* atomic_sub_return implies a barrier */
if (atomic_sub_return(nr_pages, &fs_info->async_delalloc_pages) <
@@ -1221,8 +1220,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
async_cow_start, async_cow_submit,
async_cow_free);
- nr_pages = (cur_end - start + PAGE_SIZE) >>
- PAGE_SHIFT;
+ nr_pages = DIV_ROUND_UP(cur_end - start, PAGE_SIZE);
atomic_add(nr_pages, &fs_info->async_delalloc_pages);
btrfs_queue_work(fs_info->delalloc_workers, &async_cow->work);
--
2.17.1
next prev parent reply other threads:[~2019-01-03 8:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-03 8:49 [PATCH 0/7] More misc fixes Nikolay Borisov
2019-01-03 8:49 ` [PATCH 1/7] btrfs: Remove inode argument from async_cow_submit Nikolay Borisov
2019-01-05 6:02 ` Anand Jain
2019-01-07 10:12 ` Johannes Thumshirn
2019-01-03 8:50 ` [PATCH 2/7] btrfs: Remove isize local variable in compress_file_range Nikolay Borisov
2019-01-05 6:17 ` Anand Jain
2019-01-07 10:17 ` Johannes Thumshirn
2019-01-07 17:41 ` David Sterba
2019-01-03 8:50 ` [PATCH 3/7] btrfs: Use ihold instead of igrab in cow_file_range_async Nikolay Borisov
2019-01-04 15:29 ` David Sterba
2019-01-03 8:50 ` [PATCH 4/7] btrfs: Remove WARN_ON in btrfs_alloc_delalloc_work Nikolay Borisov
2019-01-04 15:30 ` David Sterba
2019-01-07 10:19 ` Johannes Thumshirn
2019-01-03 8:50 ` [PATCH 5/7] btrfs: Document logic in async_cow_submit Nikolay Borisov
2019-01-03 8:50 ` Nikolay Borisov [this message]
2019-01-03 14:44 ` [PATCH 6/7] btrfs: Replace open-coded maths with DIV_ROUND_UP David Sterba
2019-01-03 15:33 ` Nikolay Borisov
2019-01-07 15:29 ` David Sterba
2019-01-03 8:50 ` [PATCH 7/7] btrfs: Refactor shrink_delalloc Nikolay Borisov
2019-01-04 15:35 ` David Sterba
2019-01-07 17:58 ` David Sterba
2019-01-07 17:59 ` [PATCH 0/7] More misc fixes David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190103085005.32053-7-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox