diff options
Diffstat (limited to 'fs/btrfs/free-space-cache.c')
-rw-r--r-- | fs/btrfs/free-space-cache.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 1027b854b90c..59ea2e4349c9 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -307,7 +307,6 @@ static void io_ctl_unmap_page(struct io_ctl *io_ctl) | |||
307 | 307 | ||
308 | static void io_ctl_map_page(struct io_ctl *io_ctl, int clear) | 308 | static void io_ctl_map_page(struct io_ctl *io_ctl, int clear) |
309 | { | 309 | { |
310 | WARN_ON(io_ctl->cur); | ||
311 | BUG_ON(io_ctl->index >= io_ctl->num_pages); | 310 | BUG_ON(io_ctl->index >= io_ctl->num_pages); |
312 | io_ctl->page = io_ctl->pages[io_ctl->index++]; | 311 | io_ctl->page = io_ctl->pages[io_ctl->index++]; |
313 | io_ctl->cur = kmap(io_ctl->page); | 312 | io_ctl->cur = kmap(io_ctl->page); |
@@ -1250,18 +1249,13 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl, | |||
1250 | * if previous extent entry covers the offset, | 1249 | * if previous extent entry covers the offset, |
1251 | * we should return it instead of the bitmap entry | 1250 | * we should return it instead of the bitmap entry |
1252 | */ | 1251 | */ |
1253 | n = &entry->offset_index; | 1252 | n = rb_prev(&entry->offset_index); |
1254 | while (1) { | 1253 | if (n) { |
1255 | n = rb_prev(n); | ||
1256 | if (!n) | ||
1257 | break; | ||
1258 | prev = rb_entry(n, struct btrfs_free_space, | 1254 | prev = rb_entry(n, struct btrfs_free_space, |
1259 | offset_index); | 1255 | offset_index); |
1260 | if (!prev->bitmap) { | 1256 | if (!prev->bitmap && |
1261 | if (prev->offset + prev->bytes > offset) | 1257 | prev->offset + prev->bytes > offset) |
1262 | entry = prev; | 1258 | entry = prev; |
1263 | break; | ||
1264 | } | ||
1265 | } | 1259 | } |
1266 | } | 1260 | } |
1267 | return entry; | 1261 | return entry; |
@@ -1287,18 +1281,13 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl, | |||
1287 | } | 1281 | } |
1288 | 1282 | ||
1289 | if (entry->bitmap) { | 1283 | if (entry->bitmap) { |
1290 | n = &entry->offset_index; | 1284 | n = rb_prev(&entry->offset_index); |
1291 | while (1) { | 1285 | if (n) { |
1292 | n = rb_prev(n); | ||
1293 | if (!n) | ||
1294 | break; | ||
1295 | prev = rb_entry(n, struct btrfs_free_space, | 1286 | prev = rb_entry(n, struct btrfs_free_space, |
1296 | offset_index); | 1287 | offset_index); |
1297 | if (!prev->bitmap) { | 1288 | if (!prev->bitmap && |
1298 | if (prev->offset + prev->bytes > offset) | 1289 | prev->offset + prev->bytes > offset) |
1299 | return prev; | 1290 | return prev; |
1300 | break; | ||
1301 | } | ||
1302 | } | 1291 | } |
1303 | if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset) | 1292 | if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset) |
1304 | return entry; | 1293 | return entry; |
@@ -1364,7 +1353,7 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) | |||
1364 | u64 bitmap_bytes; | 1353 | u64 bitmap_bytes; |
1365 | u64 extent_bytes; | 1354 | u64 extent_bytes; |
1366 | u64 size = block_group->key.offset; | 1355 | u64 size = block_group->key.offset; |
1367 | u64 bytes_per_bg = BITS_PER_BITMAP * block_group->sectorsize; | 1356 | u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; |
1368 | int max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg); | 1357 | int max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg); |
1369 | 1358 | ||
1370 | BUG_ON(ctl->total_bitmaps > max_bitmaps); | 1359 | BUG_ON(ctl->total_bitmaps > max_bitmaps); |
@@ -1650,8 +1639,7 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl, | |||
1650 | * some block groups are so tiny they can't be enveloped by a bitmap, so | 1639 | * some block groups are so tiny they can't be enveloped by a bitmap, so |
1651 | * don't even bother to create a bitmap for this | 1640 | * don't even bother to create a bitmap for this |
1652 | */ | 1641 | */ |
1653 | if (BITS_PER_BITMAP * block_group->sectorsize > | 1642 | if (BITS_PER_BITMAP * ctl->unit > block_group->key.offset) |
1654 | block_group->key.offset) | ||
1655 | return false; | 1643 | return false; |
1656 | 1644 | ||
1657 | return true; | 1645 | return true; |
@@ -2298,10 +2286,10 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group, | |||
2298 | unsigned long total_found = 0; | 2286 | unsigned long total_found = 0; |
2299 | int ret; | 2287 | int ret; |
2300 | 2288 | ||
2301 | i = offset_to_bit(entry->offset, block_group->sectorsize, | 2289 | i = offset_to_bit(entry->offset, ctl->unit, |
2302 | max_t(u64, offset, entry->offset)); | 2290 | max_t(u64, offset, entry->offset)); |
2303 | want_bits = bytes_to_bits(bytes, block_group->sectorsize); | 2291 | want_bits = bytes_to_bits(bytes, ctl->unit); |
2304 | min_bits = bytes_to_bits(min_bytes, block_group->sectorsize); | 2292 | min_bits = bytes_to_bits(min_bytes, ctl->unit); |
2305 | 2293 | ||
2306 | again: | 2294 | again: |
2307 | found_bits = 0; | 2295 | found_bits = 0; |
@@ -2325,23 +2313,22 @@ again: | |||
2325 | 2313 | ||
2326 | total_found += found_bits; | 2314 | total_found += found_bits; |
2327 | 2315 | ||
2328 | if (cluster->max_size < found_bits * block_group->sectorsize) | 2316 | if (cluster->max_size < found_bits * ctl->unit) |
2329 | cluster->max_size = found_bits * block_group->sectorsize; | 2317 | cluster->max_size = found_bits * ctl->unit; |
2330 | 2318 | ||
2331 | if (total_found < want_bits || cluster->max_size < cont1_bytes) { | 2319 | if (total_found < want_bits || cluster->max_size < cont1_bytes) { |
2332 | i = next_zero + 1; | 2320 | i = next_zero + 1; |
2333 | goto again; | 2321 | goto again; |
2334 | } | 2322 | } |
2335 | 2323 | ||
2336 | cluster->window_start = start * block_group->sectorsize + | 2324 | cluster->window_start = start * ctl->unit + entry->offset; |
2337 | entry->offset; | ||
2338 | rb_erase(&entry->offset_index, &ctl->free_space_offset); | 2325 | rb_erase(&entry->offset_index, &ctl->free_space_offset); |
2339 | ret = tree_insert_offset(&cluster->root, entry->offset, | 2326 | ret = tree_insert_offset(&cluster->root, entry->offset, |
2340 | &entry->offset_index, 1); | 2327 | &entry->offset_index, 1); |
2341 | BUG_ON(ret); /* -EEXIST; Logic error */ | 2328 | BUG_ON(ret); /* -EEXIST; Logic error */ |
2342 | 2329 | ||
2343 | trace_btrfs_setup_cluster(block_group, cluster, | 2330 | trace_btrfs_setup_cluster(block_group, cluster, |
2344 | total_found * block_group->sectorsize, 1); | 2331 | total_found * ctl->unit, 1); |
2345 | return 0; | 2332 | return 0; |
2346 | } | 2333 | } |
2347 | 2334 | ||