Lines Matching +full:5 +full:bg
319 struct btrfs_block_group *bg; in btrfs_inc_nocow_writers() local
322 bg = btrfs_lookup_block_group(fs_info, bytenr); in btrfs_inc_nocow_writers()
323 if (!bg) in btrfs_inc_nocow_writers()
326 spin_lock(&bg->lock); in btrfs_inc_nocow_writers()
327 if (bg->ro) in btrfs_inc_nocow_writers()
330 atomic_inc(&bg->nocow_writers); in btrfs_inc_nocow_writers()
331 spin_unlock(&bg->lock); in btrfs_inc_nocow_writers()
334 btrfs_put_block_group(bg); in btrfs_inc_nocow_writers()
339 return bg; in btrfs_inc_nocow_writers()
353 void btrfs_dec_nocow_writers(struct btrfs_block_group *bg) in btrfs_dec_nocow_writers() argument
355 if (atomic_dec_and_test(&bg->nocow_writers)) in btrfs_dec_nocow_writers()
356 wake_up_var(&bg->nocow_writers); in btrfs_dec_nocow_writers()
359 btrfs_put_block_group(bg); in btrfs_dec_nocow_writers()
362 void btrfs_wait_nocow_writers(struct btrfs_block_group *bg) in btrfs_wait_nocow_writers() argument
364 wait_var_event(&bg->nocow_writers, !atomic_read(&bg->nocow_writers)); in btrfs_wait_nocow_writers()
370 struct btrfs_block_group *bg; in btrfs_dec_block_group_reservations() local
372 bg = btrfs_lookup_block_group(fs_info, start); in btrfs_dec_block_group_reservations()
373 ASSERT(bg); in btrfs_dec_block_group_reservations()
374 if (atomic_dec_and_test(&bg->reservations)) in btrfs_dec_block_group_reservations()
375 wake_up_var(&bg->reservations); in btrfs_dec_block_group_reservations()
376 btrfs_put_block_group(bg); in btrfs_dec_block_group_reservations()
379 void btrfs_wait_block_group_reservations(struct btrfs_block_group *bg) in btrfs_wait_block_group_reservations() argument
381 struct btrfs_space_info *space_info = bg->space_info; in btrfs_wait_block_group_reservations()
383 ASSERT(bg->ro); in btrfs_wait_block_group_reservations()
385 if (!(bg->flags & BTRFS_BLOCK_GROUP_DATA)) in btrfs_wait_block_group_reservations()
401 wait_var_event(&bg->reservations, !atomic_read(&bg->reservations)); in btrfs_wait_block_group_reservations()
644 * only a handful are enough to give a good answer. Therefore, we just grab 5 of
684 for (i = 0; i < 5; ++i) { in load_block_group_size_class()
685 ret = sample_block_group_extent_item(caching_ctl, block_group, i, 5, &key); in load_block_group_size_class()
838 static inline void btrfs_free_excluded_extents(const struct btrfs_block_group *bg) in btrfs_free_excluded_extents() argument
840 clear_extent_bits(&bg->fs_info->excluded_extents, bg->start, in btrfs_free_excluded_extents()
841 bg->start + bg->length - 1, EXTENT_UPTODATE); in btrfs_free_excluded_extents()
1377 * Here we make sure if we mark this bg RO, we still have enough in inc_block_group_ro()
1418 const struct btrfs_block_group *bg) in clean_pinned_extents() argument
1422 const u64 start = bg->start; in clean_pinned_extents()
1423 const u64 end = start + bg->length - 1; in clean_pinned_extents()
1727 void btrfs_mark_bg_unused(struct btrfs_block_group *bg) in btrfs_mark_bg_unused() argument
1729 struct btrfs_fs_info *fs_info = bg->fs_info; in btrfs_mark_bg_unused()
1732 if (list_empty(&bg->bg_list)) { in btrfs_mark_bg_unused()
1733 btrfs_get_block_group(bg); in btrfs_mark_bg_unused()
1734 trace_btrfs_add_unused_block_group(bg); in btrfs_mark_bg_unused()
1735 list_add_tail(&bg->bg_list, &fs_info->unused_bgs); in btrfs_mark_bg_unused()
1736 } else if (!test_bit(BLOCK_GROUP_FLAG_NEW, &bg->runtime_flags)) { in btrfs_mark_bg_unused()
1738 trace_btrfs_add_unused_block_group(bg); in btrfs_mark_bg_unused()
1739 list_move_tail(&bg->bg_list, &fs_info->unused_bgs); in btrfs_mark_bg_unused()
1766 static bool should_reclaim_block_group(const struct btrfs_block_group *bg, u64 bytes_freed) in should_reclaim_block_group() argument
1768 const int thresh_pct = btrfs_calc_reclaim_threshold(bg->space_info); in should_reclaim_block_group()
1769 u64 thresh_bytes = mult_perc(bg->length, thresh_pct); in should_reclaim_block_group()
1770 const u64 new_val = bg->used; in should_reclaim_block_group()
1791 struct btrfs_block_group *bg; in btrfs_reclaim_bgs_work() local
1833 bg = list_first_entry(&fs_info->reclaim_bgs, in btrfs_reclaim_bgs_work()
1836 list_del_init(&bg->bg_list); in btrfs_reclaim_bgs_work()
1838 space_info = bg->space_info; in btrfs_reclaim_bgs_work()
1845 spin_lock(&bg->lock); in btrfs_reclaim_bgs_work()
1846 if (bg->reserved || bg->pinned || bg->ro) { in btrfs_reclaim_bgs_work()
1853 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1858 if (bg->used == 0) { in btrfs_reclaim_bgs_work()
1871 btrfs_mark_bg_unused(bg); in btrfs_reclaim_bgs_work()
1872 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1888 if (!should_reclaim_block_group(bg, bg->length)) { in btrfs_reclaim_bgs_work()
1889 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1894 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1916 zone_unusable = bg->zone_unusable; in btrfs_reclaim_bgs_work()
1917 ret = inc_block_group_ro(bg, 0); in btrfs_reclaim_bgs_work()
1924 bg->start, in btrfs_reclaim_bgs_work()
1925 div64_u64(bg->used * 100, bg->length), in btrfs_reclaim_bgs_work()
1926 div64_u64(zone_unusable * 100, bg->length)); in btrfs_reclaim_bgs_work()
1927 trace_btrfs_reclaim_block_group(bg); in btrfs_reclaim_bgs_work()
1928 reclaimed = bg->used; in btrfs_reclaim_bgs_work()
1929 ret = btrfs_relocate_chunk(fs_info, bg->start); in btrfs_reclaim_bgs_work()
1931 btrfs_dec_block_group_ro(bg); in btrfs_reclaim_bgs_work()
1933 bg->start); in btrfs_reclaim_bgs_work()
1955 if (list_empty(&bg->bg_list)) { in btrfs_reclaim_bgs_work()
1956 btrfs_get_block_group(bg); in btrfs_reclaim_bgs_work()
1957 list_add_tail(&bg->bg_list, &retry_list); in btrfs_reclaim_bgs_work()
1961 btrfs_put_block_group(bg); in btrfs_reclaim_bgs_work()
1996 void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg) in btrfs_mark_bg_to_reclaim() argument
1998 struct btrfs_fs_info *fs_info = bg->fs_info; in btrfs_mark_bg_to_reclaim()
2001 if (list_empty(&bg->bg_list)) { in btrfs_mark_bg_to_reclaim()
2002 btrfs_get_block_group(bg); in btrfs_mark_bg_to_reclaim()
2003 trace_btrfs_add_reclaim_block_group(bg); in btrfs_mark_bg_to_reclaim()
2004 list_add_tail(&bg->bg_list, &fs_info->reclaim_bgs); in btrfs_mark_bg_to_reclaim()
2013 struct btrfs_block_group_item bg; in read_bg_from_eb() local
2025 "logical %llu len %llu found bg but no related chunk", in read_bg_from_eb()
2038 read_extent_buffer(leaf, &bg, btrfs_item_ptr_offset(leaf, slot), in read_bg_from_eb()
2039 sizeof(bg)); in read_bg_from_eb()
2040 flags = btrfs_stack_block_group_flags(&bg) & in read_bg_from_eb()
2283 struct btrfs_block_group *bg; in check_chunk_block_group_mappings() local
2294 bg = btrfs_lookup_block_group(fs_info, map->start); in check_chunk_block_group_mappings()
2295 if (!bg) { in check_chunk_block_group_mappings()
2303 if (bg->start != map->start || bg->length != map->chunk_len || in check_chunk_block_group_mappings()
2304 (bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK) != in check_chunk_block_group_mappings()
2310 bg->start, bg->length, in check_chunk_block_group_mappings()
2311 bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK); in check_chunk_block_group_mappings()
2314 btrfs_put_block_group(bg); in check_chunk_block_group_mappings()
2319 btrfs_put_block_group(bg); in check_chunk_block_group_mappings()
2364 "bg %llu is a mixed block group but filesystem hasn't enabled mixed block groups", in read_one_block_group()
2372 btrfs_err(info, "zoned: failed to load zone info of bg %llu", in read_one_block_group()
2451 struct btrfs_block_group *bg; in fill_dummy_bgs() local
2454 bg = btrfs_create_block_group_cache(fs_info, map->start); in fill_dummy_bgs()
2455 if (!bg) { in fill_dummy_bgs()
2461 bg->length = map->chunk_len; in fill_dummy_bgs()
2462 bg->flags = map->type; in fill_dummy_bgs()
2463 bg->cached = BTRFS_CACHE_FINISHED; in fill_dummy_bgs()
2464 bg->used = map->chunk_len; in fill_dummy_bgs()
2465 bg->flags = map->type; in fill_dummy_bgs()
2466 ret = btrfs_add_block_group_cache(fs_info, bg); in fill_dummy_bgs()
2473 btrfs_put_block_group(bg); in fill_dummy_bgs()
2478 btrfs_remove_free_space_cache(bg); in fill_dummy_bgs()
2479 btrfs_put_block_group(bg); in fill_dummy_bgs()
2483 btrfs_add_bg_to_space_info(fs_info, bg); in fill_dummy_bgs()
2485 set_avail_alloc_bits(fs_info, bg->flags); in fill_dummy_bgs()
2890 * assigned to our block group. We want our bg to be added to the rbtree in btrfs_make_block_group()
3010 * Skip chunk allocation if the bg is SYSTEM, this is to avoid system in btrfs_inc_block_group_ro()
3882 struct btrfs_block_group *bg; in do_chunk_alloc() local
3893 bg = btrfs_create_chunk(trans, flags); in do_chunk_alloc()
3894 if (IS_ERR(bg)) { in do_chunk_alloc()
3895 ret = PTR_ERR(bg); in do_chunk_alloc()
3899 ret = btrfs_chunk_alloc_add_chunk_item(trans, bg); in do_chunk_alloc()
3955 ret = btrfs_chunk_alloc_add_chunk_item(trans, bg); in do_chunk_alloc()
3970 btrfs_get_block_group(bg); in do_chunk_alloc()
3971 return bg; in do_chunk_alloc()
4262 struct btrfs_block_group *bg; in reserve_chunk_space() local
4270 bg = btrfs_create_chunk(trans, flags); in reserve_chunk_space()
4271 if (IS_ERR(bg)) { in reserve_chunk_space()
4272 ret = PTR_ERR(bg); in reserve_chunk_space()
4292 btrfs_chunk_alloc_add_chunk_item(trans, bg); in reserve_chunk_space()
4543 bool btrfs_inc_block_group_swap_extents(struct btrfs_block_group *bg) in btrfs_inc_block_group_swap_extents() argument
4547 spin_lock(&bg->lock); in btrfs_inc_block_group_swap_extents()
4548 if (bg->ro) in btrfs_inc_block_group_swap_extents()
4551 bg->swap_extents++; in btrfs_inc_block_group_swap_extents()
4552 spin_unlock(&bg->lock); in btrfs_inc_block_group_swap_extents()
4557 void btrfs_dec_block_group_swap_extents(struct btrfs_block_group *bg, int amount) in btrfs_dec_block_group_swap_extents() argument
4559 spin_lock(&bg->lock); in btrfs_dec_block_group_swap_extents()
4560 ASSERT(!bg->ro); in btrfs_dec_block_group_swap_extents()
4561 ASSERT(bg->swap_extents >= amount); in btrfs_dec_block_group_swap_extents()
4562 bg->swap_extents -= amount; in btrfs_dec_block_group_swap_extents()
4563 spin_unlock(&bg->lock); in btrfs_dec_block_group_swap_extents()
4578 * @bg: The block group we allocated in.
4594 int btrfs_use_block_group_size_class(struct btrfs_block_group *bg, in btrfs_use_block_group_size_class() argument
4601 if (bg->size_class == size_class) in btrfs_use_block_group_size_class()
4613 if (bg->size_class != BTRFS_BG_SZ_NONE) { in btrfs_use_block_group_size_class()
4622 bg->size_class = size_class; in btrfs_use_block_group_size_class()
4627 bool btrfs_block_group_should_use_size_class(const struct btrfs_block_group *bg) in btrfs_block_group_should_use_size_class() argument
4629 if (btrfs_is_zoned(bg->fs_info)) in btrfs_block_group_should_use_size_class()
4631 if (!btrfs_is_block_group_data_only(bg)) in btrfs_block_group_should_use_size_class()