Lines Matching refs:ctl
34 static int link_free_space(struct btrfs_free_space_ctl *ctl,
36 static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
631 static void merge_space_tree(struct btrfs_free_space_ctl *ctl) in merge_space_tree() argument
637 spin_lock(&ctl->tree_lock); in merge_space_tree()
638 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { in merge_space_tree()
645 unlink_free_space(ctl, prev); in merge_space_tree()
646 unlink_free_space(ctl, e); in merge_space_tree()
649 link_free_space(ctl, prev); in merge_space_tree()
651 spin_unlock(&ctl->tree_lock); in merge_space_tree()
657 spin_unlock(&ctl->tree_lock); in merge_space_tree()
661 struct btrfs_free_space_ctl *ctl, in __load_free_space_cache() argument
756 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
757 ret = link_free_space(ctl, e); in __load_free_space_cache()
758 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
775 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
776 ret = link_free_space(ctl, e); in __load_free_space_cache()
777 ctl->total_bitmaps++; in __load_free_space_cache()
778 ctl->op->recalc_thresholds(ctl); in __load_free_space_cache()
779 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
806 merge_space_tree(ctl); in __load_free_space_cache()
813 __btrfs_remove_free_space_cache(ctl); in __load_free_space_cache()
820 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in load_free_space_cache() local
878 ret = __load_free_space_cache(fs_info->tree_root, inode, ctl, in load_free_space_cache()
884 spin_lock(&ctl->tree_lock); in load_free_space_cache()
885 matched = (ctl->free_space == (block_group->key.offset - used - in load_free_space_cache()
887 spin_unlock(&ctl->tree_lock); in load_free_space_cache()
890 __btrfs_remove_free_space_cache(ctl); in load_free_space_cache()
915 struct btrfs_free_space_ctl *ctl, in write_cache_extent_entries() argument
923 struct rb_node *node = rb_first(&ctl->free_space_offset); in write_cache_extent_entries()
975 list_for_each_entry(trim_entry, &ctl->trimming_ranges, list) { in write_cache_extent_entries()
1233 struct btrfs_free_space_ctl *ctl, in __btrfs_write_out_cache() argument
1278 mutex_lock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1280 spin_lock(&ctl->tree_lock); in __btrfs_write_out_cache()
1281 ret = write_cache_extent_entries(io_ctl, ctl, in __btrfs_write_out_cache()
1305 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1306 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1358 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1359 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1376 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_write_out_cache() local
1391 ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl, in btrfs_write_out_cache()
1428 static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl, in offset_to_bitmap() argument
1434 bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; in offset_to_bitmap()
1435 bitmap_start = offset - ctl->start; in offset_to_bitmap()
1438 bitmap_start += ctl->start; in offset_to_bitmap()
1502 tree_search_offset(struct btrfs_free_space_ctl *ctl, in tree_search_offset() argument
1505 struct rb_node *n = ctl->free_space_offset.rb_node; in tree_search_offset()
1591 if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset) in tree_search_offset()
1602 ctl->unit > offset) in tree_search_offset()
1618 __unlink_free_space(struct btrfs_free_space_ctl *ctl, in __unlink_free_space() argument
1621 rb_erase(&info->offset_index, &ctl->free_space_offset); in __unlink_free_space()
1622 ctl->free_extents--; in __unlink_free_space()
1625 static void unlink_free_space(struct btrfs_free_space_ctl *ctl, in unlink_free_space() argument
1628 __unlink_free_space(ctl, info); in unlink_free_space()
1629 ctl->free_space -= info->bytes; in unlink_free_space()
1632 static int link_free_space(struct btrfs_free_space_ctl *ctl, in link_free_space() argument
1638 ret = tree_insert_offset(&ctl->free_space_offset, info->offset, in link_free_space()
1643 ctl->free_space += info->bytes; in link_free_space()
1644 ctl->free_extents++; in link_free_space()
1648 static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) in recalculate_thresholds() argument
1650 struct btrfs_block_group_cache *block_group = ctl->private; in recalculate_thresholds()
1655 u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; in recalculate_thresholds()
1660 ASSERT(ctl->total_bitmaps <= max_bitmaps); in recalculate_thresholds()
1677 bitmap_bytes = (ctl->total_bitmaps + 1) * ctl->unit; in recalculate_thresholds()
1680 ctl->extents_thresh = 0; in recalculate_thresholds()
1691 ctl->extents_thresh = in recalculate_thresholds()
1695 static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in __bitmap_clear_bits() argument
1701 start = offset_to_bit(info->offset, ctl->unit, offset); in __bitmap_clear_bits()
1702 count = bytes_to_bits(bytes, ctl->unit); in __bitmap_clear_bits()
1708 if (info->max_extent_size > ctl->unit) in __bitmap_clear_bits()
1712 static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in bitmap_clear_bits() argument
1716 __bitmap_clear_bits(ctl, info, offset, bytes); in bitmap_clear_bits()
1717 ctl->free_space -= bytes; in bitmap_clear_bits()
1720 static void bitmap_set_bits(struct btrfs_free_space_ctl *ctl, in bitmap_set_bits() argument
1726 start = offset_to_bit(info->offset, ctl->unit, offset); in bitmap_set_bits()
1727 count = bytes_to_bits(bytes, ctl->unit); in bitmap_set_bits()
1733 ctl->free_space += bytes; in bitmap_set_bits()
1740 static int search_bitmap(struct btrfs_free_space_ctl *ctl, in search_bitmap() argument
1761 i = offset_to_bit(bitmap_info->offset, ctl->unit, in search_bitmap()
1763 bits = bytes_to_bits(*bytes, ctl->unit); in search_bitmap()
1783 *offset = (u64)(i * ctl->unit) + bitmap_info->offset; in search_bitmap()
1784 *bytes = (u64)(found_bits) * ctl->unit; in search_bitmap()
1788 *bytes = (u64)(max_bits) * ctl->unit; in search_bitmap()
1802 find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, in find_free_space() argument
1811 if (!ctl->free_space_offset.rb_node) in find_free_space()
1814 entry = tree_search_offset(ctl, offset_to_bitmap(ctl, *offset), 0, 1); in find_free_space()
1830 tmp = entry->offset - ctl->start + align - 1; in find_free_space()
1832 tmp = tmp * align + ctl->start; in find_free_space()
1848 ret = search_bitmap(ctl, entry, &tmp, &size, true); in find_free_space()
1869 static void add_new_bitmap(struct btrfs_free_space_ctl *ctl, in add_new_bitmap() argument
1872 info->offset = offset_to_bitmap(ctl, offset); in add_new_bitmap()
1875 link_free_space(ctl, info); in add_new_bitmap()
1876 ctl->total_bitmaps++; in add_new_bitmap()
1878 ctl->op->recalc_thresholds(ctl); in add_new_bitmap()
1881 static void free_bitmap(struct btrfs_free_space_ctl *ctl, in free_bitmap() argument
1884 unlink_free_space(ctl, bitmap_info); in free_bitmap()
1887 ctl->total_bitmaps--; in free_bitmap()
1888 ctl->op->recalc_thresholds(ctl); in free_bitmap()
1891 static noinline int remove_from_bitmap(struct btrfs_free_space_ctl *ctl, in remove_from_bitmap() argument
1900 end = bitmap_info->offset + (u64)(BITS_PER_BITMAP * ctl->unit) - 1; in remove_from_bitmap()
1909 search_bytes = ctl->unit; in remove_from_bitmap()
1911 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes, in remove_from_bitmap()
1922 bitmap_clear_bits(ctl, bitmap_info, search_start, search_bytes); in remove_from_bitmap()
1929 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
1955 search_bytes = ctl->unit; in remove_from_bitmap()
1956 ret = search_bitmap(ctl, bitmap_info, &search_start, in remove_from_bitmap()
1963 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
1968 static u64 add_bytes_to_bitmap(struct btrfs_free_space_ctl *ctl, in add_bytes_to_bitmap() argument
1975 end = info->offset + (u64)(BITS_PER_BITMAP * ctl->unit); in add_bytes_to_bitmap()
1979 bitmap_set_bits(ctl, info, offset, bytes_to_set); in add_bytes_to_bitmap()
1991 static bool use_bitmap(struct btrfs_free_space_ctl *ctl, in use_bitmap() argument
1994 struct btrfs_block_group_cache *block_group = ctl->private; in use_bitmap()
2007 if (!forced && ctl->free_extents < ctl->extents_thresh) { in use_bitmap()
2016 if (ctl->free_extents * 2 <= ctl->extents_thresh) in use_bitmap()
2031 if (((BITS_PER_BITMAP * ctl->unit) >> 1) > block_group->key.offset) in use_bitmap()
2042 static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl, in insert_into_bitmap() argument
2054 if (!ctl->op->use_bitmap(ctl, info)) in insert_into_bitmap()
2057 if (ctl->op == &free_space_op) in insert_into_bitmap()
2058 block_group = ctl->private; in insert_into_bitmap()
2086 if (entry->offset == offset_to_bitmap(ctl, offset)) { in insert_into_bitmap()
2087 bytes_added = add_bytes_to_bitmap(ctl, entry, in insert_into_bitmap()
2100 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in insert_into_bitmap()
2107 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes); in insert_into_bitmap()
2120 add_new_bitmap(ctl, info, offset); in insert_into_bitmap()
2125 spin_unlock(&ctl->tree_lock); in insert_into_bitmap()
2132 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2141 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2160 static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, in try_merge_free_space() argument
2174 right_info = tree_search_offset(ctl, offset + bytes, 0, 0); in try_merge_free_space()
2179 left_info = tree_search_offset(ctl, offset - 1, 0, 0); in try_merge_free_space()
2183 unlink_free_space(ctl, right_info); in try_merge_free_space()
2185 __unlink_free_space(ctl, right_info); in try_merge_free_space()
2194 unlink_free_space(ctl, left_info); in try_merge_free_space()
2196 __unlink_free_space(ctl, left_info); in try_merge_free_space()
2206 static bool steal_from_bitmap_to_end(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_end() argument
2214 const u64 bitmap_offset = offset_to_bitmap(ctl, end); in steal_from_bitmap_to_end()
2217 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_end()
2221 i = offset_to_bit(bitmap->offset, ctl->unit, end); in steal_from_bitmap_to_end()
2225 bytes = (j - i) * ctl->unit; in steal_from_bitmap_to_end()
2229 bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2231 __bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2234 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_end()
2239 static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_front() argument
2250 bitmap_offset = offset_to_bitmap(ctl, info->offset); in steal_from_bitmap_to_front()
2255 bitmap_offset = offset_to_bitmap(ctl, info->offset - 1); in steal_from_bitmap_to_front()
2258 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_front()
2262 i = offset_to_bit(bitmap->offset, ctl->unit, info->offset) - 1; in steal_from_bitmap_to_front()
2274 bytes = (i + 1) * ctl->unit; in steal_from_bitmap_to_front()
2276 bytes = (i - prev_j) * ctl->unit; in steal_from_bitmap_to_front()
2282 bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2284 __bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2287 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_front()
2303 static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap() argument
2314 if (ctl->total_bitmaps > 0) { in steal_from_bitmap()
2318 stole_end = steal_from_bitmap_to_end(ctl, info, update_stat); in steal_from_bitmap()
2319 if (ctl->total_bitmaps > 0) in steal_from_bitmap()
2320 stole_front = steal_from_bitmap_to_front(ctl, info, in steal_from_bitmap()
2324 try_merge_free_space(ctl, info, update_stat); in steal_from_bitmap()
2329 struct btrfs_free_space_ctl *ctl, in __btrfs_add_free_space() argument
2343 spin_lock(&ctl->tree_lock); in __btrfs_add_free_space()
2345 if (try_merge_free_space(ctl, info, true)) in __btrfs_add_free_space()
2353 ret = insert_into_bitmap(ctl, info); in __btrfs_add_free_space()
2367 steal_from_bitmap(ctl, info, true); in __btrfs_add_free_space()
2369 ret = link_free_space(ctl, info); in __btrfs_add_free_space()
2373 spin_unlock(&ctl->tree_lock); in __btrfs_add_free_space()
2394 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space() local
2399 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space()
2406 info = tree_search_offset(ctl, offset, 0, 0); in btrfs_remove_free_space()
2412 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in btrfs_remove_free_space()
2427 unlink_free_space(ctl, info); in btrfs_remove_free_space()
2434 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2447 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2461 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2470 ret = remove_from_bitmap(ctl, info, &offset, &bytes); in btrfs_remove_free_space()
2476 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2485 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_dump_free_space() local
2490 spin_lock(&ctl->tree_lock); in btrfs_dump_free_space()
2491 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { in btrfs_dump_free_space()
2499 spin_unlock(&ctl->tree_lock); in btrfs_dump_free_space()
2509 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_init_free_space_ctl() local
2511 spin_lock_init(&ctl->tree_lock); in btrfs_init_free_space_ctl()
2512 ctl->unit = fs_info->sectorsize; in btrfs_init_free_space_ctl()
2513 ctl->start = block_group->key.objectid; in btrfs_init_free_space_ctl()
2514 ctl->private = block_group; in btrfs_init_free_space_ctl()
2515 ctl->op = &free_space_op; in btrfs_init_free_space_ctl()
2516 INIT_LIST_HEAD(&ctl->trimming_ranges); in btrfs_init_free_space_ctl()
2517 mutex_init(&ctl->cache_writeout_mutex); in btrfs_init_free_space_ctl()
2524 ctl->extents_thresh = (SZ_32K / 2) / sizeof(struct btrfs_free_space); in btrfs_init_free_space_ctl()
2538 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in __btrfs_return_cluster_to_free_space() local
2561 try_merge_free_space(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2562 steal_from_bitmap(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2564 tree_insert_offset(&ctl->free_space_offset, in __btrfs_return_cluster_to_free_space()
2576 struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache_locked() argument
2581 while ((node = rb_last(&ctl->free_space_offset)) != NULL) { in __btrfs_remove_free_space_cache_locked()
2584 unlink_free_space(ctl, info); in __btrfs_remove_free_space_cache_locked()
2587 free_bitmap(ctl, info); in __btrfs_remove_free_space_cache_locked()
2590 cond_resched_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache_locked()
2594 void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache() argument
2596 spin_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2597 __btrfs_remove_free_space_cache_locked(ctl); in __btrfs_remove_free_space_cache()
2598 spin_unlock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2603 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space_cache() local
2607 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2616 cond_resched_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2618 __btrfs_remove_free_space_cache_locked(ctl); in btrfs_remove_free_space_cache()
2619 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2627 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_for_alloc() local
2634 spin_lock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2635 entry = find_free_space(ctl, &offset, &bytes_search, in btrfs_find_space_for_alloc()
2642 bitmap_clear_bits(ctl, entry, offset, bytes); in btrfs_find_space_for_alloc()
2644 free_bitmap(ctl, entry); in btrfs_find_space_for_alloc()
2646 unlink_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2657 link_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2660 spin_unlock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2663 __btrfs_add_free_space(block_group->fs_info, ctl, in btrfs_find_space_for_alloc()
2680 struct btrfs_free_space_ctl *ctl; in btrfs_return_cluster_to_free_space() local
2699 ctl = block_group->free_space_ctl; in btrfs_return_cluster_to_free_space()
2702 spin_lock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
2704 spin_unlock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
2717 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_bitmap() local
2726 err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); in btrfs_alloc_from_bitmap()
2734 __bitmap_clear_bits(ctl, entry, ret, bytes); in btrfs_alloc_from_bitmap()
2748 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_cluster() local
2811 spin_lock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
2813 ctl->free_space -= bytes; in btrfs_alloc_from_cluster()
2815 ctl->free_extents--; in btrfs_alloc_from_cluster()
2819 ctl->total_bitmaps--; in btrfs_alloc_from_cluster()
2820 ctl->op->recalc_thresholds(ctl); in btrfs_alloc_from_cluster()
2825 spin_unlock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
2836 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_bitmap_cluster() local
2847 i = offset_to_bit(entry->offset, ctl->unit, in btrfs_bitmap_cluster()
2849 want_bits = bytes_to_bits(bytes, ctl->unit); in btrfs_bitmap_cluster()
2850 min_bits = bytes_to_bits(min_bytes, ctl->unit); in btrfs_bitmap_cluster()
2876 entry->max_extent_size = (u64)max_bits * ctl->unit; in btrfs_bitmap_cluster()
2887 if (cluster->max_size < found_bits * ctl->unit) in btrfs_bitmap_cluster()
2888 cluster->max_size = found_bits * ctl->unit; in btrfs_bitmap_cluster()
2895 cluster->window_start = start * ctl->unit + entry->offset; in btrfs_bitmap_cluster()
2896 rb_erase(&entry->offset_index, &ctl->free_space_offset); in btrfs_bitmap_cluster()
2902 total_found * ctl->unit, 1); in btrfs_bitmap_cluster()
2917 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_no_bitmap() local
2926 entry = tree_search_offset(ctl, offset, 0, 1); in setup_cluster_no_bitmap()
2986 rb_erase(&entry->offset_index, &ctl->free_space_offset); in setup_cluster_no_bitmap()
3008 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_bitmap() local
3011 u64 bitmap_offset = offset_to_bitmap(ctl, offset); in setup_cluster_bitmap()
3013 if (ctl->total_bitmaps == 0) in setup_cluster_bitmap()
3024 entry = tree_search_offset(ctl, bitmap_offset, 1, 0); in setup_cluster_bitmap()
3058 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_cluster() local
3081 spin_lock(&ctl->tree_lock); in btrfs_find_space_cluster()
3087 if (ctl->free_space < bytes) { in btrfs_find_space_cluster()
3088 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3125 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3151 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in do_trimming() local
3170 mutex_lock(&ctl->cache_writeout_mutex); in do_trimming()
3173 mutex_unlock(&ctl->cache_writeout_mutex); in do_trimming()
3192 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_no_bitmap() local
3203 mutex_lock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3204 spin_lock(&ctl->tree_lock); in trim_no_bitmap()
3206 if (ctl->free_space < minlen) { in trim_no_bitmap()
3207 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3208 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3212 entry = tree_search_offset(ctl, start, 0, 1); in trim_no_bitmap()
3214 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3215 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3223 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3224 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3232 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3233 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3242 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3243 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3247 unlink_free_space(ctl, entry); in trim_no_bitmap()
3250 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3253 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_no_bitmap()
3254 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3277 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_bitmaps() local
3282 u64 offset = offset_to_bitmap(ctl, start); in trim_bitmaps()
3288 mutex_lock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3289 spin_lock(&ctl->tree_lock); in trim_bitmaps()
3291 if (ctl->free_space < minlen) { in trim_bitmaps()
3292 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3293 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3297 entry = tree_search_offset(ctl, offset, 1, 0); in trim_bitmaps()
3299 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3300 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3306 ret2 = search_bitmap(ctl, entry, &start, &bytes, false); in trim_bitmaps()
3308 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3309 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3316 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3317 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3321 bitmap_clear_bits(ctl, entry, start, bytes); in trim_bitmaps()
3323 free_bitmap(ctl, entry); in trim_bitmaps()
3325 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3328 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_bitmaps()
3329 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3337 offset += BITS_PER_BITMAP * ctl->unit; in trim_bitmaps()
3340 if (start >= offset + BITS_PER_BITMAP * ctl->unit) in trim_bitmaps()
3341 offset += BITS_PER_BITMAP * ctl->unit; in trim_bitmaps()
3429 struct btrfs_free_space_ctl *ctl = fs_root->free_ino_ctl; in btrfs_find_ino_for_alloc() local
3433 spin_lock(&ctl->tree_lock); in btrfs_find_ino_for_alloc()
3435 if (RB_EMPTY_ROOT(&ctl->free_space_offset)) in btrfs_find_ino_for_alloc()
3438 entry = rb_entry(rb_first(&ctl->free_space_offset), in btrfs_find_ino_for_alloc()
3444 unlink_free_space(ctl, entry); in btrfs_find_ino_for_alloc()
3450 link_free_space(ctl, entry); in btrfs_find_ino_for_alloc()
3456 ret = search_bitmap(ctl, entry, &offset, &count, true); in btrfs_find_ino_for_alloc()
3461 bitmap_clear_bits(ctl, entry, offset, 1); in btrfs_find_ino_for_alloc()
3463 free_bitmap(ctl, entry); in btrfs_find_ino_for_alloc()
3466 spin_unlock(&ctl->tree_lock); in btrfs_find_ino_for_alloc()
3505 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in load_free_ino_cache() local
3532 ret = __load_free_space_cache(root, inode, ctl, path, 0); in load_free_ino_cache()
3551 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_write_out_ino_cache() local
3560 ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, trans); in btrfs_write_out_ino_cache()
3596 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_add_free_space_entry() local
3610 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
3614 ret = link_free_space(ctl, info); in test_add_free_space_entry()
3615 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
3629 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
3630 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_add_free_space_entry()
3635 add_new_bitmap(ctl, info, offset); in test_add_free_space_entry()
3640 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes); in test_add_free_space_entry()
3644 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
3664 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_check_exists() local
3668 spin_lock(&ctl->tree_lock); in test_check_exists()
3669 info = tree_search_offset(ctl, offset, 0, 0); in test_check_exists()
3671 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_check_exists()
3684 bit_bytes = ctl->unit; in test_check_exists()
3685 ret = search_bitmap(ctl, info, &bit_off, &bit_bytes, false); in test_check_exists()
3737 spin_unlock(&ctl->tree_lock); in test_check_exists()