Re: [PATCH 14/15] btrfs-progs: Wire up delayed refs

2018-07-30 Thread Nikolay Borisov



On 30.07.2018 11:33, Misono Tomohiro wrote:
> On 2018/06/08 21:47, Nikolay Borisov wrote:
>> This commit enables the delayed refs infrastructures. This entails doing
>> the following:
>>
>> 1. Replacing existing calls of btrfs_extent_post_op (which is the
>> equivalent of delayed refs) with the proper btrfs_run_delayed_refs.
>> As well as eliminating open-coded calls to finish_current_insert and
>> del_pending_extents which execute the delayed ops.
>>
>> 2. Wiring up the addition of delayed refs when freeing extents
>> (btrfs_free_extent) and when adding new extents (alloc_tree_block).
>>
>> 3. Adding calls to btrfs_run_delayed refs in the transaction commit
>> path alongside comments why every call is needed, since it's not always
>> obvious (those call sites were derived empirically by running and
>> debugging existing tests)
>>
>> 4. Correctly flagging the transaction in which we are reinitialising
>> the extent tree.
>>
>> Signed-off-by: Nikolay Borisov 
>> ---
>>  check/main.c  |   3 +-
>>  extent-tree.c | 166 
>> ++
>>  transaction.c |  24 +
>>  3 files changed, 111 insertions(+), 82 deletions(-)
>>
>> diff --git a/check/main.c b/check/main.c
>> index b84903acdb25..7c9689f29fd3 100644
>> --- a/check/main.c
>> +++ b/check/main.c
>> @@ -8634,7 +8634,7 @@ static int reinit_extent_tree(struct 
>> btrfs_trans_handle *trans,
>>  fprintf(stderr, "Error adding block group\n");
>>  return ret;
>>  }
>> -btrfs_extent_post_op(trans);
>> +btrfs_run_delayed_refs(trans, -1);
>>  }
>>  
>>  ret = reset_balance(trans, fs_info);
>> @@ -9682,6 +9682,7 @@ int cmd_check(int argc, char **argv)
>>  goto close_out;
>>  }
>>  
>> +trans->reinit_extent_tree = true;
>>  if (init_extent_tree) {
>>  printf("Creating a new extent tree\n");
>>  ret = reinit_extent_tree(trans, info,
>> diff --git a/extent-tree.c b/extent-tree.c
>> index 3208ed11cb91..9d085158f2d8 100644
>> --- a/extent-tree.c
>> +++ b/extent-tree.c
>> @@ -1418,8 +1418,6 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle 
>> *trans,
>>  err = ret;
>>  out:
>>  btrfs_free_path(path);
>> -finish_current_insert(trans);
>> -del_pending_extents(trans);
>>  BUG_ON(err);
>>  return err;
>>  }
>> @@ -1602,8 +1600,6 @@ int btrfs_set_block_flags(struct btrfs_trans_handle 
>> *trans, u64 bytenr,
>>  btrfs_set_extent_flags(l, item, flags);
>>  out:
>>  btrfs_free_path(path);
>> -finish_current_insert(trans);
>> -del_pending_extents(trans);
>>  return ret;
>>  }
>>  
>> @@ -1701,7 +1697,6 @@ static int write_one_cache_group(struct 
>> btrfs_trans_handle *trans,
>>   struct btrfs_block_group_cache *cache)
>>  {
>>  int ret;
>> -int pending_ret;
>>  struct btrfs_root *extent_root = trans->fs_info->extent_root;
>>  unsigned long bi;
>>  struct extent_buffer *leaf;
>> @@ -1717,12 +1712,8 @@ static int write_one_cache_group(struct 
>> btrfs_trans_handle *trans,
>>  btrfs_mark_buffer_dirty(leaf);
>>  btrfs_release_path(path);
>>  fail:
>> -finish_current_insert(trans);
>> -pending_ret = del_pending_extents(trans);
>>  if (ret)
>>  return ret;
>> -if (pending_ret)
>> -return pending_ret;
>>  return 0;
>>  
>>  }
>> @@ -2050,6 +2041,7 @@ static int finish_current_insert(struct 
>> btrfs_trans_handle *trans)
>>  int skinny_metadata =
>>  btrfs_fs_incompat(extent_root->fs_info, SKINNY_METADATA);
>>  
>> +
>>  while(1) {
>>  ret = find_first_extent_bit(>extent_ins, 0, ,
>>  , EXTENT_LOCKED);
>> @@ -2081,6 +2073,8 @@ static int finish_current_insert(struct 
>> btrfs_trans_handle *trans)
>>  BUG_ON(1);
>>  }
>>  
>> +
>> +printf("shouldn't be executed\n");
>>  clear_extent_bits(>extent_ins, start, end, EXTENT_LOCKED);
>>  kfree(extent_op);
>>  }
>> @@ -2380,7 +2374,6 @@ static int __free_extent(struct btrfs_trans_handle 
>> *trans,
>>  }
>>  fail:
>>  btrfs_free_path(path);
>> -finish_current_insert(trans);
>>  return ret;
>>  }
>>  
>> @@ -2463,33 +2456,30 @@ int btrfs_free_extent(struct btrfs_trans_handle 
>> *trans,
>>u64 bytenr, u64 num_bytes, u64 parent,
>>u64 root_objectid, u64 owner, u64 offset)
>>  {
>> -struct btrfs_root *extent_root = root->fs_info->extent_root;
>> -int pending_ret;
>>  int ret;
>>  
>>  WARN_ON(num_bytes < root->fs_info->sectorsize);
>> -if (root == extent_root) {
>> -struct pending_extent_op *extent_op;
>> -
>> -extent_op = kmalloc(sizeof(*extent_op), GFP_NOFS);
>> -BUG_ON(!extent_op);
>> -
>> -

Re: [PATCH 14/15] btrfs-progs: Wire up delayed refs

2018-07-30 Thread Misono Tomohiro
On 2018/06/08 21:47, Nikolay Borisov wrote:
> This commit enables the delayed refs infrastructures. This entails doing
> the following:
> 
> 1. Replacing existing calls of btrfs_extent_post_op (which is the
> equivalent of delayed refs) with the proper btrfs_run_delayed_refs.
> As well as eliminating open-coded calls to finish_current_insert and
> del_pending_extents which execute the delayed ops.
> 
> 2. Wiring up the addition of delayed refs when freeing extents
> (btrfs_free_extent) and when adding new extents (alloc_tree_block).
> 
> 3. Adding calls to btrfs_run_delayed refs in the transaction commit
> path alongside comments why every call is needed, since it's not always
> obvious (those call sites were derived empirically by running and
> debugging existing tests)
> 
> 4. Correctly flagging the transaction in which we are reinitialising
> the extent tree.
> 
> Signed-off-by: Nikolay Borisov 
> ---
>  check/main.c  |   3 +-
>  extent-tree.c | 166 
> ++
>  transaction.c |  24 +
>  3 files changed, 111 insertions(+), 82 deletions(-)
> 
> diff --git a/check/main.c b/check/main.c
> index b84903acdb25..7c9689f29fd3 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -8634,7 +8634,7 @@ static int reinit_extent_tree(struct btrfs_trans_handle 
> *trans,
>   fprintf(stderr, "Error adding block group\n");
>   return ret;
>   }
> - btrfs_extent_post_op(trans);
> + btrfs_run_delayed_refs(trans, -1);
>   }
>  
>   ret = reset_balance(trans, fs_info);
> @@ -9682,6 +9682,7 @@ int cmd_check(int argc, char **argv)
>   goto close_out;
>   }
>  
> + trans->reinit_extent_tree = true;
>   if (init_extent_tree) {
>   printf("Creating a new extent tree\n");
>   ret = reinit_extent_tree(trans, info,
> diff --git a/extent-tree.c b/extent-tree.c
> index 3208ed11cb91..9d085158f2d8 100644
> --- a/extent-tree.c
> +++ b/extent-tree.c
> @@ -1418,8 +1418,6 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle 
> *trans,
>   err = ret;
>  out:
>   btrfs_free_path(path);
> - finish_current_insert(trans);
> - del_pending_extents(trans);
>   BUG_ON(err);
>   return err;
>  }
> @@ -1602,8 +1600,6 @@ int btrfs_set_block_flags(struct btrfs_trans_handle 
> *trans, u64 bytenr,
>   btrfs_set_extent_flags(l, item, flags);
>  out:
>   btrfs_free_path(path);
> - finish_current_insert(trans);
> - del_pending_extents(trans);
>   return ret;
>  }
>  
> @@ -1701,7 +1697,6 @@ static int write_one_cache_group(struct 
> btrfs_trans_handle *trans,
>struct btrfs_block_group_cache *cache)
>  {
>   int ret;
> - int pending_ret;
>   struct btrfs_root *extent_root = trans->fs_info->extent_root;
>   unsigned long bi;
>   struct extent_buffer *leaf;
> @@ -1717,12 +1712,8 @@ static int write_one_cache_group(struct 
> btrfs_trans_handle *trans,
>   btrfs_mark_buffer_dirty(leaf);
>   btrfs_release_path(path);
>  fail:
> - finish_current_insert(trans);
> - pending_ret = del_pending_extents(trans);
>   if (ret)
>   return ret;
> - if (pending_ret)
> - return pending_ret;
>   return 0;
>  
>  }
> @@ -2050,6 +2041,7 @@ static int finish_current_insert(struct 
> btrfs_trans_handle *trans)
>   int skinny_metadata =
>   btrfs_fs_incompat(extent_root->fs_info, SKINNY_METADATA);
>  
> +
>   while(1) {
>   ret = find_first_extent_bit(>extent_ins, 0, ,
>   , EXTENT_LOCKED);
> @@ -2081,6 +2073,8 @@ static int finish_current_insert(struct 
> btrfs_trans_handle *trans)
>   BUG_ON(1);
>   }
>  
> +
> + printf("shouldn't be executed\n");
>   clear_extent_bits(>extent_ins, start, end, EXTENT_LOCKED);
>   kfree(extent_op);
>   }
> @@ -2380,7 +2374,6 @@ static int __free_extent(struct btrfs_trans_handle 
> *trans,
>   }
>  fail:
>   btrfs_free_path(path);
> - finish_current_insert(trans);
>   return ret;
>  }
>  
> @@ -2463,33 +2456,30 @@ int btrfs_free_extent(struct btrfs_trans_handle 
> *trans,
> u64 bytenr, u64 num_bytes, u64 parent,
> u64 root_objectid, u64 owner, u64 offset)
>  {
> - struct btrfs_root *extent_root = root->fs_info->extent_root;
> - int pending_ret;
>   int ret;
>  
>   WARN_ON(num_bytes < root->fs_info->sectorsize);
> - if (root == extent_root) {
> - struct pending_extent_op *extent_op;
> -
> - extent_op = kmalloc(sizeof(*extent_op), GFP_NOFS);
> - BUG_ON(!extent_op);
> -
> - extent_op->type = PENDING_EXTENT_DELETE;
> - extent_op->bytenr = bytenr;
> - extent_op->num_bytes = 

[PATCH 14/15] btrfs-progs: Wire up delayed refs

2018-06-08 Thread Nikolay Borisov
This commit enables the delayed refs infrastructures. This entails doing
the following:

1. Replacing existing calls of btrfs_extent_post_op (which is the
equivalent of delayed refs) with the proper btrfs_run_delayed_refs.
As well as eliminating open-coded calls to finish_current_insert and
del_pending_extents which execute the delayed ops.

2. Wiring up the addition of delayed refs when freeing extents
(btrfs_free_extent) and when adding new extents (alloc_tree_block).

3. Adding calls to btrfs_run_delayed refs in the transaction commit
path alongside comments why every call is needed, since it's not always
obvious (those call sites were derived empirically by running and
debugging existing tests)

4. Correctly flagging the transaction in which we are reinitialising
the extent tree.

Signed-off-by: Nikolay Borisov 
---
 check/main.c  |   3 +-
 extent-tree.c | 166 ++
 transaction.c |  24 +
 3 files changed, 111 insertions(+), 82 deletions(-)

diff --git a/check/main.c b/check/main.c
index b84903acdb25..7c9689f29fd3 100644
--- a/check/main.c
+++ b/check/main.c
@@ -8634,7 +8634,7 @@ static int reinit_extent_tree(struct btrfs_trans_handle 
*trans,
fprintf(stderr, "Error adding block group\n");
return ret;
}
-   btrfs_extent_post_op(trans);
+   btrfs_run_delayed_refs(trans, -1);
}
 
ret = reset_balance(trans, fs_info);
@@ -9682,6 +9682,7 @@ int cmd_check(int argc, char **argv)
goto close_out;
}
 
+   trans->reinit_extent_tree = true;
if (init_extent_tree) {
printf("Creating a new extent tree\n");
ret = reinit_extent_tree(trans, info,
diff --git a/extent-tree.c b/extent-tree.c
index 3208ed11cb91..9d085158f2d8 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -1418,8 +1418,6 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
err = ret;
 out:
btrfs_free_path(path);
-   finish_current_insert(trans);
-   del_pending_extents(trans);
BUG_ON(err);
return err;
 }
@@ -1602,8 +1600,6 @@ int btrfs_set_block_flags(struct btrfs_trans_handle 
*trans, u64 bytenr,
btrfs_set_extent_flags(l, item, flags);
 out:
btrfs_free_path(path);
-   finish_current_insert(trans);
-   del_pending_extents(trans);
return ret;
 }
 
@@ -1701,7 +1697,6 @@ static int write_one_cache_group(struct 
btrfs_trans_handle *trans,
 struct btrfs_block_group_cache *cache)
 {
int ret;
-   int pending_ret;
struct btrfs_root *extent_root = trans->fs_info->extent_root;
unsigned long bi;
struct extent_buffer *leaf;
@@ -1717,12 +1712,8 @@ static int write_one_cache_group(struct 
btrfs_trans_handle *trans,
btrfs_mark_buffer_dirty(leaf);
btrfs_release_path(path);
 fail:
-   finish_current_insert(trans);
-   pending_ret = del_pending_extents(trans);
if (ret)
return ret;
-   if (pending_ret)
-   return pending_ret;
return 0;
 
 }
@@ -2050,6 +2041,7 @@ static int finish_current_insert(struct 
btrfs_trans_handle *trans)
int skinny_metadata =
btrfs_fs_incompat(extent_root->fs_info, SKINNY_METADATA);
 
+
while(1) {
ret = find_first_extent_bit(>extent_ins, 0, ,
, EXTENT_LOCKED);
@@ -2081,6 +2073,8 @@ static int finish_current_insert(struct 
btrfs_trans_handle *trans)
BUG_ON(1);
}
 
+
+   printf("shouldn't be executed\n");
clear_extent_bits(>extent_ins, start, end, EXTENT_LOCKED);
kfree(extent_op);
}
@@ -2380,7 +2374,6 @@ static int __free_extent(struct btrfs_trans_handle *trans,
}
 fail:
btrfs_free_path(path);
-   finish_current_insert(trans);
return ret;
 }
 
@@ -2463,33 +2456,30 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
  u64 bytenr, u64 num_bytes, u64 parent,
  u64 root_objectid, u64 owner, u64 offset)
 {
-   struct btrfs_root *extent_root = root->fs_info->extent_root;
-   int pending_ret;
int ret;
 
WARN_ON(num_bytes < root->fs_info->sectorsize);
-   if (root == extent_root) {
-   struct pending_extent_op *extent_op;
-
-   extent_op = kmalloc(sizeof(*extent_op), GFP_NOFS);
-   BUG_ON(!extent_op);
-
-   extent_op->type = PENDING_EXTENT_DELETE;
-   extent_op->bytenr = bytenr;
-   extent_op->num_bytes = num_bytes;
-   extent_op->level = (int)owner;
-
-   set_extent_bits(>fs_info->pending_del,
-   bytenr, bytenr + num_bytes - 1,
-