btrfs: switch extent_state state to unsigned
Currently there's a 4B hole in the structure between refs and state and there are only 16 bits used so we can make it unsigned. This will get a better packing and may save some stack space for local variables. The size of extent_state gets reduced by 8B and there are usually a lot of slab objects. struct extent_state { u64 start; /* 0 8 */ u64 end; /* 8 8 */ struct rb_node rb_node; /* 16 24 */ wait_queue_head_t wq; /* 40 24 */ /* --- cacheline 1 boundary (64 bytes) --- */ atomic_t refs; /* 64 4 */ /* XXX 4 bytes hole, try to pack */ long unsigned int state; /* 72 8 */ u64 private; /* 80 8 */ /* size: 88, cachelines: 2, members: 7 */ /* sum members: 84, holes: 1, sum holes: 4 */ /* last cacheline: 24 bytes */ }; Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
This commit is contained in:
parent
5efa0490cc
commit
9ee49a047d
4 changed files with 55 additions and 55 deletions
|
@ -64,7 +64,7 @@ void btrfs_leak_debug_check(void)
|
|||
|
||||
while (!list_empty(&states)) {
|
||||
state = list_entry(states.next, struct extent_state, leak_list);
|
||||
pr_err("BTRFS: state leak: start %llu end %llu state %lu in tree %d refs %d\n",
|
||||
pr_err("BTRFS: state leak: start %llu end %llu state %u in tree %d refs %d\n",
|
||||
state->start, state->end, state->state,
|
||||
extent_state_in_tree(state),
|
||||
atomic_read(&state->refs));
|
||||
|
@ -396,21 +396,21 @@ static void merge_state(struct extent_io_tree *tree,
|
|||
}
|
||||
|
||||
static void set_state_cb(struct extent_io_tree *tree,
|
||||
struct extent_state *state, unsigned long *bits)
|
||||
struct extent_state *state, unsigned *bits)
|
||||
{
|
||||
if (tree->ops && tree->ops->set_bit_hook)
|
||||
tree->ops->set_bit_hook(tree->mapping->host, state, bits);
|
||||
}
|
||||
|
||||
static void clear_state_cb(struct extent_io_tree *tree,
|
||||
struct extent_state *state, unsigned long *bits)
|
||||
struct extent_state *state, unsigned *bits)
|
||||
{
|
||||
if (tree->ops && tree->ops->clear_bit_hook)
|
||||
tree->ops->clear_bit_hook(tree->mapping->host, state, bits);
|
||||
}
|
||||
|
||||
static void set_state_bits(struct extent_io_tree *tree,
|
||||
struct extent_state *state, unsigned long *bits);
|
||||
struct extent_state *state, unsigned *bits);
|
||||
|
||||
/*
|
||||
* insert an extent_state struct into the tree. 'bits' are set on the
|
||||
|
@ -426,7 +426,7 @@ static int insert_state(struct extent_io_tree *tree,
|
|||
struct extent_state *state, u64 start, u64 end,
|
||||
struct rb_node ***p,
|
||||
struct rb_node **parent,
|
||||
unsigned long *bits)
|
||||
unsigned *bits)
|
||||
{
|
||||
struct rb_node *node;
|
||||
|
||||
|
@ -511,10 +511,10 @@ static struct extent_state *next_state(struct extent_state *state)
|
|||
*/
|
||||
static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
|
||||
struct extent_state *state,
|
||||
unsigned long *bits, int wake)
|
||||
unsigned *bits, int wake)
|
||||
{
|
||||
struct extent_state *next;
|
||||
unsigned long bits_to_clear = *bits & ~EXTENT_CTLBITS;
|
||||
unsigned bits_to_clear = *bits & ~EXTENT_CTLBITS;
|
||||
|
||||
if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) {
|
||||
u64 range = state->end - state->start + 1;
|
||||
|
@ -570,7 +570,7 @@ static void extent_io_tree_panic(struct extent_io_tree *tree, int err)
|
|||
* This takes the tree lock, and returns 0 on success and < 0 on error.
|
||||
*/
|
||||
int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, int wake, int delete,
|
||||
unsigned bits, int wake, int delete,
|
||||
struct extent_state **cached_state,
|
||||
gfp_t mask)
|
||||
{
|
||||
|
@ -789,9 +789,9 @@ static void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
|||
|
||||
static void set_state_bits(struct extent_io_tree *tree,
|
||||
struct extent_state *state,
|
||||
unsigned long *bits)
|
||||
unsigned *bits)
|
||||
{
|
||||
unsigned long bits_to_set = *bits & ~EXTENT_CTLBITS;
|
||||
unsigned bits_to_set = *bits & ~EXTENT_CTLBITS;
|
||||
|
||||
set_state_cb(tree, state, bits);
|
||||
if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
|
||||
|
@ -803,7 +803,7 @@ static void set_state_bits(struct extent_io_tree *tree,
|
|||
|
||||
static void cache_state_if_flags(struct extent_state *state,
|
||||
struct extent_state **cached_ptr,
|
||||
const u64 flags)
|
||||
unsigned flags)
|
||||
{
|
||||
if (cached_ptr && !(*cached_ptr)) {
|
||||
if (!flags || (state->state & flags)) {
|
||||
|
@ -833,7 +833,7 @@ static void cache_state(struct extent_state *state,
|
|||
|
||||
static int __must_check
|
||||
__set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, unsigned long exclusive_bits,
|
||||
unsigned bits, unsigned exclusive_bits,
|
||||
u64 *failed_start, struct extent_state **cached_state,
|
||||
gfp_t mask)
|
||||
{
|
||||
|
@ -1034,7 +1034,7 @@ __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
|||
}
|
||||
|
||||
int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, u64 * failed_start,
|
||||
unsigned bits, u64 * failed_start,
|
||||
struct extent_state **cached_state, gfp_t mask)
|
||||
{
|
||||
return __set_extent_bit(tree, start, end, bits, 0, failed_start,
|
||||
|
@ -1060,7 +1060,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
|||
* boundary bits like LOCK.
|
||||
*/
|
||||
int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, unsigned long clear_bits,
|
||||
unsigned bits, unsigned clear_bits,
|
||||
struct extent_state **cached_state, gfp_t mask)
|
||||
{
|
||||
struct extent_state *state;
|
||||
|
@ -1268,14 +1268,14 @@ int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
|
|||
}
|
||||
|
||||
int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, gfp_t mask)
|
||||
unsigned bits, gfp_t mask)
|
||||
{
|
||||
return set_extent_bit(tree, start, end, bits, NULL,
|
||||
NULL, mask);
|
||||
}
|
||||
|
||||
int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, gfp_t mask)
|
||||
unsigned bits, gfp_t mask)
|
||||
{
|
||||
return clear_extent_bit(tree, start, end, bits, 0, 0, NULL, mask);
|
||||
}
|
||||
|
@ -1330,10 +1330,11 @@ int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
|
|||
* us if waiting is desired.
|
||||
*/
|
||||
int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, struct extent_state **cached_state)
|
||||
unsigned bits, struct extent_state **cached_state)
|
||||
{
|
||||
int err;
|
||||
u64 failed_start;
|
||||
|
||||
while (1) {
|
||||
err = __set_extent_bit(tree, start, end, EXTENT_LOCKED | bits,
|
||||
EXTENT_LOCKED, &failed_start,
|
||||
|
@ -1440,7 +1441,7 @@ static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)
|
|||
*/
|
||||
static struct extent_state *
|
||||
find_first_extent_bit_state(struct extent_io_tree *tree,
|
||||
u64 start, unsigned long bits)
|
||||
u64 start, unsigned bits)
|
||||
{
|
||||
struct rb_node *node;
|
||||
struct extent_state *state;
|
||||
|
@ -1474,7 +1475,7 @@ find_first_extent_bit_state(struct extent_io_tree *tree,
|
|||
* If nothing was found, 1 is returned. If found something, return 0.
|
||||
*/
|
||||
int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
|
||||
u64 *start_ret, u64 *end_ret, unsigned long bits,
|
||||
u64 *start_ret, u64 *end_ret, unsigned bits,
|
||||
struct extent_state **cached_state)
|
||||
{
|
||||
struct extent_state *state;
|
||||
|
@ -1753,7 +1754,7 @@ STATIC u64 find_lock_delalloc_range(struct inode *inode,
|
|||
|
||||
int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
|
||||
struct page *locked_page,
|
||||
unsigned long clear_bits,
|
||||
unsigned clear_bits,
|
||||
unsigned long page_ops)
|
||||
{
|
||||
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
|
||||
|
@ -1810,7 +1811,7 @@ int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
|
|||
*/
|
||||
u64 count_range_bits(struct extent_io_tree *tree,
|
||||
u64 *start, u64 search_end, u64 max_bytes,
|
||||
unsigned long bits, int contig)
|
||||
unsigned bits, int contig)
|
||||
{
|
||||
struct rb_node *node;
|
||||
struct extent_state *state;
|
||||
|
@ -1928,7 +1929,7 @@ int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private)
|
|||
* range is found set.
|
||||
*/
|
||||
int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, int filled, struct extent_state *cached)
|
||||
unsigned bits, int filled, struct extent_state *cached)
|
||||
{
|
||||
struct extent_state *state = NULL;
|
||||
struct rb_node *node;
|
||||
|
|
|
@ -4,22 +4,22 @@
|
|||
#include <linux/rbtree.h>
|
||||
|
||||
/* bits for the extent state */
|
||||
#define EXTENT_DIRTY 1
|
||||
#define EXTENT_WRITEBACK (1 << 1)
|
||||
#define EXTENT_UPTODATE (1 << 2)
|
||||
#define EXTENT_LOCKED (1 << 3)
|
||||
#define EXTENT_NEW (1 << 4)
|
||||
#define EXTENT_DELALLOC (1 << 5)
|
||||
#define EXTENT_DEFRAG (1 << 6)
|
||||
#define EXTENT_BOUNDARY (1 << 9)
|
||||
#define EXTENT_NODATASUM (1 << 10)
|
||||
#define EXTENT_DO_ACCOUNTING (1 << 11)
|
||||
#define EXTENT_FIRST_DELALLOC (1 << 12)
|
||||
#define EXTENT_NEED_WAIT (1 << 13)
|
||||
#define EXTENT_DAMAGED (1 << 14)
|
||||
#define EXTENT_NORESERVE (1 << 15)
|
||||
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
|
||||
#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
|
||||
#define EXTENT_DIRTY (1U << 0)
|
||||
#define EXTENT_WRITEBACK (1U << 1)
|
||||
#define EXTENT_UPTODATE (1U << 2)
|
||||
#define EXTENT_LOCKED (1U << 3)
|
||||
#define EXTENT_NEW (1U << 4)
|
||||
#define EXTENT_DELALLOC (1U << 5)
|
||||
#define EXTENT_DEFRAG (1U << 6)
|
||||
#define EXTENT_BOUNDARY (1U << 9)
|
||||
#define EXTENT_NODATASUM (1U << 10)
|
||||
#define EXTENT_DO_ACCOUNTING (1U << 11)
|
||||
#define EXTENT_FIRST_DELALLOC (1U << 12)
|
||||
#define EXTENT_NEED_WAIT (1U << 13)
|
||||
#define EXTENT_DAMAGED (1U << 14)
|
||||
#define EXTENT_NORESERVE (1U << 15)
|
||||
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
|
||||
#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
|
||||
|
||||
/*
|
||||
* flags for bio submission. The high bits indicate the compression
|
||||
|
@ -81,9 +81,9 @@ struct extent_io_ops {
|
|||
int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
|
||||
struct extent_state *state, int uptodate);
|
||||
void (*set_bit_hook)(struct inode *inode, struct extent_state *state,
|
||||
unsigned long *bits);
|
||||
unsigned *bits);
|
||||
void (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
|
||||
unsigned long *bits);
|
||||
unsigned *bits);
|
||||
void (*merge_extent_hook)(struct inode *inode,
|
||||
struct extent_state *new,
|
||||
struct extent_state *other);
|
||||
|
@ -108,7 +108,7 @@ struct extent_state {
|
|||
/* ADD NEW ELEMENTS AFTER THIS */
|
||||
wait_queue_head_t wq;
|
||||
atomic_t refs;
|
||||
unsigned long state;
|
||||
unsigned state;
|
||||
|
||||
/* for use by the FS */
|
||||
u64 private;
|
||||
|
@ -188,7 +188,7 @@ int try_release_extent_mapping(struct extent_map_tree *map,
|
|||
int try_release_extent_buffer(struct page *page);
|
||||
int lock_extent(struct extent_io_tree *tree, u64 start, u64 end);
|
||||
int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, struct extent_state **cached);
|
||||
unsigned bits, struct extent_state **cached);
|
||||
int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end);
|
||||
int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
struct extent_state **cached, gfp_t mask);
|
||||
|
@ -202,21 +202,21 @@ void extent_io_exit(void);
|
|||
|
||||
u64 count_range_bits(struct extent_io_tree *tree,
|
||||
u64 *start, u64 search_end,
|
||||
u64 max_bytes, unsigned long bits, int contig);
|
||||
u64 max_bytes, unsigned bits, int contig);
|
||||
|
||||
void free_extent_state(struct extent_state *state);
|
||||
int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, int filled,
|
||||
unsigned bits, int filled,
|
||||
struct extent_state *cached_state);
|
||||
int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, gfp_t mask);
|
||||
unsigned bits, gfp_t mask);
|
||||
int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, int wake, int delete,
|
||||
unsigned bits, int wake, int delete,
|
||||
struct extent_state **cached, gfp_t mask);
|
||||
int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, gfp_t mask);
|
||||
unsigned bits, gfp_t mask);
|
||||
int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, u64 *failed_start,
|
||||
unsigned bits, u64 *failed_start,
|
||||
struct extent_state **cached_state, gfp_t mask);
|
||||
int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
struct extent_state **cached_state, gfp_t mask);
|
||||
|
@ -229,14 +229,14 @@ int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
|
|||
int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
gfp_t mask);
|
||||
int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
unsigned long bits, unsigned long clear_bits,
|
||||
unsigned bits, unsigned clear_bits,
|
||||
struct extent_state **cached_state, gfp_t mask);
|
||||
int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
struct extent_state **cached_state, gfp_t mask);
|
||||
int set_extent_defrag(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
struct extent_state **cached_state, gfp_t mask);
|
||||
int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
|
||||
u64 *start_ret, u64 *end_ret, unsigned long bits,
|
||||
u64 *start_ret, u64 *end_ret, unsigned bits,
|
||||
struct extent_state **cached_state);
|
||||
int extent_invalidatepage(struct extent_io_tree *tree,
|
||||
struct page *page, unsigned long offset);
|
||||
|
@ -323,7 +323,7 @@ int extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end);
|
|||
int extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end);
|
||||
int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
|
||||
struct page *locked_page,
|
||||
unsigned long bits_to_clear,
|
||||
unsigned bits_to_clear,
|
||||
unsigned long page_ops);
|
||||
struct bio *
|
||||
btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
|
||||
|
|
|
@ -1604,7 +1604,7 @@ static void btrfs_del_delalloc_inode(struct btrfs_root *root,
|
|||
* have pending delalloc work to be done.
|
||||
*/
|
||||
static void btrfs_set_bit_hook(struct inode *inode,
|
||||
struct extent_state *state, unsigned long *bits)
|
||||
struct extent_state *state, unsigned *bits)
|
||||
{
|
||||
|
||||
if ((*bits & EXTENT_DEFRAG) && !(*bits & EXTENT_DELALLOC))
|
||||
|
@ -1645,7 +1645,7 @@ static void btrfs_set_bit_hook(struct inode *inode,
|
|||
*/
|
||||
static void btrfs_clear_bit_hook(struct inode *inode,
|
||||
struct extent_state *state,
|
||||
unsigned long *bits)
|
||||
unsigned *bits)
|
||||
{
|
||||
u64 len = state->end + 1 - state->start;
|
||||
|
||||
|
|
|
@ -258,8 +258,7 @@ static int test_find_delalloc(void)
|
|||
}
|
||||
ret = 0;
|
||||
out_bits:
|
||||
clear_extent_bits(&tmp, 0, total_dirty - 1,
|
||||
(unsigned long)-1, GFP_NOFS);
|
||||
clear_extent_bits(&tmp, 0, total_dirty - 1, (unsigned)-1, GFP_NOFS);
|
||||
out:
|
||||
if (locked_page)
|
||||
page_cache_release(locked_page);
|
||||
|
|
Loading…
Reference in a new issue