remove delalloc accounting for __btrfs_remove_ordered_extent
RFC 1/1 remove delalloc accounting for __btrfs_remove_ordered_extent
I got below oops when doing file write with mount option max_extent=1M It appears the accouting is already done in set/clear/split/merge hooks and I don't see reason why we need do accouting in __btrfs_remove_ordered_extent again. Below patch makes my test work but please double check.
[ 185.776309] Pid: 3368, comm: btrfs-endio-wri Not tainted 2.6.33-rc8-00165-g446ce07 #668 0M017G/Studio Slim 540s [ 185.776353] RIP: 0010:[<ffffffffa000ca13>] [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.776427] RSP: 0018:ffff88012614bbd0 EFLAGS: 00010286 [ 185.776460] RAX: 00000000ffffffff RBX: ffff88012771c960 RCX: 0000000000000000 [ 185.776496] RDX: ffffffffa000c9dd RSI: ffff8801295d3800 RDI: 0000000000000001 [ 185.776532] RBP: ffff88012614bc00 R08: ffff88012614bb90 R09: 0000000000000000 [ 185.776568] R10: ffff88012614bbc0 R11: 0000000000000043 R12: ffff88012990a9b8 [ 185.776603] R13: 000000000001a000 R14: ffff88012990a900 R15: ffff88012771c950 [ 185.776640] FS: 0000000000000000(0000) GS:ffff880005880000(0000) knlGS:0000000000000000 [ 185.776678] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 185.776711] CR2: 0000003de9123f40 CR3: 00000001249b6000 CR4: 00000000000406e0 [ 185.776747] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 185.776795] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 185.776845] Process btrfs-endio-wri (pid: 3368, threadinfo ffff88012614a000, task ffff880128b34240) [ 185.776910] Stack: [ 185.776946] ffff88012614bbf0 ffff88012771c960 ffff8801249d4840 ffff88012771c7c0 [ 185.777050] <0> ffff88012771c950 0000000100000000 ffff88012614bc30 ffffffffa003559e [ 185.777203] <0> 0000000000000001 ffff8801249d4840 ffff88012771c960 0000000100000000 [ 185.777388] Call Trace: [ 185.777438] [<ffffffffa003559e>] __btrfs_remove_ordered_extent+0x72/0x126 [btrfs] [ 185.777511] [<ffffffffa003593f>] btrfs_ordered_update_i_size+0x2ed/0x33a [btrfs] [ 185.777585] [<ffffffffa0028c9e>] btrfs_finish_ordered_io+0x196/0x1d8 [btrfs] [ 185.777636] [<ffffffff810d39d1>] ? test_clear_page_writeback+0xfa/0x10c [ 185.777695] [<ffffffffa0028cfa>] btrfs_writepage_end_io_hook+0x1a/0x1c [btrfs] [ 185.777765] [<ffffffffa0039ef8>] end_bio_extent_writepage+0xae/0x159 [btrfs] [ 185.777815] [<ffffffff81130e56>] bio_endio+0x2b/0x2d [ 185.777868] [<ffffffffa001bcea>] end_workqueue_fn+0x111/0x120 [btrfs] [ 185.777923] [<ffffffffa00427e5>] worker_loop+0x1b9/0x547 [btrfs] [ 185.777977] [<ffffffffa004262c>] ? worker_loop+0x0/0x547 [btrfs] [ 185.778024] [<ffffffff8107f9b9>] kthread+0x7f/0x87 [ 185.778071] [<ffffffff8102f954>] kernel_thread_helper+0x4/0x10 [ 185.778119] [<ffffffff8105a8e1>] ? finish_task_switch+0x50/0xc2 [ 185.778166] [<ffffffff8161a5a9>] ? _raw_spin_unlock_irq+0x1b/0x36 [ 185.778212] [<ffffffff8161ae6d>] ? restore_args+0x0/0x30 [ 185.778257] [<ffffffff8107f93a>] ? kthread+0x0/0x87 [ 185.778300] [<ffffffff8102f950>] ? kernel_thread_helper+0x0/0x10 [ 185.778345] Code: 3b 43 f8 7f 12 4c 89 ff e8 cf db 60 e1 4c 89 e7 e8 c7 db 60 e1 eb 46 4c 89 ff e8 bd db 60 e1 8b 43 f4 ff c8 89 43 f4 85 c0 79 04 <0f> 0b eb fe 49 8b 46 48 4c 39 e8 73 0c 49 c7 46 48 00 00 00 00 [ 185.779620] RIP [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.779710] RSP <ffff88012614bbd0> [ 185.779765] ---[ end trace daf2ed048f53f7f0 ]--- [ 185.779812] note: btrfs-endio-wri[3368] exited with preempt_count
--- fs/btrfs/ordered-data.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
fs/btrfs/ordered-data.c +0 -6
@@ -306,12 +306,6 @@ static int __btrfs_remove_ordered_extent(struct inode *inode, tree->last =NULL ;set_bit (BTRFS_ORDERED_COMPLETE , &entry->flags); -spin_lock (&BTRFS_I (inode)->accounting_lock); -BTRFS_I (inode)->outstanding_extents--; -spin_unlock (&BTRFS_I (inode)->accounting_lock); -btrfs_unreserve_metadata_for_delalloc (BTRFS_I (inode)->root, - inode,1 ); -spin_lock (&BTRFS_I (inode)->root->fs_info->ordered_extent_lock);list_del_init (&entry->root_extent_list);
Signature · 1 line
1.6.3.3
Quoted 59 lines · Shaohua Li
I got below oops when doing file write with mount option max_extent=1M It appears the accouting is already done in set/clear/split/merge hooks and I don't see reason why we need do accouting in
__btrfs_remove_ordered_extentagain. Below patch makes my test work but please double check.[ 185.776309] Pid: 3368, comm: btrfs-endio-wri Not tainted 2.6.33-rc8-00165-g446ce07 #668 0M017G/Studio Slim 540s [ 185.776353] RIP: 0010:[<ffffffffa000ca13>] [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.776427] RSP: 0018:ffff88012614bbd0 EFLAGS: 00010286 [ 185.776460] RAX: 00000000ffffffff RBX: ffff88012771c960 RCX: 0000000000000000 [ 185.776496] RDX: ffffffffa000c9dd RSI: ffff8801295d3800 RDI: 0000000000000001 [ 185.776532] RBP: ffff88012614bc00 R08: ffff88012614bb90 R09: 0000000000000000 [ 185.776568] R10: ffff88012614bbc0 R11: 0000000000000043 R12: ffff88012990a9b8 [ 185.776603] R13: 000000000001a000 R14: ffff88012990a900 R15: ffff88012771c950 [ 185.776640] FS: 0000000000000000(0000) GS:ffff880005880000(0000) knlGS:0000000000000000 [ 185.776678] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 185.776711] CR2: 0000003de9123f40 CR3: 00000001249b6000 CR4: 00000000000406e0 [ 185.776747] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 185.776795] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 185.776845] Process btrfs-endio-wri (pid: 3368, threadinfo ffff88012614a000, task ffff880128b34240) [ 185.776910] Stack: [ 185.776946] ffff88012614bbf0 ffff88012771c960 ffff8801249d4840 ffff88012771c7c0 [ 185.777050] <0> ffff88012771c950 0000000100000000 ffff88012614bc30 ffffffffa003559e [ 185.777203] <0> 0000000000000001 ffff8801249d4840 ffff88012771c960 0000000100000000 [ 185.777388] Call Trace: [ 185.777438] [<ffffffffa003559e>] __btrfs_remove_ordered_extent+0x72/0x126 [btrfs] [ 185.777511] [<ffffffffa003593f>] btrfs_ordered_update_i_size+0x2ed/0x33a [btrfs] [ 185.777585] [<ffffffffa0028c9e>] btrfs_finish_ordered_io+0x196/0x1d8 [btrfs] [ 185.777636] [<ffffffff810d39d1>] ? test_clear_page_writeback+0xfa/0x10c [ 185.777695] [<ffffffffa0028cfa>] btrfs_writepage_end_io_hook+0x1a/0x1c [btrfs] [ 185.777765] [<ffffffffa0039ef8>] end_bio_extent_writepage+0xae/0x159 [btrfs] [ 185.777815] [<ffffffff81130e56>] bio_endio+0x2b/0x2d [ 185.777868] [<ffffffffa001bcea>] end_workqueue_fn+0x111/0x120 [btrfs] [ 185.777923] [<ffffffffa00427e5>] worker_loop+0x1b9/0x547 [btrfs] [ 185.777977] [<ffffffffa004262c>] ? worker_loop+0x0/0x547 [btrfs] [ 185.778024] [<ffffffff8107f9b9>] kthread+0x7f/0x87 [ 185.778071] [<ffffffff8102f954>] kernel_thread_helper+0x4/0x10 [ 185.778119] [<ffffffff8105a8e1>] ? finish_task_switch+0x50/0xc2 [ 185.778166] [<ffffffff8161a5a9>] ? _raw_spin_unlock_irq+0x1b/0x36 [ 185.778212] [<ffffffff8161ae6d>] ? restore_args+0x0/0x30 [ 185.778257] [<ffffffff8107f93a>] ? kthread+0x0/0x87 [ 185.778300] [<ffffffff8102f950>] ? kernel_thread_helper+0x0/0x10 [ 185.778345] Code: 3b 43 f8 7f 12 4c 89 ff e8 cf db 60 e1 4c 89 e7 e8 c7 db 60 e1 eb 46 4c 89 ff e8 bd db 60 e1 8b 43 f4 ff c8 89 43 f4 85 c0 79 04 <0f> 0b eb fe 49 8b 46 48 4c 39 e8 73 0c 49 c7 46 48 00 00 00 00 [ 185.779620] RIP [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.779710] RSP <ffff88012614bbd0> [ 185.779765] ---[ end trace daf2ed048f53f7f0 ]--- [ 185.779812] note: btrfs-endio-wri[3368] exited with preempt_countSigned-off-by Shaohua Li <[email protected]>--- fs/btrfs/ordered-data.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)fs/btrfs/ordered-data.c +0
-0@@ -306,12 +306,6 @@ static int __btrfs_remove_ordered_extent(struct inode *inode, tree->last =NULL ;set_bit (BTRFS_ORDERED_COMPLETE , &entry->flags);
fs/btrfs/ordered-data.c static int __btrfs_remove_ordered_extent(struct inode *inode, · line 311
Quoted 10 lines
fs/btrfs/ordered-data.c +0
-6-spin_lock (&BTRFS_I (inode)->accounting_lock); -BTRFS_I (inode)->outstanding_extents--; -spin_unlock (&BTRFS_I (inode)->accounting_lock); -btrfs_unreserve_metadata_for_delalloc (BTRFS_I (inode)->root, - inode,1 ); -spin_lock (&BTRFS_I (inode)->root->fs_info->ordered_extent_lock);list_del_init (&entry->root_extent_list);
We don't want to remove the accounting until the data is actually on the disk, thats why its done here. Thanks,
Josef
Quoted 38 lines · Shaohua Li
I got below oops when doing file write with mount option max_extent=1M It appears the accouting is already done in set/clear/split/merge hooks and I don't see reason why we need do accouting in
__btrfs_remove_ordered_extentagain. Below patch makes my test work but please double check.[ 185.776309] Pid: 3368, comm: btrfs-endio-wri Not tainted 2.6.33-rc8-00165-g446ce07 #668 0M017G/Studio Slim 540s [ 185.776353] RIP: 0010:[<ffffffffa000ca13>] [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.776427] RSP: 0018:ffff88012614bbd0 EFLAGS: 00010286 [ 185.776460] RAX: 00000000ffffffff RBX: ffff88012771c960 RCX: 0000000000000000 [ 185.776496] RDX: ffffffffa000c9dd RSI: ffff8801295d3800 RDI: 0000000000000001 [ 185.776532] RBP: ffff88012614bc00 R08: ffff88012614bb90 R09: 0000000000000000 [ 185.776568] R10: ffff88012614bbc0 R11: 0000000000000043 R12: ffff88012990a9b8 [ 185.776603] R13: 000000000001a000 R14: ffff88012990a900 R15: ffff88012771c950 [ 185.776640] FS: 0000000000000000(0000) GS:ffff880005880000(0000) knlGS:0000000000000000 [ 185.776678] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 185.776711] CR2: 0000003de9123f40 CR3: 00000001249b6000 CR4: 00000000000406e0 [ 185.776747] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 185.776795] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 185.776845] Process btrfs-endio-wri (pid: 3368, threadinfo ffff88012614a000, task ffff880128b34240) [ 185.776910] Stack: [ 185.776946] ffff88012614bbf0 ffff88012771c960 ffff8801249d4840 ffff88012771c7c0 [ 185.777050] <0> ffff88012771c950 0000000100000000 ffff88012614bc30 ffffffffa003559e [ 185.777203] <0> 0000000000000001 ffff8801249d4840 ffff88012771c960 0000000100000000 [ 185.777388] Call Trace: [ 185.777438] [<ffffffffa003559e>] __btrfs_remove_ordered_extent+0x72/0x126 [btrfs] [ 185.777511] [<ffffffffa003593f>] btrfs_ordered_update_i_size+0x2ed/0x33a [btrfs] [ 185.777585] [<ffffffffa0028c9e>] btrfs_finish_ordered_io+0x196/0x1d8 [btrfs] [ 185.777636] [<ffffffff810d39d1>] ? test_clear_page_writeback+0xfa/0x10c [ 185.777695] [<ffffffffa0028cfa>] btrfs_writepage_end_io_hook+0x1a/0x1c [btrfs] [ 185.777765] [<ffffffffa0039ef8>] end_bio_extent_writepage+0xae/0x159 [btrfs] [ 185.777815] [<ffffffff81130e56>] bio_endio+0x2b/0x2d [ 185.777868] [<ffffffffa001bcea>] end_workqueue_fn+0x111/0x120 [btrfs] [ 185.777923] [<ffffffffa00427e5>] worker_loop+0x1b9/0x547 [btrfs] [ 185.777977] [<ffffffffa004262c>] ? worker_loop+0x0/0x547 [btrfs] [ 185.778024] [<ffffffff8107f9b9>] kthread+0x7f/0x87 [ 185.778071] [<ffffffff8102f954>] kernel_thread_helper+0x4/0x10 [ 185.778119] [<ffffffff8105a8e1>] ? finish_task_switch+0x50/0xc2 [ 185.778166] [<ffffffff8161a5a9>] ? _raw_spin_unlock_irq+0x1b/0x36
Quoted 9 lines
[ 185.778212] [<ffffffff8161ae6d>] ? restore_args+0x0/0x30 [ 185.778257] [<ffffffff8107f93a>] ? kthread+0x0/0x87 [ 185.778300] [<ffffffff8102f950>] ? kernel_thread_helper+0x0/0x10 [ 185.778345] Code: 3b 43 f8 7f 12 4c 89 ff e8 cf db 60 e1 4c 89 e7 e8 c7 db 60 e1 eb 46 4c 89 ff e8 bd db 60 e1 8b 43 f4 ff c8 89 43 f4 85 c0 79 04 <0f> 0b eb fe 49 8b 46 48 4c 39 e8 73 0c 49 c7 46 48 00 00 00 00 [ 185.779620] RIP [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.779710] RSP <ffff88012614bbd0> [ 185.779765] ---[ end trace daf2ed048f53f7f0 ]--- [ 185.779812] note: btrfs-endio-wri[3368] exited with preempt_count
How do you reproduce this problem? I've been trying to but it's not reproducing for me. Thanks,
Josef
Quoted 38 lines · Shaohua Li
I got below oops when doing file write with mount option max_extent=1M It appears the accouting is already done in set/clear/split/merge hooks and I don't see reason why we need do accouting in
__btrfs_remove_ordered_extentagain. Below patch makes my test work but please double check.[ 185.776309] Pid: 3368, comm: btrfs-endio-wri Not tainted 2.6.33-rc8-00165-g446ce07 #668 0M017G/Studio Slim 540s [ 185.776353] RIP: 0010:[<ffffffffa000ca13>] [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.776427] RSP: 0018:ffff88012614bbd0 EFLAGS: 00010286 [ 185.776460] RAX: 00000000ffffffff RBX: ffff88012771c960 RCX: 0000000000000000 [ 185.776496] RDX: ffffffffa000c9dd RSI: ffff8801295d3800 RDI: 0000000000000001 [ 185.776532] RBP: ffff88012614bc00 R08: ffff88012614bb90 R09: 0000000000000000 [ 185.776568] R10: ffff88012614bbc0 R11: 0000000000000043 R12: ffff88012990a9b8 [ 185.776603] R13: 000000000001a000 R14: ffff88012990a900 R15: ffff88012771c950 [ 185.776640] FS: 0000000000000000(0000) GS:ffff880005880000(0000) knlGS:0000000000000000 [ 185.776678] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 185.776711] CR2: 0000003de9123f40 CR3: 00000001249b6000 CR4: 00000000000406e0 [ 185.776747] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 185.776795] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 185.776845] Process btrfs-endio-wri (pid: 3368, threadinfo ffff88012614a000, task ffff880128b34240) [ 185.776910] Stack: [ 185.776946] ffff88012614bbf0 ffff88012771c960 ffff8801249d4840 ffff88012771c7c0 [ 185.777050] <0> ffff88012771c950 0000000100000000 ffff88012614bc30 ffffffffa003559e [ 185.777203] <0> 0000000000000001 ffff8801249d4840 ffff88012771c960 0000000100000000 [ 185.777388] Call Trace: [ 185.777438] [<ffffffffa003559e>] __btrfs_remove_ordered_extent+0x72/0x126 [btrfs] [ 185.777511] [<ffffffffa003593f>] btrfs_ordered_update_i_size+0x2ed/0x33a [btrfs] [ 185.777585] [<ffffffffa0028c9e>] btrfs_finish_ordered_io+0x196/0x1d8 [btrfs] [ 185.777636] [<ffffffff810d39d1>] ? test_clear_page_writeback+0xfa/0x10c [ 185.777695] [<ffffffffa0028cfa>] btrfs_writepage_end_io_hook+0x1a/0x1c [btrfs] [ 185.777765] [<ffffffffa0039ef8>] end_bio_extent_writepage+0xae/0x159 [btrfs] [ 185.777815] [<ffffffff81130e56>] bio_endio+0x2b/0x2d [ 185.777868] [<ffffffffa001bcea>] end_workqueue_fn+0x111/0x120 [btrfs] [ 185.777923] [<ffffffffa00427e5>] worker_loop+0x1b9/0x547 [btrfs] [ 185.777977] [<ffffffffa004262c>] ? worker_loop+0x0/0x547 [btrfs] [ 185.778024] [<ffffffff8107f9b9>] kthread+0x7f/0x87 [ 185.778071] [<ffffffff8102f954>] kernel_thread_helper+0x4/0x10 [ 185.778119] [<ffffffff8105a8e1>] ? finish_task_switch+0x50/0xc2 [ 185.778166] [<ffffffff8161a5a9>] ? _raw_spin_unlock_irq+0x1b/0x36
Quoted 9 lines
[ 185.778212] [<ffffffff8161ae6d>] ? restore_args+0x0/0x30 [ 185.778257] [<ffffffff8107f93a>] ? kthread+0x0/0x87 [ 185.778300] [<ffffffff8102f950>] ? kernel_thread_helper+0x0/0x10 [ 185.778345] Code: 3b 43 f8 7f 12 4c 89 ff e8 cf db 60 e1 4c 89 e7 e8 c7 db 60 e1 eb 46 4c 89 ff e8 bd db 60 e1 8b 43 f4 ff c8 89 43 f4 85 c0 79 04 <0f> 0b eb fe 49 8b 46 48 4c 39 e8 73 0c 49 c7 46 48 00 00 00 00 [ 185.779620] RIP [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.779710] RSP <ffff88012614bbd0> [ 185.779765] ---[ end trace daf2ed048f53f7f0 ]--- [ 185.779812] note: btrfs-endio-wri[3368] exited with preempt_count
Are you tired of me emailing you yet :)? I've reproduced the problem, I'm testing a fix and I'll send it along to you when I think I've got it working. Thanks,
Josef
Quoted 38 lines · Shaohua Li
I got below oops when doing file write with mount option max_extent=1M It appears the accouting is already done in set/clear/split/merge hooks and I don't see reason why we need do accouting in
__btrfs_remove_ordered_extentagain. Below patch makes my test work but please double check.[ 185.776309] Pid: 3368, comm: btrfs-endio-wri Not tainted 2.6.33-rc8-00165-g446ce07 #668 0M017G/Studio Slim 540s [ 185.776353] RIP: 0010:[<ffffffffa000ca13>] [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.776427] RSP: 0018:ffff88012614bbd0 EFLAGS: 00010286 [ 185.776460] RAX: 00000000ffffffff RBX: ffff88012771c960 RCX: 0000000000000000 [ 185.776496] RDX: ffffffffa000c9dd RSI: ffff8801295d3800 RDI: 0000000000000001 [ 185.776532] RBP: ffff88012614bc00 R08: ffff88012614bb90 R09: 0000000000000000 [ 185.776568] R10: ffff88012614bbc0 R11: 0000000000000043 R12: ffff88012990a9b8 [ 185.776603] R13: 000000000001a000 R14: ffff88012990a900 R15: ffff88012771c950 [ 185.776640] FS: 0000000000000000(0000) GS:ffff880005880000(0000) knlGS:0000000000000000 [ 185.776678] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 185.776711] CR2: 0000003de9123f40 CR3: 00000001249b6000 CR4: 00000000000406e0 [ 185.776747] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 185.776795] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 185.776845] Process btrfs-endio-wri (pid: 3368, threadinfo ffff88012614a000, task ffff880128b34240) [ 185.776910] Stack: [ 185.776946] ffff88012614bbf0 ffff88012771c960 ffff8801249d4840 ffff88012771c7c0 [ 185.777050] <0> ffff88012771c950 0000000100000000 ffff88012614bc30 ffffffffa003559e [ 185.777203] <0> 0000000000000001 ffff8801249d4840 ffff88012771c960 0000000100000000 [ 185.777388] Call Trace: [ 185.777438] [<ffffffffa003559e>] __btrfs_remove_ordered_extent+0x72/0x126 [btrfs] [ 185.777511] [<ffffffffa003593f>] btrfs_ordered_update_i_size+0x2ed/0x33a [btrfs] [ 185.777585] [<ffffffffa0028c9e>] btrfs_finish_ordered_io+0x196/0x1d8 [btrfs] [ 185.777636] [<ffffffff810d39d1>] ? test_clear_page_writeback+0xfa/0x10c [ 185.777695] [<ffffffffa0028cfa>] btrfs_writepage_end_io_hook+0x1a/0x1c [btrfs] [ 185.777765] [<ffffffffa0039ef8>] end_bio_extent_writepage+0xae/0x159 [btrfs] [ 185.777815] [<ffffffff81130e56>] bio_endio+0x2b/0x2d [ 185.777868] [<ffffffffa001bcea>] end_workqueue_fn+0x111/0x120 [btrfs] [ 185.777923] [<ffffffffa00427e5>] worker_loop+0x1b9/0x547 [btrfs] [ 185.777977] [<ffffffffa004262c>] ? worker_loop+0x0/0x547 [btrfs] [ 185.778024] [<ffffffff8107f9b9>] kthread+0x7f/0x87 [ 185.778071] [<ffffffff8102f954>] kernel_thread_helper+0x4/0x10 [ 185.778119] [<ffffffff8105a8e1>] ? finish_task_switch+0x50/0xc2 [ 185.778166] [<ffffffff8161a5a9>] ? _raw_spin_unlock_irq+0x1b/0x36
Quoted 9 lines
[ 185.778212] [<ffffffff8161ae6d>] ? restore_args+0x0/0x30 [ 185.778257] [<ffffffff8107f93a>] ? kthread+0x0/0x87 [ 185.778300] [<ffffffff8102f950>] ? kernel_thread_helper+0x0/0x10 [ 185.778345] Code: 3b 43 f8 7f 12 4c 89 ff e8 cf db 60 e1 4c 89 e7 e8 c7 db 60 e1 eb 46 4c 89 ff e8 bd db 60 e1 8b 43 f4 ff c8 89 43 f4 85 c0 79 04 <0f> 0b eb fe 49 8b 46 48 4c 39 e8 73 0c 49 c7 46 48 00 00 00 00 [ 185.779620] RIP [<ffffffffa000ca13>] btrfs_unreserve_metadata_for_delalloc+0xc0/0x101 [btrfs] [ 185.779710] RSP <ffff88012614bbd0> [ 185.779765] ---[ end trace daf2ed048f53f7f0 ]--- [ 185.779812] note: btrfs-endio-wri[3368] exited with preempt_count
Ok here is my patch, but theres a catch. I've recently redone how we deal with metadata reservations for delalloc, but its not been pulled in yet. However I fixed the problem on top of that patch, and although its not needed for the fix, my fix wont apply properly without it. The other thing is theres a random patch in between the two of them. So here are 3 patches, 1 is needed because my fix is applied on the other one, and 1 isnt needed at all and was just there. Hopefully you will be able to apply this nice and cleanly against your tree and test it. If not let me know and I will move things around so you can just apply the fix itself. I've tested this pretty heavily locally and I think we're good, I'd just like to have more testing. Thanks,
Josef
fs/btrfs/ctree.h +11 -4
@@ -667,6 +667,13 @@ struct btrfs_block_group_item {__le64 flags; } __attribute__ ((__packed__)); +struct btrfs_reserved_space_pool { +u64 total_bytes; +u64 reserved_bytes; +u64 used_bytes; +spinlock_t lock; +}; +struct btrfs_space_info {u64 flags;
@@ -689,8 +696,6 @@ struct btrfs_space_info {chunks for this space */ int force_alloc;/* set if we need to force a chunk alloc for this space */ -int force_delalloc;/* make people start doing filemap_flush until -we're under a threshold */ struct list_head list;
@@ -985,6 +990,7 @@ struct btrfs_fs_info {unsigned metadata_ratio;void *bdev_holder; +struct btrfs_reserved_space_pool *reserved_space_pool; };/*
@@ -2049,9 +2055,9 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info);int btrfs_reserve_metadata_space (struct btrfs_root *root,int num_items);int btrfs_unreserve_metadata_space (struct btrfs_root *root,int num_items);int btrfs_unreserve_metadata_for_delalloc (struct btrfs_root *root, -struct inode *inode,int num_items); +struct inode *inode,u64 bytes);int btrfs_reserve_metadata_for_delalloc (struct btrfs_root *root, -struct inode *inode,int num_items); +struct inode *inode,u64 bytes);int btrfs_check_data_free_space (struct btrfs_root *root,struct inode *inode,u64 bytes); void btrfs_free_reserved_data_space(struct btrfs_root *root,
@@ -2060,6 +2066,7 @@ void btrfs_delalloc_reserve_space(struct btrfs_root *root, struct inode *inode, u64 bytes);void btrfs_delalloc_free_space (struct btrfs_root *root,struct inode *inode,u64 bytes); +void btrfs_init_space_pools (struct btrfs_fs_info *fs_info);/* ctree.c */ int btrfs_bin_search (struct extent_buffer *eb,struct btrfs_key *key,int level,int *slot);
fs/btrfs/disk-io.c +17 -0
@@ -1521,6 +1521,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,struct btrfs_root *log_tree_root;int ret; +int i;int err = -EINVAL ;struct btrfs_super_block *disk_super;
@@ -1866,8 +1867,23 @@ struct btrfs_root *open_ctree(struct super_block *sb, csum_root->track_dirty =1 ; + fs_info->reserved_space_pool = + alloc_percpu(struct btrfs_reserved_space_pool); +if (!fs_info->reserved_space_pool) + goto fail_csum_root; + +for_each_possible_cpu (i) { +struct btrfs_reserved_space_pool *pool; + pool =per_cpu_ptr (fs_info->reserved_space_pool, i); +spin_lock_init (&pool->lock); + pool->total_bytes =0 ; + pool->reserved_bytes =0 ; + pool->used_bytes =0 ; + } +btrfs_read_block_groups (extent_root); +btrfs_init_space_pools (fs_info); fs_info->generation = generation; fs_info->last_trans_committed = generation; fs_info->data_alloc_profile = (u64)-1 ;
@@ -2403,6 +2419,7 @@ int close_ctree(struct btrfs_root *root)free_extent_buffer (root->fs_info->csum_root->commit_root);btrfs_free_block_groups (root->fs_info); +free_percpu (fs_info->reserved_space_pool);del_fs_roots (fs_info);
fs/btrfs/extent-tree.c +424 -149
743 lines not on this page · raw message
fs/btrfs/file.c +2 -2
@@ -853,7 +853,7 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,/* do the reserve before the mutex lock in case we have to do some * flushing. We wouldn't deadlock, but this is more polite. */ - err =btrfs_reserve_metadata_for_delalloc (root, inode,1 ); + err =btrfs_reserve_metadata_for_delalloc (root, inode, count);if (err) goto out_nolock;
@@ -973,7 +973,7 @@ out:mutex_unlock (&inode->i_mutex);if (ret) err = ret; -btrfs_unreserve_metadata_for_delalloc (root, inode,1 ); +btrfs_unreserve_metadata_for_delalloc (root, inode, count); out_nolock:kfree (pages);
fs/btrfs/inode.c +71 -28
176 lines not on this page · raw message
fs/btrfs/ioctl.c +45 -0
57 lines not on this page · raw message
fs/btrfs/ioctl.h +14 -0
@@ -36,6 +36,18 @@ struct btrfs_ioctl_clone_range_args {__u64 dest_offset; }; +struct btrfs_ioctl_space_info { +u32 flags; +u64 total_bytes; +u64 used_bytes; +}; + +struct btrfs_ioctl_space_args { +u64 space_slots; +u64 total_spaces; +struct btrfs_ioctl_space_info spaces[0 ]; +}; +#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -67,4 +79,6 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 18, \ + struct btrfs_ioctl_space_args)#endif
fs/btrfs/ordered-data.c +16 -5
@@ -303,7 +303,9 @@ static int __btrfs_remove_ordered_extent(struct inode *inode, struct btrfs_ordered_extent *entry) {struct btrfs_ordered_inode_tree *tree; +struct btrfs_root *root =BTRFS_I (inode)->root;struct rb_node *node; +int bug =0 ; tree = &BTRFS_I (inode)->ordered_tree; node = &entry->rb_node;
@@ -311,13 +313,22 @@ static int __btrfs_remove_ordered_extent(struct inode *inode, tree->last =NULL ;set_bit (BTRFS_ORDERED_COMPLETE , &entry->flags); +/* +* Since we limit ordered extents to root->max_extent we can just +* subtract 1 from outstanding extents, and send max_extent to +* unreserve_metadata_for_delalloc and everything will be a-ok. +*/ spin_lock (&BTRFS_I (inode)->accounting_lock); -BTRFS_I (inode)->outstanding_extents--; +if (BTRFS_I (inode)->outstanding_extents) +BTRFS_I (inode)->outstanding_extents--; +else + bug =1 ;spin_unlock (&BTRFS_I (inode)->accounting_lock); -btrfs_unreserve_metadata_for_delalloc (BTRFS_I (inode)->root, - inode,1 ); +BUG_ON (bug); +btrfs_unreserve_metadata_for_delalloc (root, inode, + root->fs_info->max_extent); -spin_lock (&BTRFS_I (inode)->root->fs_info->ordered_extent_lock); +spin_lock (&root->fs_info->ordered_extent_lock);list_del_init (&entry->root_extent_list);/*
@@ -329,7 +340,7 @@ static int __btrfs_remove_ordered_extent(struct inode *inode, !mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY)) {list_del_init (&BTRFS_I (inode)->ordered_operations); } -spin_unlock (&BTRFS_I (inode)->root->fs_info->ordered_extent_lock); +spin_unlock (&root->fs_info->ordered_extent_lock);return 0 ; }
fs/btrfs/transaction.c +2 -0
@@ -1060,6 +1060,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,btrfs_prepare_extent_commit (trans, root); +btrfs_init_space_pools (root->fs_info); + cur_trans = root->fs_info->running_transaction;spin_lock (&root->fs_info->new_trans_lock); root->fs_info->running_transaction =NULL ;