]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
btrfs: use DIV_ROUND_UP instead of open-coded variants
authorDavid Sterba <dsterba@suse.cz>
Wed, 4 Jun 2014 23:59:57 +0000 (01:59 +0200)
committerChris Mason <clm@fb.com>
Wed, 17 Sep 2014 20:37:17 +0000 (13:37 -0700)
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>
fs/btrfs/check-integrity.c
fs/btrfs/compression.c
fs/btrfs/file.c
fs/btrfs/free-space-cache.c
fs/btrfs/ioctl.c
fs/btrfs/lzo.c
fs/btrfs/raid56.c
fs/btrfs/zlib.c

index d0690da3b1503a985ca38ae38ec5c0ddb91fcd30..e0033c843ce7b4f1eb9f2a6707a7a7859f29fd3e 100644 (file)
@@ -1251,8 +1251,7 @@ static void btrfsic_read_from_block_data(
 
        while (len > 0) {
                cur = min(len, ((size_t)PAGE_CACHE_SIZE - offset_in_page));
-               BUG_ON(i >= (block_ctx->len + PAGE_CACHE_SIZE - 1) >>
-                           PAGE_CACHE_SHIFT);
+               BUG_ON(i >= DIV_ROUND_UP(block_ctx->len, PAGE_CACHE_SIZE));
                kaddr = block_ctx->datav[i];
                memcpy(dst, kaddr + offset_in_page, cur);
 
index 1daea0b47187b58db65dde86411e88578473fcf4..eeee13842cd0937b7600e27615fa80398bdcc37c 100644 (file)
@@ -91,8 +91,7 @@ static inline int compressed_bio_size(struct btrfs_root *root,
        u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
 
        return sizeof(struct compressed_bio) +
-               ((disk_size + root->sectorsize - 1) / root->sectorsize) *
-               csum_size;
+               (DIV_ROUND_UP(disk_size, root->sectorsize)) * csum_size;
 }
 
 static struct bio *compressed_bio_alloc(struct block_device *bdev,
@@ -615,8 +614,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
        cb->compress_type = extent_compress_type(bio_flags);
        cb->orig_bio = bio;
 
-       nr_pages = (compressed_len + PAGE_CACHE_SIZE - 1) /
-                                PAGE_CACHE_SIZE;
+       nr_pages = DIV_ROUND_UP(compressed_len, PAGE_CACHE_SIZE);
        cb->compressed_pages = kzalloc(sizeof(struct page *) * nr_pages,
                                       GFP_NOFS);
        if (!cb->compressed_pages)
@@ -686,8 +684,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
                                                        comp_bio, sums);
                                BUG_ON(ret); /* -ENOMEM */
                        }
-                       sums += (comp_bio->bi_iter.bi_size +
-                                root->sectorsize - 1) / root->sectorsize;
+                       sums += DIV_ROUND_UP(comp_bio->bi_iter.bi_size,
+                                            root->sectorsize);
 
                        ret = btrfs_map_bio(root, READ, comp_bio,
                                            mirror_num, 0);
index 033f04bac85ba089308cbdc49f3686884ff6a55f..2287545c5498b180ba846bea2b97464e4a5ac052 100644 (file)
@@ -1481,9 +1481,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
        bool force_page_uptodate = false;
        bool need_unlock;
 
-       nrptrs = min((iov_iter_count(i) + PAGE_CACHE_SIZE - 1) /
-                    PAGE_CACHE_SIZE, PAGE_CACHE_SIZE /
-                    (sizeof(struct page *)));
+       nrptrs = min(DIV_ROUND_UP(iov_iter_count(i), PAGE_CACHE_SIZE),
+                       PAGE_CACHE_SIZE / (sizeof(struct page *)));
        nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied);
        nrptrs = max(nrptrs, 8);
        pages = kmalloc(nrptrs * sizeof(struct page *), GFP_KERNEL);
@@ -1497,8 +1496,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
                size_t write_bytes = min(iov_iter_count(i),
                                         nrptrs * (size_t)PAGE_CACHE_SIZE -
                                         offset);
-               size_t num_pages = (write_bytes + offset +
-                                   PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+               size_t num_pages = DIV_ROUND_UP(write_bytes + offset,
+                                               PAGE_CACHE_SIZE);
                size_t reserve_bytes;
                size_t dirty_pages;
                size_t copied;
@@ -1526,9 +1525,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
                                 * our prealloc extent may be smaller than
                                 * write_bytes, so scale down.
                                 */
-                               num_pages = (write_bytes + offset +
-                                            PAGE_CACHE_SIZE - 1) >>
-                                       PAGE_CACHE_SHIFT;
+                               num_pages = DIV_ROUND_UP(write_bytes + offset,
+                                                        PAGE_CACHE_SIZE);
                                reserve_bytes = num_pages << PAGE_CACHE_SHIFT;
                                ret = 0;
                        } else {
@@ -1590,9 +1588,8 @@ again:
                        dirty_pages = 0;
                } else {
                        force_page_uptodate = false;
-                       dirty_pages = (copied + offset +
-                                      PAGE_CACHE_SIZE - 1) >>
-                                      PAGE_CACHE_SHIFT;
+                       dirty_pages = DIV_ROUND_UP(copied + offset,
+                                                  PAGE_CACHE_SIZE);
                }
 
                /*
index f181c9afe5f4244e8adf6045ddc3f4d712430f0e..2f0fe1028e51f3170fd7affe63b6f8797dfd0131 100644 (file)
@@ -279,8 +279,7 @@ static int io_ctl_init(struct io_ctl *io_ctl, struct inode *inode,
        int num_pages;
        int check_crcs = 0;
 
-       num_pages = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
-                   PAGE_CACHE_SHIFT;
+       num_pages = DIV_ROUND_UP(i_size_read(inode), PAGE_CACHE_SIZE);
 
        if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID)
                check_crcs = 1;
index d6e10d60f8ad884f6500bdca46bc4ccbe6223250..8eecfcce56ed43a8d4b57fc6878c29313cfce1e8 100644 (file)
@@ -1335,8 +1335,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                inode->i_mapping->writeback_index = i;
 
        while (i <= last_index && defrag_count < max_to_defrag &&
-              (i < (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
-               PAGE_CACHE_SHIFT)) {
+              (i < DIV_ROUND_UP(i_size_read(inode), PAGE_CACHE_SIZE))) {
                /*
                 * make sure we stop running if someone unmounts
                 * the FS
@@ -1359,7 +1358,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                         * the should_defrag function tells us how much to skip
                         * bump our counter by the suggested amount
                         */
-                       next = (skip + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+                       next = DIV_ROUND_UP(skip, PAGE_CACHE_SIZE);
                        i = max(i + 1, next);
                        continue;
                }
index dfad8514f0daa5054378ebae0d739c9a89dd3963..78285f30909edd09f19cc6eb48985d47eed3c565 100644 (file)
@@ -266,8 +266,7 @@ static int lzo_decompress_biovec(struct list_head *ws,
        char *data_in;
        unsigned long page_in_index = 0;
        unsigned long page_out_index = 0;
-       unsigned long total_pages_in = (srclen + PAGE_CACHE_SIZE - 1) /
-                                       PAGE_CACHE_SIZE;
+       unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_CACHE_SIZE);
        unsigned long buf_start;
        unsigned long buf_offset = 0;
        unsigned long bytes;
index 0a6b6e4bcbb97a8af56ad6a58aef9f514c3b1132..6a41631cb95988c89e23ffdcb6bdc2466c065b2d 100644 (file)
@@ -912,7 +912,7 @@ static struct page *page_in_rbio(struct btrfs_raid_bio *rbio,
 static unsigned long rbio_nr_pages(unsigned long stripe_len, int nr_stripes)
 {
        unsigned long nr = stripe_len * nr_stripes;
-       return (nr + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+       return DIV_ROUND_UP(nr, PAGE_CACHE_SIZE);
 }
 
 /*
@@ -1442,7 +1442,7 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
        struct btrfs_bio *bbio = rbio->bbio;
        struct bio_list bio_list;
        int ret;
-       int nr_pages = (rbio->stripe_len + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+       int nr_pages = DIV_ROUND_UP(rbio->stripe_len, PAGE_CACHE_SIZE);
        int pagenr;
        int stripe;
        struct bio *bio;
@@ -1725,7 +1725,7 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
        int pagenr, stripe;
        void **pointers;
        int faila = -1, failb = -1;
-       int nr_pages = (rbio->stripe_len + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+       int nr_pages = DIV_ROUND_UP(rbio->stripe_len, PAGE_CACHE_SIZE);
        struct page *page;
        int err;
        int i;
@@ -1940,7 +1940,7 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio)
        struct btrfs_bio *bbio = rbio->bbio;
        struct bio_list bio_list;
        int ret;
-       int nr_pages = (rbio->stripe_len + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+       int nr_pages = DIV_ROUND_UP(rbio->stripe_len, PAGE_CACHE_SIZE);
        int pagenr;
        int stripe;
        struct bio *bio;
index b67d8fc81277675edb3fdb7beb9b8c4db2c919ad..77a0e5dba81837685db05e589006342f5188a00a 100644 (file)
@@ -225,8 +225,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in,
        size_t total_out = 0;
        unsigned long page_in_index = 0;
        unsigned long page_out_index = 0;
-       unsigned long total_pages_in = (srclen + PAGE_CACHE_SIZE - 1) /
-                                       PAGE_CACHE_SIZE;
+       unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_CACHE_SIZE);
        unsigned long buf_start;
        unsigned long pg_offset;