diff mbox series

[7/8] btrfs: use extent_io_tree_release() to empty dirty log pages

Message ID 459c0d25abdfecdc7c57192fa656c6abda11af31.1695333278.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: some speedups for io tree operations and cleanups | expand

Commit Message

Filipe Manana Sept. 22, 2023, 10:39 a.m. UTC
From: Filipe Manana <fdmanana@suse.com>

When freeing a log tree, during a transaction commit, we clear its dirty
log pages io tree by calling clear_extent_bits() using a range from 0 to
(u64)-1. This will iterate the io tree's rbtree and call rb_erase() on
each node before freeing it, which will often trigger rebalance operations
on the rbtree. A better alternative it to use extent_io_tree_release(),
which will not do deletions and trigger rebalances.

So use extent_io_tree_release() instead of clear_extent_bits().

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/tree-log.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

kernel test robot Sept. 26, 2023, 6:25 a.m. UTC | #1
Hello,

kernel test robot noticed "BUG:sleeping_function_called_from_invalid_context_at_fs/btrfs/extent-io-tree.c" on:

commit: 84b23544b95acd2e4c05fc473816d19b749fe17b ("[PATCH 7/8] btrfs: use extent_io_tree_release() to empty dirty log pages")
url: https://github.com/intel-lab-lkp/linux/commits/fdmanana-kernel-org/btrfs-make-extent-state-merges-more-efficient-during-insertions/20230922-184038
base: https://git.kernel.org/cgit/linux/kernel/git/kdave/linux.git for-next
patch link: https://lore.kernel.org/all/459c0d25abdfecdc7c57192fa656c6abda11af31.1695333278.git.fdmanana@suse.com/
patch subject: [PATCH 7/8] btrfs: use extent_io_tree_release() to empty dirty log pages

in testcase: ltp
version: ltp-x86_64-14c1f76-1_20230715
with following parameters:

	disk: 1HDD
	fs: btrfs
	test: ltp-aiodio.part2-01



compiler: gcc-12
test machine: 4 threads 1 sockets Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz (Ivy Bridge) with 8G memory

(please refer to attached dmesg/kmsg for entire log/backtrace)



If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <oliver.sang@intel.com>
| Closes: https://lore.kernel.org/oe-lkp/202309261438.d1bebb50-oliver.sang@intel.com



kern  :err   : [  179.301033] BUG: sleeping function called from invalid context at fs/btrfs/extent-io-tree.c:132
kern  :err   : [  179.301247] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 3670, name: aiodio_sparse
kern  :err   : [  179.301432] preempt_count: 1, expected: 0
kern  :err   : [  179.301544] RCU nest depth: 0, expected: 0
kern  :warn  : [  179.301708] CPU: 1 PID: 3670 Comm: aiodio_sparse Not tainted 6.6.0-rc2-00143-g84b23544b95a #1
kern  :warn  : [  179.301924] Hardware name: Hewlett-Packard p6-1451cx/2ADA, BIOS 8.15 02/05/2013
kern  :warn  : [  179.302126] Call Trace:
kern  :warn  : [  179.302242]  <TASK>
kern :warn : [  179.302351] dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1)) 
kern :warn : [  179.302489] __might_resched (kernel/sched/core.c:10188) 
kern :warn : [  179.302630] ? preempt_notifier_dec (kernel/sched/core.c:10142) 
kern :warn : [  179.302781] ? extent_io_tree_release (fs/btrfs/extent-io-tree.c:132) btrfs
kern :warn : [  179.303082] ? walk_down_log_tree (fs/btrfs/tree-log.c:2711) btrfs
kern :warn : [  179.303368] extent_io_tree_release (include/linux/sched.h:2097 fs/btrfs/extent-io-tree.c:132) btrfs
kern :warn : [  179.303657] free_log_tree (fs/btrfs/tree-log.c:3214) btrfs
kern :warn : [  179.303922] ? walk_log_tree (fs/btrfs/tree-log.c:3173) btrfs
kern :warn : [  179.304123] ? free_log_tree (fs/btrfs/tree-log.c:330) btrfs
kern :warn : [  179.304323] btrfs_free_log (fs/btrfs/tree-log.c:3227) btrfs
kern :warn : [  179.304519] commit_fs_roots (fs/btrfs/transaction.c:1539) btrfs
kern :warn : [  179.304721] ? btrfs_read_block_groups (fs/btrfs/block-group.c:2668) btrfs
kern :warn : [  179.304934] ? __btrfs_run_delayed_refs (fs/btrfs/extent-tree.c:2135) btrfs
kern :warn : [  179.305142] ? trace_btrfs_transaction_commit (fs/btrfs/transaction.c:1501) btrfs
kern :warn : [  179.305357] btrfs_commit_transaction (fs/btrfs/transaction.c:2508 (discriminator 3)) btrfs
kern :warn : [  179.305566] ? cleanup_transaction (fs/btrfs/transaction.c:2243) btrfs
kern :warn : [  179.305769] ? dput (fs/dcache.c:900) 
kern :warn : [  179.305879] ? dget_parent (fs/dcache.c:971) 
kern :warn : [  179.305988] btrfs_sync_file (fs/btrfs/file.c:1987) btrfs
kern :warn : [  179.306184] ? start_ordered_ops+0x100/0x100 btrfs
kern :warn : [  179.306400] ? find_vma (mm/mmap.c:1853) 
kern :warn : [  179.306506] ? find_vma_intersection (mm/mmap.c:1853) 
kern :warn : [  179.306630] __do_sys_msync (mm/msync.c:97) 
kern :warn : [  179.306742] do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80) 
kern :warn : [  179.306852] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120) 
kern  :warn  : [  179.306986] RIP: 0033:0x7f3b83d45740
kern :warn : [ 179.307093] Code: 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 80 3d a1 8e 0d 00 00 74 17 b8 1a 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 58 c3 0f 1f 80 00 00 00 00 48 83 ec 28 89 54
All code
========
   0:	00 f7                	add    %dh,%bh
   2:	d8 64 89 01          	fsubs  0x1(%rcx,%rcx,4)
   6:	48 83 c8 ff          	or     $0xffffffffffffffff,%rax
   a:	c3                   	retq   
   b:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
  12:	00 00 00 
  15:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
  1a:	80 3d a1 8e 0d 00 00 	cmpb   $0x0,0xd8ea1(%rip)        # 0xd8ec2
  21:	74 17                	je     0x3a
  23:	b8 1a 00 00 00       	mov    $0x1a,%eax
  28:	0f 05                	syscall 
  2a:*	48 3d 00 f0 ff ff    	cmp    $0xfffffffffffff000,%rax		<-- trapping instruction
  30:	77 58                	ja     0x8a
  32:	c3                   	retq   
  33:	0f 1f 80 00 00 00 00 	nopl   0x0(%rax)
  3a:	48 83 ec 28          	sub    $0x28,%rsp
  3e:	89                   	.byte 0x89
  3f:	54                   	push   %rsp

Code starting with the faulting instruction
===========================================
   0:	48 3d 00 f0 ff ff    	cmp    $0xfffffffffffff000,%rax
   6:	77 58                	ja     0x60
   8:	c3                   	retq   
   9:	0f 1f 80 00 00 00 00 	nopl   0x0(%rax)
  10:	48 83 ec 28          	sub    $0x28,%rsp
  14:	89                   	.byte 0x89
  15:	54                   	push   %rsp
kern  :warn  : [  179.307439] RSP: 002b:00007ffdafb85f58 EFLAGS: 00000202 ORIG_RAX: 000000000000001a
kern  :warn  : [  179.307615] RAX: ffffffffffffffda RBX: 0000000006400000 RCX: 00007f3b83d45740
kern  :warn  : [  179.307777] RDX: 0000000000000004 RSI: 0000000006400000 RDI: 00007f3b7d800000
kern  :warn  : [  179.307938] RBP: 00007f3b7d800000 R08: 0000000000000004 R09: 0000000000000000
kern  :warn  : [  179.308098] R10: 00007f3b83c50168 R11: 0000000000000202 R12: 0000000000000004
kern  :warn  : [  179.308287] R13: 000055b86e53d033 R14: 000055b86e53d140 R15: 0000000000000000
kern  :warn  : [  179.308454]  </TASK>



The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20230926/202309261438.d1bebb50-oliver.sang@intel.com
David Sterba Sept. 26, 2023, 4:27 p.m. UTC | #2
On Tue, Sep 26, 2023 at 02:25:06PM +0800, kernel test robot wrote:
> Hello,
> 
> kernel test robot noticed "BUG:sleeping_function_called_from_invalid_context_at_fs/btrfs/extent-io-tree.c" on:
> 
> commit: 84b23544b95acd2e4c05fc473816d19b749fe17b ("[PATCH 7/8] btrfs: use extent_io_tree_release() to empty dirty log pages")
> url: https://github.com/intel-lab-lkp/linux/commits/fdmanana-kernel-org/btrfs-make-extent-state-merges-more-efficient-during-insertions/20230922-184038
> base: https://git.kernel.org/cgit/linux/kernel/git/kdave/linux.git for-next
> patch link: https://lore.kernel.org/all/459c0d25abdfecdc7c57192fa656c6abda11af31.1695333278.git.fdmanana@suse.com/
> patch subject: [PATCH 7/8] btrfs: use extent_io_tree_release() to empty dirty log pages

Known and fixed in the git branch.
diff mbox series

Patch

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index f4257be56bd3..8687c944451f 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -3207,8 +3207,7 @@  static void free_log_tree(struct btrfs_trans_handle *trans,
 		}
 	}
 
-	clear_extent_bits(&log->dirty_log_pages, 0, (u64)-1,
-			  EXTENT_DIRTY | EXTENT_NEW | EXTENT_NEED_WAIT);
+	extent_io_tree_release(&log->dirty_log_pages);
 	extent_io_tree_release(&log->log_csum_range);
 
 	btrfs_put_root(log);