summaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2014-06-04 19:59:57 -0400
committerChris Mason <clm@fb.com>2014-09-17 16:37:17 -0400
commited6078f70335f158ca79790a0d0708ce558a6e9a (patch)
tree636322e2a1e25f7db9f5982204a8fa4bc1bf9cbf /fs/btrfs
parent4e54b17ad67a2d0d59bda6edcf725dc5b281c253 (diff)
btrfs: use DIV_ROUND_UP instead of open-coded variants
The form (value + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT is equivalent to (value + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE The rest is a simple subsitution, no difference in the generated assembly code. Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/check-integrity.c3
-rw-r--r--fs/btrfs/compression.c10
-rw-r--r--fs/btrfs/file.c19
-rw-r--r--fs/btrfs/free-space-cache.c3
-rw-r--r--fs/btrfs/ioctl.c5
-rw-r--r--fs/btrfs/lzo.c3
-rw-r--r--fs/btrfs/raid56.c8
-rw-r--r--fs/btrfs/zlib.c3
8 files changed, 22 insertions, 32 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index d0690da3b150..e0033c843ce7 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -1251,8 +1251,7 @@ static void btrfsic_read_from_block_data(
1251 1251
1252 while (len > 0) { 1252 while (len > 0) {
1253 cur = min(len, ((size_t)PAGE_CACHE_SIZE - offset_in_page)); 1253 cur = min(len, ((size_t)PAGE_CACHE_SIZE - offset_in_page));
1254 BUG_ON(i >= (block_ctx->len + PAGE_CACHE_SIZE - 1) >> 1254 BUG_ON(i >= DIV_ROUND_UP(block_ctx->len, PAGE_CACHE_SIZE));
1255 PAGE_CACHE_SHIFT);
1256 kaddr = block_ctx->datav[i]; 1255 kaddr = block_ctx->datav[i];
1257 memcpy(dst, kaddr + offset_in_page, cur); 1256 memcpy(dst, kaddr + offset_in_page, cur);
1258 1257
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 1daea0b47187..eeee13842cd0 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -91,8 +91,7 @@ static inline int compressed_bio_size(struct btrfs_root *root,
91 u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); 91 u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
92 92
93 return sizeof(struct compressed_bio) + 93 return sizeof(struct compressed_bio) +
94 ((disk_size + root->sectorsize - 1) / root->sectorsize) * 94 (DIV_ROUND_UP(disk_size, root->sectorsize)) * csum_size;
95 csum_size;
96} 95}
97 96
98static struct bio *compressed_bio_alloc(struct block_device *bdev, 97static struct bio *compressed_bio_alloc(struct block_device *bdev,
@@ -615,8 +614,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
615 cb->compress_type = extent_compress_type(bio_flags); 614 cb->compress_type = extent_compress_type(bio_flags);
616 cb->orig_bio = bio; 615 cb->orig_bio = bio;
617 616
618 nr_pages = (compressed_len + PAGE_CACHE_SIZE - 1) / 617 nr_pages = DIV_ROUND_UP(compressed_len, PAGE_CACHE_SIZE);
619 PAGE_CACHE_SIZE;
620 cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages, 618 cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages,
621 GFP_NOFS); 619 GFP_NOFS);
622 if (!cb->compressed_pages) 620 if (!cb->compressed_pages)
@@ -686,8 +684,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
686 comp_bio, sums); 684 comp_bio, sums);
687 BUG_ON(ret); /* -ENOMEM */ 685 BUG_ON(ret); /* -ENOMEM */
688 } 686 }
689 sums += (comp_bio->bi_iter.bi_size + 687 sums += DIV_ROUND_UP(comp_bio->bi_iter.bi_size,
690 root->sectorsize - 1) / root->sectorsize; 688 root->sectorsize);
691 689
692 ret = btrfs_map_bio(root, READ, comp_bio, 690 ret = btrfs_map_bio(root, READ, comp_bio,
693 mirror_num, 0); 691 mirror_num, 0);
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 033f04bac85b..2287545c5498 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1481,9 +1481,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1481 bool force_page_uptodate = false; 1481 bool force_page_uptodate = false;
1482 bool need_unlock; 1482 bool need_unlock;
1483 1483
1484 nrptrs = min((iov_iter_count(i) + PAGE_CACHE_SIZE - 1) / 1484 nrptrs = min(DIV_ROUND_UP(iov_iter_count(i), PAGE_CACHE_SIZE),
1485 PAGE_CACHE_SIZE, PAGE_CACHE_SIZE / 1485 PAGE_CACHE_SIZE / (sizeof(struct page *)));
1486 (sizeof(struct page *)));
1487 nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied); 1486 nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied);
1488 nrptrs = max(nrptrs, 8); 1487 nrptrs = max(nrptrs, 8);
1489 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL); 1488 pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
@@ -1497,8 +1496,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1497 size_t write_bytes = min(iov_iter_count(i), 1496 size_t write_bytes = min(iov_iter_count(i),
1498 nrptrs * (size_t)PAGE_CACHE_SIZE - 1497 nrptrs * (size_t)PAGE_CACHE_SIZE -
1499 offset); 1498 offset);
1500 size_t num_pages = (write_bytes + offset + 1499 size_t num_pages = DIV_ROUND_UP(write_bytes + offset,
1501 PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 1500 PAGE_CACHE_SIZE);
1502 size_t reserve_bytes; 1501 size_t reserve_bytes;
1503 size_t dirty_pages; 1502 size_t dirty_pages;
1504 size_t copied; 1503 size_t copied;
@@ -1526,9 +1525,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1526 * our prealloc extent may be smaller than 1525 * our prealloc extent may be smaller than
1527 * write_bytes, so scale down. 1526 * write_bytes, so scale down.
1528 */ 1527 */
1529 num_pages = (write_bytes + offset + 1528 num_pages = DIV_ROUND_UP(write_bytes + offset,
1530 PAGE_CACHE_SIZE - 1) >> 1529 PAGE_CACHE_SIZE);
1531 PAGE_CACHE_SHIFT;
1532 reserve_bytes = num_pages << PAGE_CACHE_SHIFT; 1530 reserve_bytes = num_pages << PAGE_CACHE_SHIFT;
1533 ret = 0; 1531 ret = 0;
1534 } else { 1532 } else {
@@ -1590,9 +1588,8 @@ again:
1590 dirty_pages = 0; 1588 dirty_pages = 0;
1591 } else { 1589 } else {
1592 force_page_uptodate = false; 1590 force_page_uptodate = false;
1593 dirty_pages = (copied + offset + 1591 dirty_pages = DIV_ROUND_UP(copied + offset,
1594 PAGE_CACHE_SIZE - 1) >> 1592 PAGE_CACHE_SIZE);
1595 PAGE_CACHE_SHIFT;
1596 } 1593 }
1597 1594
1598 /* 1595 /*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index f181c9afe5f4..2f0fe1028e51 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -279,8 +279,7 @@ static int io_ctl_init(struct io_ctl *io_ctl, struct inode *inode,
279 int num_pages; 279 int num_pages;
280 int check_crcs = 0; 280 int check_crcs = 0;
281 281
282 num_pages = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> 282 num_pages = DIV_ROUND_UP(i_size_read(inode), PAGE_CACHE_SIZE);
283 PAGE_CACHE_SHIFT;
284 283
285 if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID) 284 if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID)
286 check_crcs = 1; 285 check_crcs = 1;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index d6e10d60f8ad..8eecfcce56ed 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1335,8 +1335,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
1335 inode->i_mapping->writeback_index = i; 1335 inode->i_mapping->writeback_index = i;
1336 1336
1337 while (i <= last_index && defrag_count < max_to_defrag && 1337 while (i <= last_index && defrag_count < max_to_defrag &&
1338 (i < (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> 1338 (i < DIV_ROUND_UP(i_size_read(inode), PAGE_CACHE_SIZE))) {
1339 PAGE_CACHE_SHIFT)) {
1340 /* 1339 /*
1341 * make sure we stop running if someone unmounts 1340 * make sure we stop running if someone unmounts
1342 * the FS 1341 * the FS
@@ -1359,7 +1358,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
1359 * the should_defrag function tells us how much to skip 1358 * the should_defrag function tells us how much to skip
1360 * bump our counter by the suggested amount 1359 * bump our counter by the suggested amount
1361 */ 1360 */
1362 next = (skip + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 1361 next = DIV_ROUND_UP(skip, PAGE_CACHE_SIZE);
1363 i = max(i + 1, next); 1362 i = max(i + 1, next);
1364 continue; 1363 continue;
1365 } 1364 }
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index dfad8514f0da..78285f30909e 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -266,8 +266,7 @@ static int lzo_decompress_biovec(struct list_head *ws,
266 char *data_in; 266 char *data_in;
267 unsigned long page_in_index = 0; 267 unsigned long page_in_index = 0;
268 unsigned long page_out_index = 0; 268 unsigned long page_out_index = 0;
269 unsigned long total_pages_in = (srclen + PAGE_CACHE_SIZE - 1) / 269 unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_CACHE_SIZE);
270 PAGE_CACHE_SIZE;
271 unsigned long buf_start; 270 unsigned long buf_start;
272 unsigned long buf_offset = 0; 271 unsigned long buf_offset = 0;
273 unsigned long bytes; 272 unsigned long bytes;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 0a6b6e4bcbb9..6a41631cb959 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -912,7 +912,7 @@ static struct page *page_in_rbio(struct btrfs_raid_bio *rbio,
912static unsigned long rbio_nr_pages(unsigned long stripe_len, int nr_stripes) 912static unsigned long rbio_nr_pages(unsigned long stripe_len, int nr_stripes)
913{ 913{
914 unsigned long nr = stripe_len * nr_stripes; 914 unsigned long nr = stripe_len * nr_stripes;
915 return (nr + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 915 return DIV_ROUND_UP(nr, PAGE_CACHE_SIZE);
916} 916}
917 917
918/* 918/*
@@ -1442,7 +1442,7 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
1442 struct btrfs_bio *bbio = rbio->bbio; 1442 struct btrfs_bio *bbio = rbio->bbio;
1443 struct bio_list bio_list; 1443 struct bio_list bio_list;
1444 int ret; 1444 int ret;
1445 int nr_pages = (rbio->stripe_len + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 1445 int nr_pages = DIV_ROUND_UP(rbio->stripe_len, PAGE_CACHE_SIZE);
1446 int pagenr; 1446 int pagenr;
1447 int stripe; 1447 int stripe;
1448 struct bio *bio; 1448 struct bio *bio;
@@ -1725,7 +1725,7 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
1725 int pagenr, stripe; 1725 int pagenr, stripe;
1726 void **pointers; 1726 void **pointers;
1727 int faila = -1, failb = -1; 1727 int faila = -1, failb = -1;
1728 int nr_pages = (rbio->stripe_len + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 1728 int nr_pages = DIV_ROUND_UP(rbio->stripe_len, PAGE_CACHE_SIZE);
1729 struct page *page; 1729 struct page *page;
1730 int err; 1730 int err;
1731 int i; 1731 int i;
@@ -1940,7 +1940,7 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio)
1940 struct btrfs_bio *bbio = rbio->bbio; 1940 struct btrfs_bio *bbio = rbio->bbio;
1941 struct bio_list bio_list; 1941 struct bio_list bio_list;
1942 int ret; 1942 int ret;
1943 int nr_pages = (rbio->stripe_len + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 1943 int nr_pages = DIV_ROUND_UP(rbio->stripe_len, PAGE_CACHE_SIZE);
1944 int pagenr; 1944 int pagenr;
1945 int stripe; 1945 int stripe;
1946 struct bio *bio; 1946 struct bio *bio;
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index b67d8fc81277..77a0e5dba818 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -225,8 +225,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in,
225 size_t total_out = 0; 225 size_t total_out = 0;
226 unsigned long page_in_index = 0; 226 unsigned long page_in_index = 0;
227 unsigned long page_out_index = 0; 227 unsigned long page_out_index = 0;
228 unsigned long total_pages_in = (srclen + PAGE_CACHE_SIZE - 1) / 228 unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_CACHE_SIZE);
229 PAGE_CACHE_SIZE;
230 unsigned long buf_start; 229 unsigned long buf_start;
231 unsigned long pg_offset; 230 unsigned long pg_offset;
232 231