Skip to content

Commit

Permalink
Btrfs: use linux/sizes.h to represent constants
Browse files Browse the repository at this point in the history
We use many constants to represent size and offset value.  And to make
code readable we use '256 * 1024 * 1024' instead of '268435456' to
represent '256MB'.  However we can make far more readable with 'SZ_256MB'
which is defined in the 'linux/sizes.h'.

So this patch replaces 'xxx * 1024 * 1024' kind of expression with
single 'SZ_xxxMB' if 'xxx' is a power of 2 then 'xxx * SZ_1M' if 'xxx' is
not a power of 2. And I haven't touched to '4096' & '8192' because it's
more intuitive than 'SZ_4KB' & 'SZ_8KB'.

Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Byongho Lee authored and David Sterba committed Jan 7, 2016
1 parent 7928d67 commit ee22184
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 177 deletions.
2 changes: 1 addition & 1 deletion fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans,
return 0;
}

search_start = buf->start & ~((u64)(1024 * 1024 * 1024) - 1);
search_start = buf->start & ~((u64)SZ_1G - 1);

if (parent)
btrfs_set_lock_blocking(parent);
Expand Down
5 changes: 3 additions & 2 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <linux/btrfs.h>
#include <linux/workqueue.h>
#include <linux/security.h>
#include <linux/sizes.h>
#include "extent_io.h"
#include "extent_map.h"
#include "async-thread.h"
Expand Down Expand Up @@ -196,9 +197,9 @@ static int btrfs_csum_sizes[] = { 4 };
/* ioprio of readahead is set to idle */
#define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0))

#define BTRFS_DIRTY_METADATA_THRESH (32 * 1024 * 1024)
#define BTRFS_DIRTY_METADATA_THRESH SZ_32M

#define BTRFS_MAX_EXTENT_SIZE (128 * 1024 * 1024)
#define BTRFS_MAX_EXTENT_SIZE SZ_128M

/*
* The key defines the order in the tree, and so it also defines (optimal)
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2809,7 +2809,7 @@ int open_ctree(struct super_block *sb,

fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super);
fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
4 * 1024 * 1024 / PAGE_CACHE_SIZE);
SZ_4M / PAGE_CACHE_SIZE);

tree_root->nodesize = nodesize;
tree_root->sectorsize = sectorsize;
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef __DISKIO__
#define __DISKIO__

#define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
#define BTRFS_SUPER_INFO_OFFSET SZ_64K
#define BTRFS_SUPER_INFO_SIZE 4096

#define BTRFS_SUPER_MIRROR_MAX 3
Expand All @@ -35,7 +35,7 @@ enum btrfs_wq_endio_type {

static inline u64 btrfs_sb_offset(int mirror)
{
u64 start = 16 * 1024;
u64 start = SZ_16K;
if (mirror)
return start << (BTRFS_SUPER_MIRROR_SHIFT * mirror);
return BTRFS_SUPER_INFO_OFFSET;
Expand Down
29 changes: 13 additions & 16 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ static noinline void caching_thread(struct btrfs_work *work)
else
last = key.objectid + key.offset;

if (total_found > (1024 * 1024 * 2)) {
if (total_found > SZ_2M) {
total_found = 0;
if (wakeup)
wake_up(&caching_ctl->wait);
Expand Down Expand Up @@ -3328,7 +3328,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
* If this block group is smaller than 100 megs don't bother caching the
* block group.
*/
if (block_group->key.offset < (100 * 1024 * 1024)) {
if (block_group->key.offset < (100 * SZ_1M)) {
spin_lock(&block_group->lock);
block_group->disk_cache_state = BTRFS_DC_WRITTEN;
spin_unlock(&block_group->lock);
Expand Down Expand Up @@ -3428,7 +3428,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
* taking up quite a bit since it's not folded into the other space
* cache.
*/
num_pages = div_u64(block_group->key.offset, 256 * 1024 * 1024);
num_pages = div_u64(block_group->key.offset, SZ_256M);
if (!num_pages)
num_pages = 1;

Expand Down Expand Up @@ -4239,14 +4239,13 @@ static int should_alloc_chunk(struct btrfs_root *root,
*/
if (force == CHUNK_ALLOC_LIMITED) {
thresh = btrfs_super_total_bytes(root->fs_info->super_copy);
thresh = max_t(u64, 64 * 1024 * 1024,
div_factor_fine(thresh, 1));
thresh = max_t(u64, SZ_64M, div_factor_fine(thresh, 1));

if (num_bytes - num_allocated < thresh)
return 1;
}

if (num_allocated + 2 * 1024 * 1024 < div_factor(num_bytes, 8))
if (num_allocated + SZ_2M < div_factor(num_bytes, 8))
return 0;
return 1;
}
Expand Down Expand Up @@ -4446,7 +4445,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,
* transaction.
*/
if (trans->can_flush_pending_bgs &&
trans->chunk_bytes_reserved >= (2 * 1024 * 1024ull)) {
trans->chunk_bytes_reserved >= (u64)SZ_2M) {
btrfs_create_pending_block_groups(trans, trans->root);
btrfs_trans_release_chunk_metadata(trans);
}
Expand Down Expand Up @@ -4544,7 +4543,7 @@ static inline int calc_reclaim_items_nr(struct btrfs_root *root, u64 to_reclaim)
return nr;
}

#define EXTENT_SIZE_PER_ITEM (256 * 1024)
#define EXTENT_SIZE_PER_ITEM SZ_256K

/*
* shrink metadata reservation for delalloc
Expand Down Expand Up @@ -4749,8 +4748,7 @@ btrfs_calc_reclaim_metadata_size(struct btrfs_root *root,
u64 expected;
u64 to_reclaim;

to_reclaim = min_t(u64, num_online_cpus() * 1024 * 1024,
16 * 1024 * 1024);
to_reclaim = min_t(u64, num_online_cpus() * SZ_1M, SZ_16M);
spin_lock(&space_info->lock);
if (can_overcommit(root, space_info, to_reclaim,
BTRFS_RESERVE_FLUSH_ALL)) {
Expand All @@ -4761,8 +4759,7 @@ btrfs_calc_reclaim_metadata_size(struct btrfs_root *root,
used = space_info->bytes_used + space_info->bytes_reserved +
space_info->bytes_pinned + space_info->bytes_readonly +
space_info->bytes_may_use;
if (can_overcommit(root, space_info, 1024 * 1024,
BTRFS_RESERVE_FLUSH_ALL))
if (can_overcommit(root, space_info, SZ_1M, BTRFS_RESERVE_FLUSH_ALL))
expected = div_factor_fine(space_info->total_bytes, 95);
else
expected = div_factor_fine(space_info->total_bytes, 90);
Expand Down Expand Up @@ -5318,7 +5315,7 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
spin_lock(&sinfo->lock);
spin_lock(&block_rsv->lock);

block_rsv->size = min_t(u64, num_bytes, 512 * 1024 * 1024);
block_rsv->size = min_t(u64, num_bytes, SZ_512M);

num_bytes = sinfo->bytes_used + sinfo->bytes_pinned +
sinfo->bytes_reserved + sinfo->bytes_readonly +
Expand Down Expand Up @@ -6222,11 +6219,11 @@ fetch_cluster_info(struct btrfs_root *root, struct btrfs_space_info *space_info,
return ret;

if (ssd)
*empty_cluster = 2 * 1024 * 1024;
*empty_cluster = SZ_2M;
if (space_info->flags & BTRFS_BLOCK_GROUP_METADATA) {
ret = &root->fs_info->meta_alloc_cluster;
if (!ssd)
*empty_cluster = 64 * 1024;
*empty_cluster = SZ_64K;
} else if ((space_info->flags & BTRFS_BLOCK_GROUP_DATA) && ssd) {
ret = &root->fs_info->data_alloc_cluster;
}
Expand Down Expand Up @@ -9124,7 +9121,7 @@ static int inc_block_group_ro(struct btrfs_block_group_cache *cache, int force)
if ((sinfo->flags &
(BTRFS_BLOCK_GROUP_SYSTEM | BTRFS_BLOCK_GROUP_METADATA)) &&
!force)
min_allocable_bytes = 1 * 1024 * 1024;
min_allocable_bytes = SZ_1M;
else
min_allocable_bytes = 0;

Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4387,7 +4387,7 @@ int try_release_extent_mapping(struct extent_map_tree *map,
u64 end = start + PAGE_CACHE_SIZE - 1;

if (gfpflags_allow_blocking(mask) &&
page->mapping->host->i_size > 16 * 1024 * 1024) {
page->mapping->host->i_size > SZ_16M) {
u64 len;
while (start <= end) {
len = end - start + 1;
Expand Down
10 changes: 4 additions & 6 deletions fs/btrfs/free-space-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "volumes.h"

#define BITS_PER_BITMAP (PAGE_CACHE_SIZE * 8)
#define MAX_CACHE_BYTES_PER_GIG (32 * 1024)
#define MAX_CACHE_BYTES_PER_GIG SZ_32K

struct btrfs_trim_range {
u64 start;
Expand Down Expand Up @@ -1656,11 +1656,10 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
* at or below 32k, so we need to adjust how much memory we allow to be
* used by extent based free space tracking
*/
if (size < 1024 * 1024 * 1024)
if (size < SZ_1G)
max_bytes = MAX_CACHE_BYTES_PER_GIG;
else
max_bytes = MAX_CACHE_BYTES_PER_GIG *
div_u64(size, 1024 * 1024 * 1024);
max_bytes = MAX_CACHE_BYTES_PER_GIG * div_u64(size, SZ_1G);

/*
* we want to account for 1 more bitmap than what we have so we can make
Expand Down Expand Up @@ -2489,8 +2488,7 @@ void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group)
* track of free space, and if we pass 1/2 of that we want to
* start converting things over to using bitmaps
*/
ctl->extents_thresh = ((1024 * 32) / 2) /
sizeof(struct btrfs_free_space);
ctl->extents_thresh = (SZ_32K / 2) / sizeof(struct btrfs_free_space);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/inode-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void btrfs_unpin_free_ino(struct btrfs_root *root)
}
}

#define INIT_THRESHOLD (((1024 * 32) / 2) / sizeof(struct btrfs_free_space))
#define INIT_THRESHOLD ((SZ_32K / 2) / sizeof(struct btrfs_free_space))
#define INODES_PER_BITMAP (PAGE_CACHE_SIZE * 8)

/*
Expand Down
22 changes: 11 additions & 11 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,23 +414,23 @@ static noinline void compress_file_range(struct inode *inode,
unsigned long nr_pages_ret = 0;
unsigned long total_compressed = 0;
unsigned long total_in = 0;
unsigned long max_compressed = 128 * 1024;
unsigned long max_uncompressed = 128 * 1024;
unsigned long max_compressed = SZ_128K;
unsigned long max_uncompressed = SZ_128K;
int i;
int will_compress;
int compress_type = root->fs_info->compress_type;
int redirty = 0;

/* if this is a small write inside eof, kick off a defrag */
if ((end - start + 1) < 16 * 1024 &&
if ((end - start + 1) < SZ_16K &&
(start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
btrfs_add_inode_defrag(NULL, inode);

actual_end = min_t(u64, isize, end + 1);
again:
will_compress = 0;
nr_pages = (end >> PAGE_CACHE_SHIFT) - (start >> PAGE_CACHE_SHIFT) + 1;
nr_pages = min(nr_pages, (128 * 1024UL) / PAGE_CACHE_SIZE);
nr_pages = min_t(unsigned long, nr_pages, SZ_128K / PAGE_CACHE_SIZE);

/*
* we don't want to send crud past the end of i_size through
Expand Down Expand Up @@ -944,7 +944,7 @@ static noinline int cow_file_range(struct inode *inode,
disk_num_bytes = num_bytes;

/* if this is a small write inside eof, kick off defrag */
if (num_bytes < 64 * 1024 &&
if (num_bytes < SZ_64K &&
(start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
btrfs_add_inode_defrag(NULL, inode);

Expand Down Expand Up @@ -1107,7 +1107,7 @@ static noinline void async_cow_submit(struct btrfs_work *work)
* atomic_sub_return implies a barrier for waitqueue_active
*/
if (atomic_sub_return(nr_pages, &root->fs_info->async_delalloc_pages) <
5 * 1024 * 1024 &&
5 * SZ_1M &&
waitqueue_active(&root->fs_info->async_submit_wait))
wake_up(&root->fs_info->async_submit_wait);

Expand All @@ -1132,7 +1132,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
struct btrfs_root *root = BTRFS_I(inode)->root;
unsigned long nr_pages;
u64 cur_end;
int limit = 10 * 1024 * 1024;
int limit = 10 * SZ_1M;

clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED,
1, 0, NULL, GFP_NOFS);
Expand All @@ -1148,7 +1148,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
!btrfs_test_opt(root, FORCE_COMPRESS))
cur_end = end;
else
cur_end = min(end, start + 512 * 1024 - 1);
cur_end = min(end, start + SZ_512K - 1);

async_cow->end = cur_end;
INIT_LIST_HEAD(&async_cow->extents);
Expand Down Expand Up @@ -4348,7 +4348,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
* up a huge file in a single leaf. Most of the time that
* bytes_deleted is > 0, it will be huge by the time we get here
*/
if (be_nice && bytes_deleted > 32 * 1024 * 1024) {
if (be_nice && bytes_deleted > SZ_32M) {
if (btrfs_should_end_transaction(trans, root)) {
err = -EAGAIN;
goto error;
Expand Down Expand Up @@ -4591,7 +4591,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,

btrfs_free_path(path);

if (be_nice && bytes_deleted > 32 * 1024 * 1024) {
if (be_nice && bytes_deleted > SZ_32M) {
unsigned long updates = trans->delayed_ref_updates;
if (updates) {
trans->delayed_ref_updates = 0;
Expand Down Expand Up @@ -9757,7 +9757,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
}
}

cur_bytes = min(num_bytes, 256ULL * 1024 * 1024);
cur_bytes = min_t(u64, num_bytes, SZ_256M);
cur_bytes = max(cur_bytes, min_size);
/*
* If we are severely fragmented we could end up with really
Expand Down
23 changes: 11 additions & 12 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em)
if (!next || next->block_start >= EXTENT_MAP_LAST_BYTE)
ret = false;
else if ((em->block_start + em->block_len == next->block_start) &&
(em->block_len > 128 * 1024 && next->block_len > 128 * 1024))
(em->block_len > SZ_128K && next->block_len > SZ_128K))
ret = false;

free_extent_map(next);
Expand Down Expand Up @@ -1262,9 +1262,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
int defrag_count = 0;
int compress_type = BTRFS_COMPRESS_ZLIB;
u32 extent_thresh = range->extent_thresh;
unsigned long max_cluster = (256 * 1024) >> PAGE_CACHE_SHIFT;
unsigned long max_cluster = SZ_256K >> PAGE_CACHE_SHIFT;
unsigned long cluster = max_cluster;
u64 new_align = ~((u64)128 * 1024 - 1);
u64 new_align = ~((u64)SZ_128K - 1);
struct page **pages = NULL;

if (isize == 0)
Expand All @@ -1281,7 +1281,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
}

if (extent_thresh == 0)
extent_thresh = 256 * 1024;
extent_thresh = SZ_256K;

/*
* if we were not given a file, allocate a readahead
Expand Down Expand Up @@ -1313,7 +1313,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,

if (newer_than) {
ret = find_new_extents(root, inode, newer_than,
&newer_off, 64 * 1024);
&newer_off, SZ_64K);
if (!ret) {
range->start = newer_off;
/*
Expand Down Expand Up @@ -1403,9 +1403,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
newer_off = max(newer_off + 1,
(u64)i << PAGE_CACHE_SHIFT);

ret = find_new_extents(root, inode,
newer_than, &newer_off,
64 * 1024);
ret = find_new_extents(root, inode, newer_than,
&newer_off, SZ_64K);
if (!ret) {
range->start = newer_off;
i = (newer_off & new_align) >> PAGE_CACHE_SHIFT;
Expand Down Expand Up @@ -1571,7 +1570,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
new_size = old_size + new_size;
}

if (new_size < 256 * 1024 * 1024) {
if (new_size < SZ_256M) {
ret = -EINVAL;
goto out_free;
}
Expand Down Expand Up @@ -2160,7 +2159,7 @@ static noinline int btrfs_ioctl_tree_search_v2(struct file *file,
struct inode *inode;
int ret;
size_t buf_size;
const size_t buf_limit = 16 * 1024 * 1024;
const size_t buf_limit = SZ_16M;

if (!capable(CAP_SYS_ADMIN))
return -EPERM;
Expand Down Expand Up @@ -3096,7 +3095,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
return ret;
}

#define BTRFS_MAX_DEDUPE_LEN (16 * 1024 * 1024)
#define BTRFS_MAX_DEDUPE_LEN SZ_16M

static long btrfs_ioctl_file_extent_same(struct file *file,
struct btrfs_ioctl_same_args __user *argp)
Expand Down Expand Up @@ -4524,7 +4523,7 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_root *root,
goto out;
}

size = min_t(u32, loi->size, 64 * 1024);
size = min_t(u32, loi->size, SZ_64K);
inodes = init_data_container(size);
if (IS_ERR(inodes)) {
ret = PTR_ERR(inodes);
Expand Down
Loading

0 comments on commit ee22184

Please sign in to comment.