aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent_io.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-01-14 13:52:13 -0500
committerChris Mason <clm@fb.com>2015-01-21 21:02:04 -0500
commit9ee49a047dc53fd21808cbb7f3b6a3345463e834 (patch)
tree98710aa584c84501c00ecf2227138ff4f44d5396 /fs/btrfs/extent_io.c
parent5efa0490cc94aee06cd8d282683e22a8ce0a0026 (diff)
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>
Diffstat (limited to 'fs/btrfs/extent_io.c')
-rw-r--r--fs/btrfs/extent_io.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index c4ca90ab687e..65bd285ef361 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -64,7 +64,7 @@ void btrfs_leak_debug_check(void)
64 64
65 while (!list_empty(&states)) { 65 while (!list_empty(&states)) {
66 state = list_entry(states.next, struct extent_state, leak_list); 66 state = list_entry(states.next, struct extent_state, leak_list);
67 pr_err("BTRFS: state leak: start %llu end %llu state %lu in tree %d refs %d\n", 67 pr_err("BTRFS: state leak: start %llu end %llu state %u in tree %d refs %d\n",
68 state->start, state->end, state->state, 68 state->start, state->end, state->state,
69 extent_state_in_tree(state), 69 extent_state_in_tree(state),
70 atomic_read(&state->refs)); 70 atomic_read(&state->refs));
@@ -396,21 +396,21 @@ static void merge_state(struct extent_io_tree *tree,
396} 396}
397 397
398static void set_state_cb(struct extent_io_tree *tree, 398static void set_state_cb(struct extent_io_tree *tree,
399 struct extent_state *state, unsigned long *bits) 399 struct extent_state *state, unsigned *bits)
400{ 400{
401 if (tree->ops && tree->ops->set_bit_hook) 401 if (tree->ops && tree->ops->set_bit_hook)
402 tree->ops->set_bit_hook(tree->mapping->host, state, bits); 402 tree->ops->set_bit_hook(tree->mapping->host, state, bits);
403} 403}
404 404
405static void clear_state_cb(struct extent_io_tree *tree, 405static void clear_state_cb(struct extent_io_tree *tree,
406 struct extent_state *state, unsigned long *bits) 406 struct extent_state *state, unsigned *bits)
407{ 407{
408 if (tree->ops && tree->ops->clear_bit_hook) 408 if (tree->ops && tree->ops->clear_bit_hook)
409 tree->ops->clear_bit_hook(tree->mapping->host, state, bits); 409 tree->ops->clear_bit_hook(tree->mapping->host, state, bits);
410} 410}
411 411
412static void set_state_bits(struct extent_io_tree *tree, 412static void set_state_bits(struct extent_io_tree *tree,
413 struct extent_state *state, unsigned long *bits); 413 struct extent_state *state, unsigned *bits);
414 414
415/* 415/*
416 * insert an extent_state struct into the tree. 'bits' are set on the 416 * 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,
426 struct extent_state *state, u64 start, u64 end, 426 struct extent_state *state, u64 start, u64 end,
427 struct rb_node ***p, 427 struct rb_node ***p,
428 struct rb_node **parent, 428 struct rb_node **parent,
429 unsigned long *bits) 429 unsigned *bits)
430{ 430{
431 struct rb_node *node; 431 struct rb_node *node;
432 432
@@ -511,10 +511,10 @@ static struct extent_state *next_state(struct extent_state *state)
511 */ 511 */
512static struct extent_state *clear_state_bit(struct extent_io_tree *tree, 512static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
513 struct extent_state *state, 513 struct extent_state *state,
514 unsigned long *bits, int wake) 514 unsigned *bits, int wake)
515{ 515{
516 struct extent_state *next; 516 struct extent_state *next;
517 unsigned long bits_to_clear = *bits & ~EXTENT_CTLBITS; 517 unsigned bits_to_clear = *bits & ~EXTENT_CTLBITS;
518 518
519 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { 519 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) {
520 u64 range = state->end - state->start + 1; 520 u64 range = state->end - state->start + 1;
@@ -570,7 +570,7 @@ static void extent_io_tree_panic(struct extent_io_tree *tree, int err)
570 * This takes the tree lock, and returns 0 on success and < 0 on error. 570 * This takes the tree lock, and returns 0 on success and < 0 on error.
571 */ 571 */
572int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, 572int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
573 unsigned long bits, int wake, int delete, 573 unsigned bits, int wake, int delete,
574 struct extent_state **cached_state, 574 struct extent_state **cached_state,
575 gfp_t mask) 575 gfp_t mask)
576{ 576{
@@ -789,9 +789,9 @@ out:
789 789
790static void set_state_bits(struct extent_io_tree *tree, 790static void set_state_bits(struct extent_io_tree *tree,
791 struct extent_state *state, 791 struct extent_state *state,
792 unsigned long *bits) 792 unsigned *bits)
793{ 793{
794 unsigned long bits_to_set = *bits & ~EXTENT_CTLBITS; 794 unsigned bits_to_set = *bits & ~EXTENT_CTLBITS;
795 795
796 set_state_cb(tree, state, bits); 796 set_state_cb(tree, state, bits);
797 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { 797 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
@@ -803,7 +803,7 @@ static void set_state_bits(struct extent_io_tree *tree,
803 803
804static void cache_state_if_flags(struct extent_state *state, 804static void cache_state_if_flags(struct extent_state *state,
805 struct extent_state **cached_ptr, 805 struct extent_state **cached_ptr,
806 const u64 flags) 806 unsigned flags)
807{ 807{
808 if (cached_ptr && !(*cached_ptr)) { 808 if (cached_ptr && !(*cached_ptr)) {
809 if (!flags || (state->state & flags)) { 809 if (!flags || (state->state & flags)) {
@@ -833,7 +833,7 @@ static void cache_state(struct extent_state *state,
833 833
834static int __must_check 834static int __must_check
835__set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, 835__set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
836 unsigned long bits, unsigned long exclusive_bits, 836 unsigned bits, unsigned exclusive_bits,
837 u64 *failed_start, struct extent_state **cached_state, 837 u64 *failed_start, struct extent_state **cached_state,
838 gfp_t mask) 838 gfp_t mask)
839{ 839{
@@ -1034,7 +1034,7 @@ search_again:
1034} 1034}
1035 1035
1036int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, 1036int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
1037 unsigned long bits, u64 * failed_start, 1037 unsigned bits, u64 * failed_start,
1038 struct extent_state **cached_state, gfp_t mask) 1038 struct extent_state **cached_state, gfp_t mask)
1039{ 1039{
1040 return __set_extent_bit(tree, start, end, bits, 0, failed_start, 1040 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,
1060 * boundary bits like LOCK. 1060 * boundary bits like LOCK.
1061 */ 1061 */
1062int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, 1062int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
1063 unsigned long bits, unsigned long clear_bits, 1063 unsigned bits, unsigned clear_bits,
1064 struct extent_state **cached_state, gfp_t mask) 1064 struct extent_state **cached_state, gfp_t mask)
1065{ 1065{
1066 struct extent_state *state; 1066 struct extent_state *state;
@@ -1268,14 +1268,14 @@ int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
1268} 1268}
1269 1269
1270int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, 1270int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
1271 unsigned long bits, gfp_t mask) 1271 unsigned bits, gfp_t mask)
1272{ 1272{
1273 return set_extent_bit(tree, start, end, bits, NULL, 1273 return set_extent_bit(tree, start, end, bits, NULL,
1274 NULL, mask); 1274 NULL, mask);
1275} 1275}
1276 1276
1277int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, 1277int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
1278 unsigned long bits, gfp_t mask) 1278 unsigned bits, gfp_t mask)
1279{ 1279{
1280 return clear_extent_bit(tree, start, end, bits, 0, 0, NULL, mask); 1280 return clear_extent_bit(tree, start, end, bits, 0, 0, NULL, mask);
1281} 1281}
@@ -1330,10 +1330,11 @@ int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
1330 * us if waiting is desired. 1330 * us if waiting is desired.
1331 */ 1331 */
1332int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, 1332int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
1333 unsigned long bits, struct extent_state **cached_state) 1333 unsigned bits, struct extent_state **cached_state)
1334{ 1334{
1335 int err; 1335 int err;
1336 u64 failed_start; 1336 u64 failed_start;
1337
1337 while (1) { 1338 while (1) {
1338 err = __set_extent_bit(tree, start, end, EXTENT_LOCKED | bits, 1339 err = __set_extent_bit(tree, start, end, EXTENT_LOCKED | bits,
1339 EXTENT_LOCKED, &failed_start, 1340 EXTENT_LOCKED, &failed_start,
@@ -1440,7 +1441,7 @@ static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)
1440 */ 1441 */
1441static struct extent_state * 1442static struct extent_state *
1442find_first_extent_bit_state(struct extent_io_tree *tree, 1443find_first_extent_bit_state(struct extent_io_tree *tree,
1443 u64 start, unsigned long bits) 1444 u64 start, unsigned bits)
1444{ 1445{
1445 struct rb_node *node; 1446 struct rb_node *node;
1446 struct extent_state *state; 1447 struct extent_state *state;
@@ -1474,7 +1475,7 @@ out:
1474 * If nothing was found, 1 is returned. If found something, return 0. 1475 * If nothing was found, 1 is returned. If found something, return 0.
1475 */ 1476 */
1476int find_first_extent_bit(struct extent_io_tree *tree, u64 start, 1477int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
1477 u64 *start_ret, u64 *end_ret, unsigned long bits, 1478 u64 *start_ret, u64 *end_ret, unsigned bits,
1478 struct extent_state **cached_state) 1479 struct extent_state **cached_state)
1479{ 1480{
1480 struct extent_state *state; 1481 struct extent_state *state;
@@ -1753,7 +1754,7 @@ out_failed:
1753 1754
1754int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end, 1755int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
1755 struct page *locked_page, 1756 struct page *locked_page,
1756 unsigned long clear_bits, 1757 unsigned clear_bits,
1757 unsigned long page_ops) 1758 unsigned long page_ops)
1758{ 1759{
1759 struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; 1760 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,
1810 */ 1811 */
1811u64 count_range_bits(struct extent_io_tree *tree, 1812u64 count_range_bits(struct extent_io_tree *tree,
1812 u64 *start, u64 search_end, u64 max_bytes, 1813 u64 *start, u64 search_end, u64 max_bytes,
1813 unsigned long bits, int contig) 1814 unsigned bits, int contig)
1814{ 1815{
1815 struct rb_node *node; 1816 struct rb_node *node;
1816 struct extent_state *state; 1817 struct extent_state *state;
@@ -1928,7 +1929,7 @@ out:
1928 * range is found set. 1929 * range is found set.
1929 */ 1930 */
1930int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, 1931int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
1931 unsigned long bits, int filled, struct extent_state *cached) 1932 unsigned bits, int filled, struct extent_state *cached)
1932{ 1933{
1933 struct extent_state *state = NULL; 1934 struct extent_state *state = NULL;
1934 struct rb_node *node; 1935 struct rb_node *node;