Lines Matching refs:ctl

41 static int link_free_space(struct btrfs_free_space_ctl *ctl,
43 static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
639 static void merge_space_tree(struct btrfs_free_space_ctl *ctl) in merge_space_tree() argument
645 spin_lock(&ctl->tree_lock); in merge_space_tree()
646 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { in merge_space_tree()
653 unlink_free_space(ctl, prev); in merge_space_tree()
654 unlink_free_space(ctl, e); in merge_space_tree()
657 link_free_space(ctl, prev); in merge_space_tree()
659 spin_unlock(&ctl->tree_lock); in merge_space_tree()
665 spin_unlock(&ctl->tree_lock); in merge_space_tree()
669 struct btrfs_free_space_ctl *ctl, in __load_free_space_cache() argument
766 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
767 ret = link_free_space(ctl, e); in __load_free_space_cache()
768 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
784 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
785 ret = link_free_space(ctl, e); in __load_free_space_cache()
786 ctl->total_bitmaps++; in __load_free_space_cache()
787 ctl->op->recalc_thresholds(ctl); in __load_free_space_cache()
788 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
815 merge_space_tree(ctl); in __load_free_space_cache()
822 __btrfs_remove_free_space_cache(ctl); in __load_free_space_cache()
829 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in load_free_space_cache() local
869 ret = __load_free_space_cache(fs_info->tree_root, inode, ctl, in load_free_space_cache()
875 spin_lock(&ctl->tree_lock); in load_free_space_cache()
876 matched = (ctl->free_space == (block_group->key.offset - used - in load_free_space_cache()
878 spin_unlock(&ctl->tree_lock); in load_free_space_cache()
881 __btrfs_remove_free_space_cache(ctl); in load_free_space_cache()
904 struct btrfs_free_space_ctl *ctl, in write_cache_extent_entries() argument
912 struct rb_node *node = rb_first(&ctl->free_space_offset); in write_cache_extent_entries()
964 list_for_each_entry(trim_entry, &ctl->trimming_ranges, list) { in write_cache_extent_entries()
1222 struct btrfs_free_space_ctl *ctl, in __btrfs_write_out_cache() argument
1268 mutex_lock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1270 spin_lock(&ctl->tree_lock); in __btrfs_write_out_cache()
1271 ret = write_cache_extent_entries(io_ctl, ctl, in __btrfs_write_out_cache()
1295 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1296 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1348 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1349 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1365 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_write_out_cache() local
1382 ret = __btrfs_write_out_cache(root, inode, ctl, block_group, in btrfs_write_out_cache()
1420 static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl, in offset_to_bitmap() argument
1426 bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; in offset_to_bitmap()
1427 bitmap_start = offset - ctl->start; in offset_to_bitmap()
1430 bitmap_start += ctl->start; in offset_to_bitmap()
1494 tree_search_offset(struct btrfs_free_space_ctl *ctl, in tree_search_offset() argument
1497 struct rb_node *n = ctl->free_space_offset.rb_node; in tree_search_offset()
1583 if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset) in tree_search_offset()
1594 ctl->unit > offset) in tree_search_offset()
1610 __unlink_free_space(struct btrfs_free_space_ctl *ctl, in __unlink_free_space() argument
1613 rb_erase(&info->offset_index, &ctl->free_space_offset); in __unlink_free_space()
1614 ctl->free_extents--; in __unlink_free_space()
1617 static void unlink_free_space(struct btrfs_free_space_ctl *ctl, in unlink_free_space() argument
1620 __unlink_free_space(ctl, info); in unlink_free_space()
1621 ctl->free_space -= info->bytes; in unlink_free_space()
1624 static int link_free_space(struct btrfs_free_space_ctl *ctl, in link_free_space() argument
1630 ret = tree_insert_offset(&ctl->free_space_offset, info->offset, in link_free_space()
1635 ctl->free_space += info->bytes; in link_free_space()
1636 ctl->free_extents++; in link_free_space()
1640 static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) in recalculate_thresholds() argument
1642 struct btrfs_block_group_cache *block_group = ctl->private; in recalculate_thresholds()
1647 u32 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; in recalculate_thresholds()
1652 ASSERT(ctl->total_bitmaps <= max_bitmaps); in recalculate_thresholds()
1670 bitmap_bytes = (ctl->total_bitmaps + 1) * PAGE_CACHE_SIZE; in recalculate_thresholds()
1673 ctl->extents_thresh = 0; in recalculate_thresholds()
1684 ctl->extents_thresh = in recalculate_thresholds()
1688 static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in __bitmap_clear_bits() argument
1694 start = offset_to_bit(info->offset, ctl->unit, offset); in __bitmap_clear_bits()
1695 count = bytes_to_bits(bytes, ctl->unit); in __bitmap_clear_bits()
1703 static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in bitmap_clear_bits() argument
1707 __bitmap_clear_bits(ctl, info, offset, bytes); in bitmap_clear_bits()
1708 ctl->free_space -= bytes; in bitmap_clear_bits()
1711 static void bitmap_set_bits(struct btrfs_free_space_ctl *ctl, in bitmap_set_bits() argument
1717 start = offset_to_bit(info->offset, ctl->unit, offset); in bitmap_set_bits()
1718 count = bytes_to_bits(bytes, ctl->unit); in bitmap_set_bits()
1724 ctl->free_space += bytes; in bitmap_set_bits()
1731 static int search_bitmap(struct btrfs_free_space_ctl *ctl, in search_bitmap() argument
1752 i = offset_to_bit(bitmap_info->offset, ctl->unit, in search_bitmap()
1754 bits = bytes_to_bits(*bytes, ctl->unit); in search_bitmap()
1774 *offset = (u64)(i * ctl->unit) + bitmap_info->offset; in search_bitmap()
1775 *bytes = (u64)(found_bits) * ctl->unit; in search_bitmap()
1779 *bytes = (u64)(max_bits) * ctl->unit; in search_bitmap()
1786 find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, in find_free_space() argument
1795 if (!ctl->free_space_offset.rb_node) in find_free_space()
1798 entry = tree_search_offset(ctl, offset_to_bitmap(ctl, *offset), 0, 1); in find_free_space()
1814 tmp = entry->offset - ctl->start + align - 1; in find_free_space()
1816 tmp = tmp * align + ctl->start; in find_free_space()
1832 ret = search_bitmap(ctl, entry, &tmp, &size, true); in find_free_space()
1851 static void add_new_bitmap(struct btrfs_free_space_ctl *ctl, in add_new_bitmap() argument
1854 info->offset = offset_to_bitmap(ctl, offset); in add_new_bitmap()
1857 link_free_space(ctl, info); in add_new_bitmap()
1858 ctl->total_bitmaps++; in add_new_bitmap()
1860 ctl->op->recalc_thresholds(ctl); in add_new_bitmap()
1863 static void free_bitmap(struct btrfs_free_space_ctl *ctl, in free_bitmap() argument
1866 unlink_free_space(ctl, bitmap_info); in free_bitmap()
1869 ctl->total_bitmaps--; in free_bitmap()
1870 ctl->op->recalc_thresholds(ctl); in free_bitmap()
1873 static noinline int remove_from_bitmap(struct btrfs_free_space_ctl *ctl, in remove_from_bitmap() argument
1882 end = bitmap_info->offset + (u64)(BITS_PER_BITMAP * ctl->unit) - 1; in remove_from_bitmap()
1891 search_bytes = ctl->unit; in remove_from_bitmap()
1893 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes, in remove_from_bitmap()
1904 bitmap_clear_bits(ctl, bitmap_info, search_start, search_bytes); in remove_from_bitmap()
1911 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
1937 search_bytes = ctl->unit; in remove_from_bitmap()
1938 ret = search_bitmap(ctl, bitmap_info, &search_start, in remove_from_bitmap()
1945 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
1950 static u64 add_bytes_to_bitmap(struct btrfs_free_space_ctl *ctl, in add_bytes_to_bitmap() argument
1957 end = info->offset + (u64)(BITS_PER_BITMAP * ctl->unit); in add_bytes_to_bitmap()
1961 bitmap_set_bits(ctl, info, offset, bytes_to_set); in add_bytes_to_bitmap()
1973 static bool use_bitmap(struct btrfs_free_space_ctl *ctl, in use_bitmap() argument
1976 struct btrfs_block_group_cache *block_group = ctl->private; in use_bitmap()
1989 if (!forced && ctl->free_extents < ctl->extents_thresh) { in use_bitmap()
1998 if (ctl->free_extents * 2 <= ctl->extents_thresh) in use_bitmap()
2013 if (((BITS_PER_BITMAP * ctl->unit) >> 1) > block_group->key.offset) in use_bitmap()
2024 static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl, in insert_into_bitmap() argument
2036 if (!ctl->op->use_bitmap(ctl, info)) in insert_into_bitmap()
2039 if (ctl->op == &free_space_op) in insert_into_bitmap()
2040 block_group = ctl->private; in insert_into_bitmap()
2068 if (entry->offset == offset_to_bitmap(ctl, offset)) { in insert_into_bitmap()
2069 bytes_added = add_bytes_to_bitmap(ctl, entry, in insert_into_bitmap()
2082 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in insert_into_bitmap()
2089 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes); in insert_into_bitmap()
2102 add_new_bitmap(ctl, info, offset); in insert_into_bitmap()
2107 spin_unlock(&ctl->tree_lock); in insert_into_bitmap()
2114 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2122 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2140 static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, in try_merge_free_space() argument
2154 right_info = tree_search_offset(ctl, offset + bytes, 0, 0); in try_merge_free_space()
2159 left_info = tree_search_offset(ctl, offset - 1, 0, 0); in try_merge_free_space()
2163 unlink_free_space(ctl, right_info); in try_merge_free_space()
2165 __unlink_free_space(ctl, right_info); in try_merge_free_space()
2174 unlink_free_space(ctl, left_info); in try_merge_free_space()
2176 __unlink_free_space(ctl, left_info); in try_merge_free_space()
2186 static bool steal_from_bitmap_to_end(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_end() argument
2194 const u64 bitmap_offset = offset_to_bitmap(ctl, end); in steal_from_bitmap_to_end()
2197 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_end()
2201 i = offset_to_bit(bitmap->offset, ctl->unit, end); in steal_from_bitmap_to_end()
2205 bytes = (j - i) * ctl->unit; in steal_from_bitmap_to_end()
2209 bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2211 __bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2214 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_end()
2219 static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_front() argument
2230 bitmap_offset = offset_to_bitmap(ctl, info->offset); in steal_from_bitmap_to_front()
2235 bitmap_offset = offset_to_bitmap(ctl, info->offset - 1); in steal_from_bitmap_to_front()
2238 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_front()
2242 i = offset_to_bit(bitmap->offset, ctl->unit, info->offset) - 1; in steal_from_bitmap_to_front()
2254 bytes = (i + 1) * ctl->unit; in steal_from_bitmap_to_front()
2256 bytes = (i - prev_j) * ctl->unit; in steal_from_bitmap_to_front()
2262 bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2264 __bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2267 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_front()
2283 static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap() argument
2294 if (ctl->total_bitmaps > 0) { in steal_from_bitmap()
2298 stole_end = steal_from_bitmap_to_end(ctl, info, update_stat); in steal_from_bitmap()
2299 if (ctl->total_bitmaps > 0) in steal_from_bitmap()
2300 stole_front = steal_from_bitmap_to_front(ctl, info, in steal_from_bitmap()
2304 try_merge_free_space(ctl, info, update_stat); in steal_from_bitmap()
2308 int __btrfs_add_free_space(struct btrfs_free_space_ctl *ctl, in __btrfs_add_free_space() argument
2322 spin_lock(&ctl->tree_lock); in __btrfs_add_free_space()
2324 if (try_merge_free_space(ctl, info, true)) in __btrfs_add_free_space()
2332 ret = insert_into_bitmap(ctl, info); in __btrfs_add_free_space()
2346 steal_from_bitmap(ctl, info, true); in __btrfs_add_free_space()
2348 ret = link_free_space(ctl, info); in __btrfs_add_free_space()
2352 spin_unlock(&ctl->tree_lock); in __btrfs_add_free_space()
2365 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space() local
2370 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space()
2377 info = tree_search_offset(ctl, offset, 0, 0); in btrfs_remove_free_space()
2383 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in btrfs_remove_free_space()
2398 unlink_free_space(ctl, info); in btrfs_remove_free_space()
2405 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2418 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2432 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2441 ret = remove_from_bitmap(ctl, info, &offset, &bytes); in btrfs_remove_free_space()
2447 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2455 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_dump_free_space() local
2460 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { in btrfs_dump_free_space()
2477 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_init_free_space_ctl() local
2479 spin_lock_init(&ctl->tree_lock); in btrfs_init_free_space_ctl()
2480 ctl->unit = block_group->sectorsize; in btrfs_init_free_space_ctl()
2481 ctl->start = block_group->key.objectid; in btrfs_init_free_space_ctl()
2482 ctl->private = block_group; in btrfs_init_free_space_ctl()
2483 ctl->op = &free_space_op; in btrfs_init_free_space_ctl()
2484 INIT_LIST_HEAD(&ctl->trimming_ranges); in btrfs_init_free_space_ctl()
2485 mutex_init(&ctl->cache_writeout_mutex); in btrfs_init_free_space_ctl()
2492 ctl->extents_thresh = ((1024 * 32) / 2) / in btrfs_init_free_space_ctl()
2507 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in __btrfs_return_cluster_to_free_space() local
2530 try_merge_free_space(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2531 steal_from_bitmap(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2533 tree_insert_offset(&ctl->free_space_offset, in __btrfs_return_cluster_to_free_space()
2545 struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache_locked() argument
2550 while ((node = rb_last(&ctl->free_space_offset)) != NULL) { in __btrfs_remove_free_space_cache_locked()
2553 unlink_free_space(ctl, info); in __btrfs_remove_free_space_cache_locked()
2556 free_bitmap(ctl, info); in __btrfs_remove_free_space_cache_locked()
2559 cond_resched_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache_locked()
2563 void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache() argument
2565 spin_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2566 __btrfs_remove_free_space_cache_locked(ctl); in __btrfs_remove_free_space_cache()
2567 spin_unlock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2572 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space_cache() local
2576 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2585 cond_resched_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2587 __btrfs_remove_free_space_cache_locked(ctl); in btrfs_remove_free_space_cache()
2588 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2596 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_for_alloc() local
2603 spin_lock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2604 entry = find_free_space(ctl, &offset, &bytes_search, in btrfs_find_space_for_alloc()
2611 bitmap_clear_bits(ctl, entry, offset, bytes); in btrfs_find_space_for_alloc()
2613 free_bitmap(ctl, entry); in btrfs_find_space_for_alloc()
2615 unlink_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2626 link_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2629 spin_unlock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2632 __btrfs_add_free_space(ctl, align_gap, align_gap_len); in btrfs_find_space_for_alloc()
2648 struct btrfs_free_space_ctl *ctl; in btrfs_return_cluster_to_free_space() local
2667 ctl = block_group->free_space_ctl; in btrfs_return_cluster_to_free_space()
2670 spin_lock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
2672 spin_unlock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
2685 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_bitmap() local
2694 err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); in btrfs_alloc_from_bitmap()
2702 __bitmap_clear_bits(ctl, entry, ret, bytes); in btrfs_alloc_from_bitmap()
2716 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_cluster() local
2778 spin_lock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
2780 ctl->free_space -= bytes; in btrfs_alloc_from_cluster()
2782 ctl->free_extents--; in btrfs_alloc_from_cluster()
2785 ctl->total_bitmaps--; in btrfs_alloc_from_cluster()
2786 ctl->op->recalc_thresholds(ctl); in btrfs_alloc_from_cluster()
2791 spin_unlock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
2802 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_bitmap_cluster() local
2813 i = offset_to_bit(entry->offset, ctl->unit, in btrfs_bitmap_cluster()
2815 want_bits = bytes_to_bits(bytes, ctl->unit); in btrfs_bitmap_cluster()
2816 min_bits = bytes_to_bits(min_bytes, ctl->unit); in btrfs_bitmap_cluster()
2842 entry->max_extent_size = (u64)max_bits * ctl->unit; in btrfs_bitmap_cluster()
2853 if (cluster->max_size < found_bits * ctl->unit) in btrfs_bitmap_cluster()
2854 cluster->max_size = found_bits * ctl->unit; in btrfs_bitmap_cluster()
2861 cluster->window_start = start * ctl->unit + entry->offset; in btrfs_bitmap_cluster()
2862 rb_erase(&entry->offset_index, &ctl->free_space_offset); in btrfs_bitmap_cluster()
2868 total_found * ctl->unit, 1); in btrfs_bitmap_cluster()
2883 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_no_bitmap() local
2892 entry = tree_search_offset(ctl, offset, 0, 1); in setup_cluster_no_bitmap()
2952 rb_erase(&entry->offset_index, &ctl->free_space_offset); in setup_cluster_no_bitmap()
2974 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_bitmap() local
2977 u64 bitmap_offset = offset_to_bitmap(ctl, offset); in setup_cluster_bitmap()
2979 if (ctl->total_bitmaps == 0) in setup_cluster_bitmap()
2990 entry = tree_search_offset(ctl, bitmap_offset, 1, 0); in setup_cluster_bitmap()
3024 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_cluster() local
3047 spin_lock(&ctl->tree_lock); in btrfs_find_space_cluster()
3053 if (ctl->free_space < bytes) { in btrfs_find_space_cluster()
3054 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3091 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3117 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in do_trimming() local
3137 mutex_lock(&ctl->cache_writeout_mutex); in do_trimming()
3140 mutex_unlock(&ctl->cache_writeout_mutex); in do_trimming()
3159 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_no_bitmap() local
3170 mutex_lock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3171 spin_lock(&ctl->tree_lock); in trim_no_bitmap()
3173 if (ctl->free_space < minlen) { in trim_no_bitmap()
3174 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3175 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3179 entry = tree_search_offset(ctl, start, 0, 1); in trim_no_bitmap()
3181 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3182 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3190 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3191 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3199 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3200 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3209 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3210 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3214 unlink_free_space(ctl, entry); in trim_no_bitmap()
3217 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3220 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_no_bitmap()
3221 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3244 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_bitmaps() local
3249 u64 offset = offset_to_bitmap(ctl, start); in trim_bitmaps()
3255 mutex_lock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3256 spin_lock(&ctl->tree_lock); in trim_bitmaps()
3258 if (ctl->free_space < minlen) { in trim_bitmaps()
3259 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3260 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3264 entry = tree_search_offset(ctl, offset, 1, 0); in trim_bitmaps()
3266 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3267 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3273 ret2 = search_bitmap(ctl, entry, &start, &bytes, false); in trim_bitmaps()
3275 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3276 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3283 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3284 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3288 bitmap_clear_bits(ctl, entry, start, bytes); in trim_bitmaps()
3290 free_bitmap(ctl, entry); in trim_bitmaps()
3292 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3295 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_bitmaps()
3296 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3304 offset += BITS_PER_BITMAP * ctl->unit; in trim_bitmaps()
3307 if (start >= offset + BITS_PER_BITMAP * ctl->unit) in trim_bitmaps()
3308 offset += BITS_PER_BITMAP * ctl->unit; in trim_bitmaps()
3399 struct btrfs_free_space_ctl *ctl = fs_root->free_ino_ctl; in btrfs_find_ino_for_alloc() local
3403 spin_lock(&ctl->tree_lock); in btrfs_find_ino_for_alloc()
3405 if (RB_EMPTY_ROOT(&ctl->free_space_offset)) in btrfs_find_ino_for_alloc()
3408 entry = rb_entry(rb_first(&ctl->free_space_offset), in btrfs_find_ino_for_alloc()
3414 unlink_free_space(ctl, entry); in btrfs_find_ino_for_alloc()
3420 link_free_space(ctl, entry); in btrfs_find_ino_for_alloc()
3426 ret = search_bitmap(ctl, entry, &offset, &count, true); in btrfs_find_ino_for_alloc()
3431 bitmap_clear_bits(ctl, entry, offset, 1); in btrfs_find_ino_for_alloc()
3433 free_bitmap(ctl, entry); in btrfs_find_ino_for_alloc()
3436 spin_unlock(&ctl->tree_lock); in btrfs_find_ino_for_alloc()
3475 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in load_free_ino_cache() local
3502 ret = __load_free_space_cache(root, inode, ctl, path, 0); in load_free_ino_cache()
3520 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_write_out_ino_cache() local
3529 ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, in btrfs_write_out_ino_cache()
3565 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_add_free_space_entry() local
3579 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
3583 ret = link_free_space(ctl, info); in test_add_free_space_entry()
3584 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
3598 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
3599 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_add_free_space_entry()
3604 add_new_bitmap(ctl, info, offset); in test_add_free_space_entry()
3609 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes); in test_add_free_space_entry()
3613 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
3633 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_check_exists() local
3637 spin_lock(&ctl->tree_lock); in test_check_exists()
3638 info = tree_search_offset(ctl, offset, 0, 0); in test_check_exists()
3640 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_check_exists()
3653 bit_bytes = ctl->unit; in test_check_exists()
3654 ret = search_bitmap(ctl, info, &bit_off, &bit_bytes, false); in test_check_exists()
3706 spin_unlock(&ctl->tree_lock); in test_check_exists()