• Home
  • Raw
  • Download

Lines Matching refs:ctl

36 static int count_bitmap_extents(struct btrfs_free_space_ctl *ctl,
38 static int link_free_space(struct btrfs_free_space_ctl *ctl,
40 static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
637 static void merge_space_tree(struct btrfs_free_space_ctl *ctl) in merge_space_tree() argument
643 spin_lock(&ctl->tree_lock); in merge_space_tree()
644 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { in merge_space_tree()
651 unlink_free_space(ctl, prev); in merge_space_tree()
652 unlink_free_space(ctl, e); in merge_space_tree()
655 link_free_space(ctl, prev); in merge_space_tree()
657 spin_unlock(&ctl->tree_lock); in merge_space_tree()
663 spin_unlock(&ctl->tree_lock); in merge_space_tree()
667 struct btrfs_free_space_ctl *ctl, in __load_free_space_cache() argument
775 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
776 ret = link_free_space(ctl, e); in __load_free_space_cache()
777 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
795 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
796 ret = link_free_space(ctl, e); in __load_free_space_cache()
797 ctl->total_bitmaps++; in __load_free_space_cache()
798 ctl->op->recalc_thresholds(ctl); in __load_free_space_cache()
799 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
823 e->bitmap_extents = count_bitmap_extents(ctl, e); in __load_free_space_cache()
825 ctl->discardable_extents[BTRFS_STAT_CURR] += in __load_free_space_cache()
827 ctl->discardable_bytes[BTRFS_STAT_CURR] += e->bytes; in __load_free_space_cache()
832 merge_space_tree(ctl); in __load_free_space_cache()
835 btrfs_discard_update_discardable(ctl->private, ctl); in __load_free_space_cache()
840 __btrfs_remove_free_space_cache(ctl); in __load_free_space_cache()
847 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in load_free_space_cache() local
905 ret = __load_free_space_cache(fs_info->tree_root, inode, ctl, in load_free_space_cache()
911 spin_lock(&ctl->tree_lock); in load_free_space_cache()
912 matched = (ctl->free_space == (block_group->length - used - in load_free_space_cache()
914 spin_unlock(&ctl->tree_lock); in load_free_space_cache()
917 __btrfs_remove_free_space_cache(ctl); in load_free_space_cache()
942 struct btrfs_free_space_ctl *ctl, in write_cache_extent_entries() argument
950 struct rb_node *node = rb_first(&ctl->free_space_offset); in write_cache_extent_entries()
1002 list_for_each_entry(trim_entry, &ctl->trimming_ranges, list) { in write_cache_extent_entries()
1256 struct btrfs_free_space_ctl *ctl, in __btrfs_write_out_cache() argument
1301 mutex_lock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1303 spin_lock(&ctl->tree_lock); in __btrfs_write_out_cache()
1304 ret = write_cache_extent_entries(io_ctl, ctl, in __btrfs_write_out_cache()
1328 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1329 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1371 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1372 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1399 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_write_out_cache() local
1414 ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl, in btrfs_write_out_cache()
1449 static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl, in offset_to_bitmap() argument
1455 bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; in offset_to_bitmap()
1456 bitmap_start = offset - ctl->start; in offset_to_bitmap()
1459 bitmap_start += ctl->start; in offset_to_bitmap()
1523 tree_search_offset(struct btrfs_free_space_ctl *ctl, in tree_search_offset() argument
1526 struct rb_node *n = ctl->free_space_offset.rb_node; in tree_search_offset()
1612 if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset) in tree_search_offset()
1623 ctl->unit > offset) in tree_search_offset()
1639 __unlink_free_space(struct btrfs_free_space_ctl *ctl, in __unlink_free_space() argument
1642 rb_erase(&info->offset_index, &ctl->free_space_offset); in __unlink_free_space()
1643 ctl->free_extents--; in __unlink_free_space()
1646 ctl->discardable_extents[BTRFS_STAT_CURR]--; in __unlink_free_space()
1647 ctl->discardable_bytes[BTRFS_STAT_CURR] -= info->bytes; in __unlink_free_space()
1651 static void unlink_free_space(struct btrfs_free_space_ctl *ctl, in unlink_free_space() argument
1654 __unlink_free_space(ctl, info); in unlink_free_space()
1655 ctl->free_space -= info->bytes; in unlink_free_space()
1658 static int link_free_space(struct btrfs_free_space_ctl *ctl, in link_free_space() argument
1664 ret = tree_insert_offset(&ctl->free_space_offset, info->offset, in link_free_space()
1670 ctl->discardable_extents[BTRFS_STAT_CURR]++; in link_free_space()
1671 ctl->discardable_bytes[BTRFS_STAT_CURR] += info->bytes; in link_free_space()
1674 ctl->free_space += info->bytes; in link_free_space()
1675 ctl->free_extents++; in link_free_space()
1679 static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) in recalculate_thresholds() argument
1681 struct btrfs_block_group *block_group = ctl->private; in recalculate_thresholds()
1686 u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; in recalculate_thresholds()
1691 ASSERT(ctl->total_bitmaps <= max_bitmaps); in recalculate_thresholds()
1704 bitmap_bytes = ctl->total_bitmaps * ctl->unit; in recalculate_thresholds()
1713 ctl->extents_thresh = in recalculate_thresholds()
1717 static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in __bitmap_clear_bits() argument
1724 start = offset_to_bit(info->offset, ctl->unit, offset); in __bitmap_clear_bits()
1725 count = bytes_to_bits(bytes, ctl->unit); in __bitmap_clear_bits()
1732 if (info->max_extent_size > ctl->unit) in __bitmap_clear_bits()
1743 ctl->discardable_extents[BTRFS_STAT_CURR] += extent_delta; in __bitmap_clear_bits()
1744 ctl->discardable_bytes[BTRFS_STAT_CURR] -= bytes; in __bitmap_clear_bits()
1748 static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in bitmap_clear_bits() argument
1752 __bitmap_clear_bits(ctl, info, offset, bytes); in bitmap_clear_bits()
1753 ctl->free_space -= bytes; in bitmap_clear_bits()
1756 static void bitmap_set_bits(struct btrfs_free_space_ctl *ctl, in bitmap_set_bits() argument
1763 start = offset_to_bit(info->offset, ctl->unit, offset); in bitmap_set_bits()
1764 count = bytes_to_bits(bytes, ctl->unit); in bitmap_set_bits()
1771 ctl->free_space += bytes; in bitmap_set_bits()
1781 ctl->discardable_extents[BTRFS_STAT_CURR] += extent_delta; in bitmap_set_bits()
1782 ctl->discardable_bytes[BTRFS_STAT_CURR] += bytes; in bitmap_set_bits()
1790 static int search_bitmap(struct btrfs_free_space_ctl *ctl, in search_bitmap() argument
1811 i = offset_to_bit(bitmap_info->offset, ctl->unit, in search_bitmap()
1813 bits = bytes_to_bits(*bytes, ctl->unit); in search_bitmap()
1833 *offset = (u64)(i * ctl->unit) + bitmap_info->offset; in search_bitmap()
1834 *bytes = (u64)(found_bits) * ctl->unit; in search_bitmap()
1838 *bytes = (u64)(max_bits) * ctl->unit; in search_bitmap()
1852 find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, in find_free_space() argument
1861 if (!ctl->free_space_offset.rb_node) in find_free_space()
1864 entry = tree_search_offset(ctl, offset_to_bitmap(ctl, *offset), 0, 1); in find_free_space()
1880 tmp = entry->offset - ctl->start + align - 1; in find_free_space()
1882 tmp = tmp * align + ctl->start; in find_free_space()
1898 ret = search_bitmap(ctl, entry, &tmp, &size, true); in find_free_space()
1919 static int count_bitmap_extents(struct btrfs_free_space_ctl *ctl, in count_bitmap_extents() argument
1922 struct btrfs_block_group *block_group = ctl->private; in count_bitmap_extents()
1932 bytes -= (rs - re) * ctl->unit; in count_bitmap_extents()
1942 static void add_new_bitmap(struct btrfs_free_space_ctl *ctl, in add_new_bitmap() argument
1945 info->offset = offset_to_bitmap(ctl, offset); in add_new_bitmap()
1949 link_free_space(ctl, info); in add_new_bitmap()
1950 ctl->total_bitmaps++; in add_new_bitmap()
1952 ctl->op->recalc_thresholds(ctl); in add_new_bitmap()
1955 static void free_bitmap(struct btrfs_free_space_ctl *ctl, in free_bitmap() argument
1965 ctl->discardable_extents[BTRFS_STAT_CURR] -= in free_bitmap()
1967 ctl->discardable_bytes[BTRFS_STAT_CURR] -= bitmap_info->bytes; in free_bitmap()
1970 unlink_free_space(ctl, bitmap_info); in free_bitmap()
1973 ctl->total_bitmaps--; in free_bitmap()
1974 ctl->op->recalc_thresholds(ctl); in free_bitmap()
1977 static noinline int remove_from_bitmap(struct btrfs_free_space_ctl *ctl, in remove_from_bitmap() argument
1986 end = bitmap_info->offset + (u64)(BITS_PER_BITMAP * ctl->unit) - 1; in remove_from_bitmap()
1995 search_bytes = ctl->unit; in remove_from_bitmap()
1997 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes, in remove_from_bitmap()
2008 bitmap_clear_bits(ctl, bitmap_info, search_start, search_bytes); in remove_from_bitmap()
2015 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
2041 search_bytes = ctl->unit; in remove_from_bitmap()
2042 ret = search_bitmap(ctl, bitmap_info, &search_start, in remove_from_bitmap()
2049 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
2054 static u64 add_bytes_to_bitmap(struct btrfs_free_space_ctl *ctl, in add_bytes_to_bitmap() argument
2067 ctl->discardable_extents[BTRFS_STAT_CURR] += in add_bytes_to_bitmap()
2069 ctl->discardable_bytes[BTRFS_STAT_CURR] += info->bytes; in add_bytes_to_bitmap()
2074 end = info->offset + (u64)(BITS_PER_BITMAP * ctl->unit); in add_bytes_to_bitmap()
2078 bitmap_set_bits(ctl, info, offset, bytes_to_set); in add_bytes_to_bitmap()
2090 static bool use_bitmap(struct btrfs_free_space_ctl *ctl, in use_bitmap() argument
2093 struct btrfs_block_group *block_group = ctl->private; in use_bitmap()
2110 if (!forced && ctl->free_extents < ctl->extents_thresh) { in use_bitmap()
2119 if (ctl->free_extents * 3 <= ctl->extents_thresh) in use_bitmap()
2134 if (((BITS_PER_BITMAP * ctl->unit) >> 1) > block_group->length) in use_bitmap()
2145 static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl, in insert_into_bitmap() argument
2159 if (!ctl->op->use_bitmap(ctl, info)) in insert_into_bitmap()
2162 if (ctl->op == &free_space_op) in insert_into_bitmap()
2163 block_group = ctl->private; in insert_into_bitmap()
2191 if (entry->offset == offset_to_bitmap(ctl, offset)) { in insert_into_bitmap()
2192 bytes_added = add_bytes_to_bitmap(ctl, entry, offset, in insert_into_bitmap()
2205 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in insert_into_bitmap()
2212 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes, in insert_into_bitmap()
2226 add_new_bitmap(ctl, info, offset); in insert_into_bitmap()
2231 spin_unlock(&ctl->tree_lock); in insert_into_bitmap()
2238 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2248 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2283 static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, in try_merge_free_space() argument
2298 right_info = tree_search_offset(ctl, offset + bytes, 0, 0); in try_merge_free_space()
2303 left_info = tree_search_offset(ctl, offset - 1, 0, 0); in try_merge_free_space()
2309 unlink_free_space(ctl, right_info); in try_merge_free_space()
2311 __unlink_free_space(ctl, right_info); in try_merge_free_space()
2322 unlink_free_space(ctl, left_info); in try_merge_free_space()
2324 __unlink_free_space(ctl, left_info); in try_merge_free_space()
2334 static bool steal_from_bitmap_to_end(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_end() argument
2342 const u64 bitmap_offset = offset_to_bitmap(ctl, end); in steal_from_bitmap_to_end()
2345 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_end()
2349 i = offset_to_bit(bitmap->offset, ctl->unit, end); in steal_from_bitmap_to_end()
2353 bytes = (j - i) * ctl->unit; in steal_from_bitmap_to_end()
2361 bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2363 __bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2366 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_end()
2371 static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_front() argument
2382 bitmap_offset = offset_to_bitmap(ctl, info->offset); in steal_from_bitmap_to_front()
2387 bitmap_offset = offset_to_bitmap(ctl, info->offset - 1); in steal_from_bitmap_to_front()
2390 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_front()
2394 i = offset_to_bit(bitmap->offset, ctl->unit, info->offset) - 1; in steal_from_bitmap_to_front()
2406 bytes = (i + 1) * ctl->unit; in steal_from_bitmap_to_front()
2408 bytes = (i - prev_j) * ctl->unit; in steal_from_bitmap_to_front()
2418 bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2420 __bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2423 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_front()
2439 static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap() argument
2450 if (ctl->total_bitmaps > 0) { in steal_from_bitmap()
2454 stole_end = steal_from_bitmap_to_end(ctl, info, update_stat); in steal_from_bitmap()
2455 if (ctl->total_bitmaps > 0) in steal_from_bitmap()
2456 stole_front = steal_from_bitmap_to_front(ctl, info, in steal_from_bitmap()
2460 try_merge_free_space(ctl, info, update_stat); in steal_from_bitmap()
2465 struct btrfs_free_space_ctl *ctl, in __btrfs_add_free_space() argument
2469 struct btrfs_block_group *block_group = ctl->private; in __btrfs_add_free_space()
2483 spin_lock(&ctl->tree_lock); in __btrfs_add_free_space()
2485 if (try_merge_free_space(ctl, info, true)) in __btrfs_add_free_space()
2493 ret = insert_into_bitmap(ctl, info); in __btrfs_add_free_space()
2507 steal_from_bitmap(ctl, info, true); in __btrfs_add_free_space()
2511 ret = link_free_space(ctl, info); in __btrfs_add_free_space()
2515 btrfs_discard_update_discardable(block_group, ctl); in __btrfs_add_free_space()
2516 spin_unlock(&ctl->tree_lock); in __btrfs_add_free_space()
2566 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space() local
2571 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space()
2578 info = tree_search_offset(ctl, offset, 0, 0); in btrfs_remove_free_space()
2584 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in btrfs_remove_free_space()
2599 unlink_free_space(ctl, info); in btrfs_remove_free_space()
2606 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2619 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2633 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2635 ret = __btrfs_add_free_space(block_group->fs_info, ctl, in btrfs_remove_free_space()
2644 ret = remove_from_bitmap(ctl, info, &offset, &bytes); in btrfs_remove_free_space()
2650 btrfs_discard_update_discardable(block_group, ctl); in btrfs_remove_free_space()
2651 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2660 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_dump_free_space() local
2665 spin_lock(&ctl->tree_lock); in btrfs_dump_free_space()
2666 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { in btrfs_dump_free_space()
2674 spin_unlock(&ctl->tree_lock); in btrfs_dump_free_space()
2684 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_init_free_space_ctl() local
2686 spin_lock_init(&ctl->tree_lock); in btrfs_init_free_space_ctl()
2687 ctl->unit = fs_info->sectorsize; in btrfs_init_free_space_ctl()
2688 ctl->start = block_group->start; in btrfs_init_free_space_ctl()
2689 ctl->private = block_group; in btrfs_init_free_space_ctl()
2690 ctl->op = &free_space_op; in btrfs_init_free_space_ctl()
2691 INIT_LIST_HEAD(&ctl->trimming_ranges); in btrfs_init_free_space_ctl()
2692 mutex_init(&ctl->cache_writeout_mutex); in btrfs_init_free_space_ctl()
2699 ctl->extents_thresh = (SZ_32K / 2) / sizeof(struct btrfs_free_space); in btrfs_init_free_space_ctl()
2712 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in __btrfs_return_cluster_to_free_space() local
2739 ctl->discardable_extents[BTRFS_STAT_CURR]--; in __btrfs_return_cluster_to_free_space()
2740 ctl->discardable_bytes[BTRFS_STAT_CURR] -= in __btrfs_return_cluster_to_free_space()
2744 try_merge_free_space(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2745 steal_from_bitmap(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2749 ctl->discardable_extents[BTRFS_STAT_CURR]++; in __btrfs_return_cluster_to_free_space()
2750 ctl->discardable_bytes[BTRFS_STAT_CURR] += in __btrfs_return_cluster_to_free_space()
2754 tree_insert_offset(&ctl->free_space_offset, in __btrfs_return_cluster_to_free_space()
2763 struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache_locked() argument
2768 while ((node = rb_last(&ctl->free_space_offset)) != NULL) { in __btrfs_remove_free_space_cache_locked()
2771 unlink_free_space(ctl, info); in __btrfs_remove_free_space_cache_locked()
2774 free_bitmap(ctl, info); in __btrfs_remove_free_space_cache_locked()
2777 cond_resched_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache_locked()
2781 void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache() argument
2783 spin_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2784 __btrfs_remove_free_space_cache_locked(ctl); in __btrfs_remove_free_space_cache()
2785 if (ctl->private) in __btrfs_remove_free_space_cache()
2786 btrfs_discard_update_discardable(ctl->private, ctl); in __btrfs_remove_free_space_cache()
2787 spin_unlock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2792 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space_cache() local
2796 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2805 cond_resched_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2807 __btrfs_remove_free_space_cache_locked(ctl); in btrfs_remove_free_space_cache()
2808 btrfs_discard_update_discardable(block_group, ctl); in btrfs_remove_free_space_cache()
2809 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2821 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_is_free_space_trimmed() local
2826 spin_lock(&ctl->tree_lock); in btrfs_is_free_space_trimmed()
2827 node = rb_first(&ctl->free_space_offset); in btrfs_is_free_space_trimmed()
2840 spin_unlock(&ctl->tree_lock); in btrfs_is_free_space_trimmed()
2848 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_for_alloc() local
2858 spin_lock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2859 entry = find_free_space(ctl, &offset, &bytes_search, in btrfs_find_space_for_alloc()
2866 bitmap_clear_bits(ctl, entry, offset, bytes); in btrfs_find_space_for_alloc()
2872 free_bitmap(ctl, entry); in btrfs_find_space_for_alloc()
2874 unlink_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2889 link_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2892 btrfs_discard_update_discardable(block_group, ctl); in btrfs_find_space_for_alloc()
2893 spin_unlock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2896 __btrfs_add_free_space(block_group->fs_info, ctl, in btrfs_find_space_for_alloc()
2914 struct btrfs_free_space_ctl *ctl; in btrfs_return_cluster_to_free_space() local
2932 ctl = block_group->free_space_ctl; in btrfs_return_cluster_to_free_space()
2935 spin_lock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
2937 spin_unlock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
2951 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_bitmap() local
2960 err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); in btrfs_alloc_from_bitmap()
2968 __bitmap_clear_bits(ctl, entry, ret, bytes); in btrfs_alloc_from_bitmap()
2982 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_cluster() local
3045 spin_lock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
3050 ctl->free_space -= bytes; in btrfs_alloc_from_cluster()
3052 ctl->discardable_bytes[BTRFS_STAT_CURR] -= bytes; in btrfs_alloc_from_cluster()
3057 ctl->free_extents--; in btrfs_alloc_from_cluster()
3061 ctl->total_bitmaps--; in btrfs_alloc_from_cluster()
3062 ctl->op->recalc_thresholds(ctl); in btrfs_alloc_from_cluster()
3064 ctl->discardable_extents[BTRFS_STAT_CURR]--; in btrfs_alloc_from_cluster()
3070 spin_unlock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
3081 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_bitmap_cluster() local
3092 i = offset_to_bit(entry->offset, ctl->unit, in btrfs_bitmap_cluster()
3094 want_bits = bytes_to_bits(bytes, ctl->unit); in btrfs_bitmap_cluster()
3095 min_bits = bytes_to_bits(min_bytes, ctl->unit); in btrfs_bitmap_cluster()
3121 entry->max_extent_size = (u64)max_bits * ctl->unit; in btrfs_bitmap_cluster()
3132 if (cluster->max_size < found_bits * ctl->unit) in btrfs_bitmap_cluster()
3133 cluster->max_size = found_bits * ctl->unit; in btrfs_bitmap_cluster()
3140 cluster->window_start = start * ctl->unit + entry->offset; in btrfs_bitmap_cluster()
3141 rb_erase(&entry->offset_index, &ctl->free_space_offset); in btrfs_bitmap_cluster()
3147 total_found * ctl->unit, 1); in btrfs_bitmap_cluster()
3162 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_no_bitmap() local
3171 entry = tree_search_offset(ctl, offset, 0, 1); in setup_cluster_no_bitmap()
3231 rb_erase(&entry->offset_index, &ctl->free_space_offset); in setup_cluster_no_bitmap()
3253 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_bitmap() local
3256 u64 bitmap_offset = offset_to_bitmap(ctl, offset); in setup_cluster_bitmap()
3258 if (ctl->total_bitmaps == 0) in setup_cluster_bitmap()
3269 entry = tree_search_offset(ctl, bitmap_offset, 1, 0); in setup_cluster_bitmap()
3303 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_cluster() local
3326 spin_lock(&ctl->tree_lock); in btrfs_find_space_cluster()
3332 if (ctl->free_space < bytes) { in btrfs_find_space_cluster()
3333 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3370 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3397 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in do_trimming() local
3421 mutex_lock(&ctl->cache_writeout_mutex); in do_trimming()
3423 __btrfs_add_free_space(fs_info, ctl, reserved_start, in do_trimming()
3427 __btrfs_add_free_space(fs_info, ctl, end, reserved_end - end, in do_trimming()
3429 __btrfs_add_free_space(fs_info, ctl, start, bytes, trim_state); in do_trimming()
3431 mutex_unlock(&ctl->cache_writeout_mutex); in do_trimming()
3456 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_no_bitmap() local
3469 mutex_lock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3470 spin_lock(&ctl->tree_lock); in trim_no_bitmap()
3472 if (ctl->free_space < minlen) in trim_no_bitmap()
3475 entry = tree_search_offset(ctl, start, 0, 1); in trim_no_bitmap()
3499 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3500 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3503 unlink_free_space(ctl, entry); in trim_no_bitmap()
3516 link_free_space(ctl, entry); in trim_no_bitmap()
3524 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3525 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3529 unlink_free_space(ctl, entry); in trim_no_bitmap()
3533 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3536 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_no_bitmap()
3537 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3564 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3565 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3584 static void reset_trimming_bitmap(struct btrfs_free_space_ctl *ctl, u64 offset) in reset_trimming_bitmap() argument
3588 spin_lock(&ctl->tree_lock); in reset_trimming_bitmap()
3589 entry = tree_search_offset(ctl, offset, 1, 0); in reset_trimming_bitmap()
3592 ctl->discardable_extents[BTRFS_STAT_CURR] += in reset_trimming_bitmap()
3594 ctl->discardable_bytes[BTRFS_STAT_CURR] += entry->bytes; in reset_trimming_bitmap()
3599 spin_unlock(&ctl->tree_lock); in reset_trimming_bitmap()
3602 static void end_trimming_bitmap(struct btrfs_free_space_ctl *ctl, in end_trimming_bitmap() argument
3607 ctl->discardable_extents[BTRFS_STAT_CURR] -= in end_trimming_bitmap()
3609 ctl->discardable_bytes[BTRFS_STAT_CURR] -= entry->bytes; in end_trimming_bitmap()
3622 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_bitmaps() local
3627 u64 offset = offset_to_bitmap(ctl, start); in trim_bitmaps()
3634 mutex_lock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3635 spin_lock(&ctl->tree_lock); in trim_bitmaps()
3637 if (ctl->free_space < minlen) { in trim_bitmaps()
3640 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3641 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3645 entry = tree_search_offset(ctl, offset, 1, 0); in trim_bitmaps()
3656 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3657 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3672 ret2 = search_bitmap(ctl, entry, &start, &bytes, false); in trim_bitmaps()
3679 end_trimming_bitmap(ctl, entry); in trim_bitmaps()
3682 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3683 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3693 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3694 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3700 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3701 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3716 bitmap_clear_bits(ctl, entry, start, bytes); in trim_bitmaps()
3718 free_bitmap(ctl, entry); in trim_bitmaps()
3720 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3723 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_bitmaps()
3724 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3729 reset_trimming_bitmap(ctl, offset); in trim_bitmaps()
3736 offset += BITS_PER_BITMAP * ctl->unit; in trim_bitmaps()
3745 reset_trimming_bitmap(ctl, offset); in trim_bitmaps()
3763 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_trim_block_group() local
3782 div64_u64_rem(end, BITS_PER_BITMAP * ctl->unit, &rem); in btrfs_trim_block_group()
3785 reset_trimming_bitmap(ctl, offset_to_bitmap(ctl, end)); in btrfs_trim_block_group()
3846 struct btrfs_free_space_ctl *ctl = fs_root->free_ino_ctl; in btrfs_find_ino_for_alloc() local
3850 spin_lock(&ctl->tree_lock); in btrfs_find_ino_for_alloc()
3852 if (RB_EMPTY_ROOT(&ctl->free_space_offset)) in btrfs_find_ino_for_alloc()
3855 entry = rb_entry(rb_first(&ctl->free_space_offset), in btrfs_find_ino_for_alloc()
3861 unlink_free_space(ctl, entry); in btrfs_find_ino_for_alloc()
3867 link_free_space(ctl, entry); in btrfs_find_ino_for_alloc()
3873 ret = search_bitmap(ctl, entry, &offset, &count, true); in btrfs_find_ino_for_alloc()
3878 bitmap_clear_bits(ctl, entry, offset, 1); in btrfs_find_ino_for_alloc()
3880 free_bitmap(ctl, entry); in btrfs_find_ino_for_alloc()
3883 spin_unlock(&ctl->tree_lock); in btrfs_find_ino_for_alloc()
3922 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in load_free_ino_cache() local
3949 ret = __load_free_space_cache(root, inode, ctl, path, 0); in load_free_ino_cache()
3968 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_write_out_ino_cache() local
3977 ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, trans); in btrfs_write_out_ino_cache()
4011 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_add_free_space_entry() local
4026 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
4030 ret = link_free_space(ctl, info); in test_add_free_space_entry()
4031 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
4045 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
4046 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_add_free_space_entry()
4051 add_new_bitmap(ctl, info, offset); in test_add_free_space_entry()
4056 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes, in test_add_free_space_entry()
4061 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
4081 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_check_exists() local
4085 spin_lock(&ctl->tree_lock); in test_check_exists()
4086 info = tree_search_offset(ctl, offset, 0, 0); in test_check_exists()
4088 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_check_exists()
4101 bit_bytes = ctl->unit; in test_check_exists()
4102 ret = search_bitmap(ctl, info, &bit_off, &bit_bytes, false); in test_check_exists()
4154 spin_unlock(&ctl->tree_lock); in test_check_exists()