Commit bc2dbc4
btrfs: avoid page_lockend underflow in btrfs_punch_hole_lock_range()
[BUG]
When running btrfs/004 with 4K fs block size and 64K page size,
sometimes fsstress workload can take 100% CPU for a while, but not long
enough to trigger a 120s hang warning.
[CAUSE]
When such 100% CPU usage happens, btrfs_punch_hole_lock_range() is
always in the call trace.
One example when this problem happens, the function
btrfs_punch_hole_lock_range() got the following parameters:
lock_start = 4096, lockend = 20469
Then we calculate @page_lockstart by rounding up lock_start to page
boundary, which is 64K (page size is 64K).
For @page_lockend, we round down the value towards page boundary, which
result 0. Then since we need to pass an inclusive end to
filemap_range_has_page(), we subtract 1 from the rounded down value,
resulting in (u64)-1.
In the above case, the range is inside the same page, and we do not even
need to call filemap_range_has_page(), not to mention to call it with
(u64)-1 at the end.
This behavior will cause btrfs_punch_hole_lock_range() to busy loop
waiting for irrelevant range to have its pages dropped.
[FIX]
Calculate @page_lockend by just rounding down @LockEnd, without
decreasing the value by one. So @page_lockend will no longer overflow.
Then exit early if @page_lockend is no larger than @page_lockstart.
As it means either the range is inside the same page, or the two pages
are adjacent already.
Finally only decrease @page_lockend when calling filemap_range_has_page().
Fixes: 0528476 ("btrfs: fix the filemap_range_has_page() call in btrfs_punch_hole_lock_range()")
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>1 parent cf6ae7e commit bc2dbc4
1 file changed
+7
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2104 | 2104 | | |
2105 | 2105 | | |
2106 | 2106 | | |
| 2107 | + | |
| 2108 | + | |
2107 | 2109 | | |
2108 | 2110 | | |
2109 | | - | |
| 2111 | + | |
2110 | 2112 | | |
2111 | 2113 | | |
2112 | 2114 | | |
2113 | 2115 | | |
2114 | 2116 | | |
2115 | 2117 | | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
2116 | 2121 | | |
2117 | 2122 | | |
2118 | 2123 | | |
| |||
2124 | 2129 | | |
2125 | 2130 | | |
2126 | 2131 | | |
2127 | | - | |
| 2132 | + | |
2128 | 2133 | | |
2129 | 2134 | | |
2130 | 2135 | | |
| |||
0 commit comments