Commit 7d345aa
ext4: fix largest free orders lists corruption on mb_optimize_scan switch
The grp->bb_largest_free_order is updated regardless of whether
mb_optimize_scan is enabled. This can lead to inconsistencies between
grp->bb_largest_free_order and the actual s_mb_largest_free_orders list
index when mb_optimize_scan is repeatedly enabled and disabled via remount.
For example, if mb_optimize_scan is initially enabled, largest free
order is 3, and the group is in s_mb_largest_free_orders[3]. Then,
mb_optimize_scan is disabled via remount, block allocations occur,
updating largest free order to 2. Finally, mb_optimize_scan is re-enabled
via remount, more block allocations update largest free order to 1.
At this point, the group would be removed from s_mb_largest_free_orders[3]
under the protection of s_mb_largest_free_orders_locks[2]. This lock
mismatch can lead to list corruption.
To fix this, whenever grp->bb_largest_free_order changes, we now always
attempt to remove the group from its old order list. However, we only
insert the group into the new order list if `mb_optimize_scan` is enabled.
This approach helps prevent lock inconsistencies and ensures the data in
the order lists remains reliable.
Fixes: 196e402 ("ext4: improve cr 0 / cr 1 group scanning")
CC: [email protected]
Suggested-by: Jan Kara <[email protected]>
Signed-off-by: Baokun Li <[email protected]>
Reviewed-by: Zhang Yi <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>1 parent 1c320d8 commit 7d345aa
1 file changed
+14
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1152 | 1152 | | |
1153 | 1153 | | |
1154 | 1154 | | |
1155 | | - | |
| 1155 | + | |
1156 | 1156 | | |
1157 | | - | |
1158 | | - | |
| 1157 | + | |
| 1158 | + | |
1159 | 1159 | | |
| 1160 | + | |
1160 | 1161 | | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
| 1162 | + | |
1164 | 1163 | | |
1165 | | - | |
1166 | 1164 | | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
| 1165 | + | |
| 1166 | + | |
1170 | 1167 | | |
1171 | | - | |
1172 | | - | |
| 1168 | + | |
1173 | 1169 | | |
1174 | | - | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
1178 | 1174 | | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
| 1175 | + | |
| 1176 | + | |
1182 | 1177 | | |
1183 | 1178 | | |
1184 | 1179 | | |
| |||
0 commit comments