Lines Matching full:ctl

36 static int link_free_space(struct btrfs_free_space_ctl *ctl,
38 static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
40 static int search_bitmap(struct btrfs_free_space_ctl *ctl,
43 static void free_bitmap(struct btrfs_free_space_ctl *ctl,
45 static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl,
663 static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) in recalculate_thresholds() argument
665 struct btrfs_block_group *block_group = ctl->private; in recalculate_thresholds()
670 u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; in recalculate_thresholds()
675 ASSERT(ctl->total_bitmaps <= max_bitmaps); in recalculate_thresholds()
688 bitmap_bytes = ctl->total_bitmaps * ctl->unit; in recalculate_thresholds()
697 ctl->extents_thresh = in recalculate_thresholds()
702 struct btrfs_free_space_ctl *ctl, in __load_free_space_cache() argument
800 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
801 ret = link_free_space(ctl, e); in __load_free_space_cache()
802 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
820 spin_lock(&ctl->tree_lock); in __load_free_space_cache()
821 ret = link_free_space(ctl, e); in __load_free_space_cache()
822 ctl->total_bitmaps++; in __load_free_space_cache()
823 recalculate_thresholds(ctl); in __load_free_space_cache()
824 spin_unlock(&ctl->tree_lock); in __load_free_space_cache()
857 __btrfs_remove_free_space_cache(ctl); in __load_free_space_cache()
862 struct btrfs_free_space_ctl *ctl) in copy_free_space_cache() argument
868 while (!ret && (n = rb_first(&ctl->free_space_offset)) != NULL) { in copy_free_space_cache()
871 unlink_free_space(ctl, info); in copy_free_space_cache()
877 u64 bytes = ctl->unit; in copy_free_space_cache()
879 while (search_bitmap(ctl, info, &offset, &bytes, in copy_free_space_cache()
885 bitmap_clear_bits(ctl, info, offset, bytes); in copy_free_space_cache()
887 bytes = ctl->unit; in copy_free_space_cache()
889 free_bitmap(ctl, info); in copy_free_space_cache()
899 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in load_free_space_cache() local
910 * valid copy it all into the actual free space ctl. in load_free_space_cache()
1002 spin_lock(&ctl->tree_lock); in load_free_space_cache()
1004 spin_unlock(&ctl->tree_lock); in load_free_space_cache()
1011 struct btrfs_free_space_ctl *ctl, in write_cache_extent_entries() argument
1019 struct rb_node *node = rb_first(&ctl->free_space_offset); in write_cache_extent_entries()
1071 list_for_each_entry(trim_entry, &ctl->trimming_ranges, list) { in write_cache_extent_entries()
1310 * @ctl: free space cache we are going to write out
1320 struct btrfs_free_space_ctl *ctl, in __btrfs_write_out_cache() argument
1365 mutex_lock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1367 spin_lock(&ctl->tree_lock); in __btrfs_write_out_cache()
1368 ret = write_cache_extent_entries(io_ctl, ctl, in __btrfs_write_out_cache()
1392 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1393 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1435 spin_unlock(&ctl->tree_lock); in __btrfs_write_out_cache()
1436 mutex_unlock(&ctl->cache_writeout_mutex); in __btrfs_write_out_cache()
1463 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_write_out_cache() local
1478 ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl, in btrfs_write_out_cache()
1513 static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl, in offset_to_bitmap() argument
1519 bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; in offset_to_bitmap()
1520 bitmap_start = offset - ctl->start; in offset_to_bitmap()
1523 bitmap_start += ctl->start; in offset_to_bitmap()
1587 tree_search_offset(struct btrfs_free_space_ctl *ctl, in tree_search_offset() argument
1590 struct rb_node *n = ctl->free_space_offset.rb_node; in tree_search_offset()
1676 if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset) in tree_search_offset()
1687 ctl->unit > offset) in tree_search_offset()
1703 __unlink_free_space(struct btrfs_free_space_ctl *ctl, in __unlink_free_space() argument
1706 rb_erase(&info->offset_index, &ctl->free_space_offset); in __unlink_free_space()
1707 ctl->free_extents--; in __unlink_free_space()
1710 ctl->discardable_extents[BTRFS_STAT_CURR]--; in __unlink_free_space()
1711 ctl->discardable_bytes[BTRFS_STAT_CURR] -= info->bytes; in __unlink_free_space()
1715 static void unlink_free_space(struct btrfs_free_space_ctl *ctl, in unlink_free_space() argument
1718 __unlink_free_space(ctl, info); in unlink_free_space()
1719 ctl->free_space -= info->bytes; in unlink_free_space()
1722 static int link_free_space(struct btrfs_free_space_ctl *ctl, in link_free_space() argument
1728 ret = tree_insert_offset(&ctl->free_space_offset, info->offset, in link_free_space()
1734 ctl->discardable_extents[BTRFS_STAT_CURR]++; in link_free_space()
1735 ctl->discardable_bytes[BTRFS_STAT_CURR] += info->bytes; in link_free_space()
1738 ctl->free_space += info->bytes; in link_free_space()
1739 ctl->free_extents++; in link_free_space()
1743 static inline void __bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in __bitmap_clear_bits() argument
1750 start = offset_to_bit(info->offset, ctl->unit, offset); in __bitmap_clear_bits()
1751 count = bytes_to_bits(bytes, ctl->unit); in __bitmap_clear_bits()
1758 if (info->max_extent_size > ctl->unit) in __bitmap_clear_bits()
1769 ctl->discardable_extents[BTRFS_STAT_CURR] += extent_delta; in __bitmap_clear_bits()
1770 ctl->discardable_bytes[BTRFS_STAT_CURR] -= bytes; in __bitmap_clear_bits()
1774 static void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl, in bitmap_clear_bits() argument
1778 __bitmap_clear_bits(ctl, info, offset, bytes); in bitmap_clear_bits()
1779 ctl->free_space -= bytes; in bitmap_clear_bits()
1782 static void bitmap_set_bits(struct btrfs_free_space_ctl *ctl, in bitmap_set_bits() argument
1789 start = offset_to_bit(info->offset, ctl->unit, offset); in bitmap_set_bits()
1790 count = bytes_to_bits(bytes, ctl->unit); in bitmap_set_bits()
1797 ctl->free_space += bytes; in bitmap_set_bits()
1807 ctl->discardable_extents[BTRFS_STAT_CURR] += extent_delta; in bitmap_set_bits()
1808 ctl->discardable_bytes[BTRFS_STAT_CURR] += bytes; in bitmap_set_bits()
1816 static int search_bitmap(struct btrfs_free_space_ctl *ctl, in search_bitmap() argument
1837 i = offset_to_bit(bitmap_info->offset, ctl->unit, in search_bitmap()
1839 bits = bytes_to_bits(*bytes, ctl->unit); in search_bitmap()
1859 *offset = (u64)(i * ctl->unit) + bitmap_info->offset; in search_bitmap()
1860 *bytes = (u64)(found_bits) * ctl->unit; in search_bitmap()
1864 *bytes = (u64)(max_bits) * ctl->unit; in search_bitmap()
1878 find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, in find_free_space() argument
1887 if (!ctl->free_space_offset.rb_node) in find_free_space()
1890 entry = tree_search_offset(ctl, offset_to_bitmap(ctl, *offset), 0, 1); in find_free_space()
1906 tmp = entry->offset - ctl->start + align - 1; in find_free_space()
1908 tmp = tmp * align + ctl->start; in find_free_space()
1924 ret = search_bitmap(ctl, entry, &tmp, &size, true); in find_free_space()
1945 static void add_new_bitmap(struct btrfs_free_space_ctl *ctl, in add_new_bitmap() argument
1948 info->offset = offset_to_bitmap(ctl, offset); in add_new_bitmap()
1952 link_free_space(ctl, info); in add_new_bitmap()
1953 ctl->total_bitmaps++; in add_new_bitmap()
1954 recalculate_thresholds(ctl); in add_new_bitmap()
1957 static void free_bitmap(struct btrfs_free_space_ctl *ctl, in free_bitmap() argument
1967 ctl->discardable_extents[BTRFS_STAT_CURR] -= in free_bitmap()
1969 ctl->discardable_bytes[BTRFS_STAT_CURR] -= bitmap_info->bytes; in free_bitmap()
1972 unlink_free_space(ctl, bitmap_info); in free_bitmap()
1975 ctl->total_bitmaps--; in free_bitmap()
1976 recalculate_thresholds(ctl); in free_bitmap()
1979 static noinline int remove_from_bitmap(struct btrfs_free_space_ctl *ctl, in remove_from_bitmap() argument
1988 end = bitmap_info->offset + (u64)(BITS_PER_BITMAP * ctl->unit) - 1; in remove_from_bitmap()
1997 search_bytes = ctl->unit; in remove_from_bitmap()
1999 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes, in remove_from_bitmap()
2010 bitmap_clear_bits(ctl, bitmap_info, search_start, search_bytes); in remove_from_bitmap()
2017 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
2043 search_bytes = ctl->unit; in remove_from_bitmap()
2044 ret = search_bitmap(ctl, bitmap_info, &search_start, in remove_from_bitmap()
2051 free_bitmap(ctl, bitmap_info); in remove_from_bitmap()
2056 static u64 add_bytes_to_bitmap(struct btrfs_free_space_ctl *ctl, in add_bytes_to_bitmap() argument
2069 ctl->discardable_extents[BTRFS_STAT_CURR] += in add_bytes_to_bitmap()
2071 ctl->discardable_bytes[BTRFS_STAT_CURR] += info->bytes; in add_bytes_to_bitmap()
2076 end = info->offset + (u64)(BITS_PER_BITMAP * ctl->unit); in add_bytes_to_bitmap()
2080 bitmap_set_bits(ctl, info, offset, bytes_to_set); in add_bytes_to_bitmap()
2092 static bool use_bitmap(struct btrfs_free_space_ctl *ctl, in use_bitmap() argument
2095 struct btrfs_block_group *block_group = ctl->private; in use_bitmap()
2112 if (!forced && ctl->free_extents < ctl->extents_thresh) { in use_bitmap()
2121 if (ctl->free_extents * 3 <= ctl->extents_thresh) in use_bitmap()
2136 if (((BITS_PER_BITMAP * ctl->unit) >> 1) > block_group->length) in use_bitmap()
2146 static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl, in insert_into_bitmap() argument
2160 if (!ctl->op->use_bitmap(ctl, info)) in insert_into_bitmap()
2163 if (ctl->op == &free_space_op) in insert_into_bitmap()
2164 block_group = ctl->private; in insert_into_bitmap()
2192 if (entry->offset == offset_to_bitmap(ctl, offset)) { in insert_into_bitmap()
2193 bytes_added = add_bytes_to_bitmap(ctl, entry, offset, in insert_into_bitmap()
2206 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in insert_into_bitmap()
2213 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes, in insert_into_bitmap()
2227 add_new_bitmap(ctl, info, offset); in insert_into_bitmap()
2232 spin_unlock(&ctl->tree_lock); in insert_into_bitmap()
2239 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2249 spin_lock(&ctl->tree_lock); in insert_into_bitmap()
2284 static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, in try_merge_free_space() argument
2299 right_info = tree_search_offset(ctl, offset + bytes, 0, 0); in try_merge_free_space()
2304 left_info = tree_search_offset(ctl, offset - 1, 0, 0); in try_merge_free_space()
2310 unlink_free_space(ctl, right_info); in try_merge_free_space()
2312 __unlink_free_space(ctl, right_info); in try_merge_free_space()
2323 unlink_free_space(ctl, left_info); in try_merge_free_space()
2325 __unlink_free_space(ctl, left_info); in try_merge_free_space()
2335 static bool steal_from_bitmap_to_end(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_end() argument
2343 const u64 bitmap_offset = offset_to_bitmap(ctl, end); in steal_from_bitmap_to_end()
2346 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_end()
2350 i = offset_to_bit(bitmap->offset, ctl->unit, end); in steal_from_bitmap_to_end()
2354 bytes = (j - i) * ctl->unit; in steal_from_bitmap_to_end()
2362 bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2364 __bitmap_clear_bits(ctl, bitmap, end, bytes); in steal_from_bitmap_to_end()
2367 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_end()
2372 static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap_to_front() argument
2383 bitmap_offset = offset_to_bitmap(ctl, info->offset); in steal_from_bitmap_to_front()
2388 bitmap_offset = offset_to_bitmap(ctl, info->offset - 1); in steal_from_bitmap_to_front()
2391 bitmap = tree_search_offset(ctl, bitmap_offset, 1, 0); in steal_from_bitmap_to_front()
2395 i = offset_to_bit(bitmap->offset, ctl->unit, info->offset) - 1; in steal_from_bitmap_to_front()
2407 bytes = (i + 1) * ctl->unit; in steal_from_bitmap_to_front()
2409 bytes = (i - prev_j) * ctl->unit; in steal_from_bitmap_to_front()
2419 bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2421 __bitmap_clear_bits(ctl, bitmap, info->offset, bytes); in steal_from_bitmap_to_front()
2424 free_bitmap(ctl, bitmap); in steal_from_bitmap_to_front()
2440 static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl, in steal_from_bitmap() argument
2451 if (ctl->total_bitmaps > 0) { in steal_from_bitmap()
2455 stole_end = steal_from_bitmap_to_end(ctl, info, update_stat); in steal_from_bitmap()
2456 if (ctl->total_bitmaps > 0) in steal_from_bitmap()
2457 stole_front = steal_from_bitmap_to_front(ctl, info, in steal_from_bitmap()
2461 try_merge_free_space(ctl, info, update_stat); in steal_from_bitmap()
2466 struct btrfs_free_space_ctl *ctl, in __btrfs_add_free_space() argument
2470 struct btrfs_block_group *block_group = ctl->private; in __btrfs_add_free_space()
2486 spin_lock(&ctl->tree_lock); in __btrfs_add_free_space()
2488 if (try_merge_free_space(ctl, info, true)) in __btrfs_add_free_space()
2496 ret = insert_into_bitmap(ctl, info); in __btrfs_add_free_space()
2510 steal_from_bitmap(ctl, info, true); in __btrfs_add_free_space()
2514 ret = link_free_space(ctl, info); in __btrfs_add_free_space()
2519 spin_unlock(&ctl->tree_lock); in __btrfs_add_free_space()
2538 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in __btrfs_add_free_space_zoned() local
2543 spin_lock(&ctl->tree_lock); in __btrfs_add_free_space_zoned()
2554 ctl->free_space += to_free; in __btrfs_add_free_space_zoned()
2561 spin_unlock(&ctl->tree_lock); in __btrfs_add_free_space_zoned()
2633 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space() local
2658 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space()
2665 info = tree_search_offset(ctl, offset, 0, 0); in btrfs_remove_free_space()
2671 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in btrfs_remove_free_space()
2686 unlink_free_space(ctl, info); in btrfs_remove_free_space()
2693 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2706 ret = link_free_space(ctl, info); in btrfs_remove_free_space()
2720 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2722 ret = __btrfs_add_free_space(block_group->fs_info, ctl, in btrfs_remove_free_space()
2731 ret = remove_from_bitmap(ctl, info, &offset, &bytes); in btrfs_remove_free_space()
2738 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space()
2747 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_dump_free_space() local
2762 spin_lock(&ctl->tree_lock); in btrfs_dump_free_space()
2763 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) { in btrfs_dump_free_space()
2771 spin_unlock(&ctl->tree_lock); in btrfs_dump_free_space()
2779 struct btrfs_free_space_ctl *ctl) in btrfs_init_free_space_ctl() argument
2783 spin_lock_init(&ctl->tree_lock); in btrfs_init_free_space_ctl()
2784 ctl->unit = fs_info->sectorsize; in btrfs_init_free_space_ctl()
2785 ctl->start = block_group->start; in btrfs_init_free_space_ctl()
2786 ctl->private = block_group; in btrfs_init_free_space_ctl()
2787 ctl->op = &free_space_op; in btrfs_init_free_space_ctl()
2788 INIT_LIST_HEAD(&ctl->trimming_ranges); in btrfs_init_free_space_ctl()
2789 mutex_init(&ctl->cache_writeout_mutex); in btrfs_init_free_space_ctl()
2796 ctl->extents_thresh = (SZ_32K / 2) / sizeof(struct btrfs_free_space); in btrfs_init_free_space_ctl()
2809 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in __btrfs_return_cluster_to_free_space() local
2836 ctl->discardable_extents[BTRFS_STAT_CURR]--; in __btrfs_return_cluster_to_free_space()
2837 ctl->discardable_bytes[BTRFS_STAT_CURR] -= in __btrfs_return_cluster_to_free_space()
2841 try_merge_free_space(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2842 steal_from_bitmap(ctl, entry, false); in __btrfs_return_cluster_to_free_space()
2846 ctl->discardable_extents[BTRFS_STAT_CURR]++; in __btrfs_return_cluster_to_free_space()
2847 ctl->discardable_bytes[BTRFS_STAT_CURR] += in __btrfs_return_cluster_to_free_space()
2851 tree_insert_offset(&ctl->free_space_offset, in __btrfs_return_cluster_to_free_space()
2860 struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache_locked() argument
2865 while ((node = rb_last(&ctl->free_space_offset)) != NULL) { in __btrfs_remove_free_space_cache_locked()
2868 unlink_free_space(ctl, info); in __btrfs_remove_free_space_cache_locked()
2871 free_bitmap(ctl, info); in __btrfs_remove_free_space_cache_locked()
2874 cond_resched_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache_locked()
2878 void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl) in __btrfs_remove_free_space_cache() argument
2880 spin_lock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2881 __btrfs_remove_free_space_cache_locked(ctl); in __btrfs_remove_free_space_cache()
2882 if (ctl->private) in __btrfs_remove_free_space_cache()
2883 btrfs_discard_update_discardable(ctl->private); in __btrfs_remove_free_space_cache()
2884 spin_unlock(&ctl->tree_lock); in __btrfs_remove_free_space_cache()
2889 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_remove_free_space_cache() local
2893 spin_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2902 cond_resched_lock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2904 __btrfs_remove_free_space_cache_locked(ctl); in btrfs_remove_free_space_cache()
2906 spin_unlock(&ctl->tree_lock); in btrfs_remove_free_space_cache()
2918 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_is_free_space_trimmed() local
2923 spin_lock(&ctl->tree_lock); in btrfs_is_free_space_trimmed()
2924 node = rb_first(&ctl->free_space_offset); in btrfs_is_free_space_trimmed()
2937 spin_unlock(&ctl->tree_lock); in btrfs_is_free_space_trimmed()
2945 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_for_alloc() local
2957 spin_lock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2958 entry = find_free_space(ctl, &offset, &bytes_search, in btrfs_find_space_for_alloc()
2965 bitmap_clear_bits(ctl, entry, offset, bytes); in btrfs_find_space_for_alloc()
2971 free_bitmap(ctl, entry); in btrfs_find_space_for_alloc()
2973 unlink_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2988 link_free_space(ctl, entry); in btrfs_find_space_for_alloc()
2992 spin_unlock(&ctl->tree_lock); in btrfs_find_space_for_alloc()
2995 __btrfs_add_free_space(block_group->fs_info, ctl, in btrfs_find_space_for_alloc()
3013 struct btrfs_free_space_ctl *ctl; in btrfs_return_cluster_to_free_space() local
3031 ctl = block_group->free_space_ctl; in btrfs_return_cluster_to_free_space()
3034 spin_lock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
3036 spin_unlock(&ctl->tree_lock); in btrfs_return_cluster_to_free_space()
3050 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_bitmap() local
3059 err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); in btrfs_alloc_from_bitmap()
3067 __bitmap_clear_bits(ctl, entry, ret, bytes); in btrfs_alloc_from_bitmap()
3081 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_alloc_from_cluster() local
3146 spin_lock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
3151 ctl->free_space -= bytes; in btrfs_alloc_from_cluster()
3153 ctl->discardable_bytes[BTRFS_STAT_CURR] -= bytes; in btrfs_alloc_from_cluster()
3158 ctl->free_extents--; in btrfs_alloc_from_cluster()
3162 ctl->total_bitmaps--; in btrfs_alloc_from_cluster()
3163 recalculate_thresholds(ctl); in btrfs_alloc_from_cluster()
3165 ctl->discardable_extents[BTRFS_STAT_CURR]--; in btrfs_alloc_from_cluster()
3171 spin_unlock(&ctl->tree_lock); in btrfs_alloc_from_cluster()
3182 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_bitmap_cluster() local
3193 i = offset_to_bit(entry->offset, ctl->unit, in btrfs_bitmap_cluster()
3195 want_bits = bytes_to_bits(bytes, ctl->unit); in btrfs_bitmap_cluster()
3196 min_bits = bytes_to_bits(min_bytes, ctl->unit); in btrfs_bitmap_cluster()
3222 entry->max_extent_size = (u64)max_bits * ctl->unit; in btrfs_bitmap_cluster()
3233 if (cluster->max_size < found_bits * ctl->unit) in btrfs_bitmap_cluster()
3234 cluster->max_size = found_bits * ctl->unit; in btrfs_bitmap_cluster()
3241 cluster->window_start = start * ctl->unit + entry->offset; in btrfs_bitmap_cluster()
3242 rb_erase(&entry->offset_index, &ctl->free_space_offset); in btrfs_bitmap_cluster()
3248 total_found * ctl->unit, 1); in btrfs_bitmap_cluster()
3263 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_no_bitmap() local
3272 entry = tree_search_offset(ctl, offset, 0, 1); in setup_cluster_no_bitmap()
3332 rb_erase(&entry->offset_index, &ctl->free_space_offset); in setup_cluster_no_bitmap()
3354 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in setup_cluster_bitmap() local
3357 u64 bitmap_offset = offset_to_bitmap(ctl, offset); in setup_cluster_bitmap()
3359 if (ctl->total_bitmaps == 0) in setup_cluster_bitmap()
3370 entry = tree_search_offset(ctl, bitmap_offset, 1, 0); in setup_cluster_bitmap()
3404 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_find_space_cluster() local
3427 spin_lock(&ctl->tree_lock); in btrfs_find_space_cluster()
3433 if (ctl->free_space < bytes) { in btrfs_find_space_cluster()
3434 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3471 spin_unlock(&ctl->tree_lock); in btrfs_find_space_cluster()
3498 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in do_trimming() local
3522 mutex_lock(&ctl->cache_writeout_mutex); in do_trimming()
3524 __btrfs_add_free_space(fs_info, ctl, reserved_start, in do_trimming()
3528 __btrfs_add_free_space(fs_info, ctl, end, reserved_end - end, in do_trimming()
3530 __btrfs_add_free_space(fs_info, ctl, start, bytes, trim_state); in do_trimming()
3532 mutex_unlock(&ctl->cache_writeout_mutex); in do_trimming()
3557 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_no_bitmap() local
3570 mutex_lock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3571 spin_lock(&ctl->tree_lock); in trim_no_bitmap()
3573 if (ctl->free_space < minlen) in trim_no_bitmap()
3576 entry = tree_search_offset(ctl, start, 0, 1); in trim_no_bitmap()
3600 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3601 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3604 unlink_free_space(ctl, entry); in trim_no_bitmap()
3617 link_free_space(ctl, entry); in trim_no_bitmap()
3625 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3626 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3630 unlink_free_space(ctl, entry); in trim_no_bitmap()
3634 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3637 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_no_bitmap()
3638 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3665 spin_unlock(&ctl->tree_lock); in trim_no_bitmap()
3666 mutex_unlock(&ctl->cache_writeout_mutex); in trim_no_bitmap()
3685 static void reset_trimming_bitmap(struct btrfs_free_space_ctl *ctl, u64 offset) in reset_trimming_bitmap() argument
3689 spin_lock(&ctl->tree_lock); in reset_trimming_bitmap()
3690 entry = tree_search_offset(ctl, offset, 1, 0); in reset_trimming_bitmap()
3693 ctl->discardable_extents[BTRFS_STAT_CURR] += in reset_trimming_bitmap()
3695 ctl->discardable_bytes[BTRFS_STAT_CURR] += entry->bytes; in reset_trimming_bitmap()
3700 spin_unlock(&ctl->tree_lock); in reset_trimming_bitmap()
3703 static void end_trimming_bitmap(struct btrfs_free_space_ctl *ctl, in end_trimming_bitmap() argument
3708 ctl->discardable_extents[BTRFS_STAT_CURR] -= in end_trimming_bitmap()
3710 ctl->discardable_bytes[BTRFS_STAT_CURR] -= entry->bytes; in end_trimming_bitmap()
3723 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in trim_bitmaps() local
3728 u64 offset = offset_to_bitmap(ctl, start); in trim_bitmaps()
3735 mutex_lock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3736 spin_lock(&ctl->tree_lock); in trim_bitmaps()
3738 if (ctl->free_space < minlen) { in trim_bitmaps()
3741 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3742 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3746 entry = tree_search_offset(ctl, offset, 1, 0); in trim_bitmaps()
3757 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3758 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3773 ret2 = search_bitmap(ctl, entry, &start, &bytes, false); in trim_bitmaps()
3780 end_trimming_bitmap(ctl, entry); in trim_bitmaps()
3783 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3784 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3794 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3795 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3801 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3802 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3817 bitmap_clear_bits(ctl, entry, start, bytes); in trim_bitmaps()
3819 free_bitmap(ctl, entry); in trim_bitmaps()
3821 spin_unlock(&ctl->tree_lock); in trim_bitmaps()
3824 list_add_tail(&trim_entry.list, &ctl->trimming_ranges); in trim_bitmaps()
3825 mutex_unlock(&ctl->cache_writeout_mutex); in trim_bitmaps()
3830 reset_trimming_bitmap(ctl, offset); in trim_bitmaps()
3837 offset += BITS_PER_BITMAP * ctl->unit; in trim_bitmaps()
3846 reset_trimming_bitmap(ctl, offset); in trim_bitmaps()
3864 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; in btrfs_trim_block_group() local
3885 div64_u64_rem(end, BITS_PER_BITMAP * ctl->unit, &rem); in btrfs_trim_block_group()
3888 reset_trimming_bitmap(ctl, offset_to_bitmap(ctl, end)); in btrfs_trim_block_group()
4010 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_add_free_space_entry() local
4025 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
4029 ret = link_free_space(ctl, info); in test_add_free_space_entry()
4030 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
4044 spin_lock(&ctl->tree_lock); in test_add_free_space_entry()
4045 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_add_free_space_entry()
4050 add_new_bitmap(ctl, info, offset); in test_add_free_space_entry()
4055 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes, in test_add_free_space_entry()
4060 spin_unlock(&ctl->tree_lock); in test_add_free_space_entry()
4080 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_check_exists() local
4084 spin_lock(&ctl->tree_lock); in test_check_exists()
4085 info = tree_search_offset(ctl, offset, 0, 0); in test_check_exists()
4087 info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), in test_check_exists()
4100 bit_bytes = ctl->unit; in test_check_exists()
4101 ret = search_bitmap(ctl, info, &bit_off, &bit_bytes, false); in test_check_exists()
4153 spin_unlock(&ctl->tree_lock); in test_check_exists()