Lines Matching refs: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()
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()
1421 struct btrfs_block_group *bg) in clean_pinned_extents() argument
1423 struct btrfs_fs_info *fs_info = bg->fs_info; in clean_pinned_extents()
1425 const u64 start = bg->start; in clean_pinned_extents()
1426 const u64 end = start + bg->length - 1; in clean_pinned_extents()
1723 void btrfs_mark_bg_unused(struct btrfs_block_group *bg) in btrfs_mark_bg_unused() argument
1725 struct btrfs_fs_info *fs_info = bg->fs_info; in btrfs_mark_bg_unused()
1728 if (list_empty(&bg->bg_list)) { in btrfs_mark_bg_unused()
1729 btrfs_get_block_group(bg); in btrfs_mark_bg_unused()
1730 trace_btrfs_add_unused_block_group(bg); in btrfs_mark_bg_unused()
1731 list_add_tail(&bg->bg_list, &fs_info->unused_bgs); in btrfs_mark_bg_unused()
1732 } else if (!test_bit(BLOCK_GROUP_FLAG_NEW, &bg->runtime_flags)) { in btrfs_mark_bg_unused()
1734 trace_btrfs_add_unused_block_group(bg); in btrfs_mark_bg_unused()
1735 list_move_tail(&bg->bg_list, &fs_info->unused_bgs); in btrfs_mark_bg_unused()
1762 static bool should_reclaim_block_group(struct btrfs_block_group *bg, u64 bytes_freed) in should_reclaim_block_group() argument
1764 const struct btrfs_space_info *space_info = bg->space_info; in should_reclaim_block_group()
1766 const u64 new_val = bg->used; in should_reclaim_block_group()
1773 thresh = mult_perc(bg->length, reclaim_thresh); in should_reclaim_block_group()
1790 struct btrfs_block_group *bg; in btrfs_reclaim_bgs_work() local
1831 bg = list_first_entry(&fs_info->reclaim_bgs, in btrfs_reclaim_bgs_work()
1834 list_del_init(&bg->bg_list); in btrfs_reclaim_bgs_work()
1836 space_info = bg->space_info; in btrfs_reclaim_bgs_work()
1842 spin_lock(&bg->lock); in btrfs_reclaim_bgs_work()
1843 if (bg->reserved || bg->pinned || bg->ro) { in btrfs_reclaim_bgs_work()
1850 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1854 if (bg->used == 0) { in btrfs_reclaim_bgs_work()
1867 btrfs_mark_bg_unused(bg); in btrfs_reclaim_bgs_work()
1868 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1883 if (!should_reclaim_block_group(bg, bg->length)) { in btrfs_reclaim_bgs_work()
1884 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1888 spin_unlock(&bg->lock); in btrfs_reclaim_bgs_work()
1909 zone_unusable = bg->zone_unusable; in btrfs_reclaim_bgs_work()
1910 ret = inc_block_group_ro(bg, 0); in btrfs_reclaim_bgs_work()
1917 bg->start, in btrfs_reclaim_bgs_work()
1918 div64_u64(bg->used * 100, bg->length), in btrfs_reclaim_bgs_work()
1919 div64_u64(zone_unusable * 100, bg->length)); in btrfs_reclaim_bgs_work()
1920 trace_btrfs_reclaim_block_group(bg); in btrfs_reclaim_bgs_work()
1921 ret = btrfs_relocate_chunk(fs_info, bg->start); in btrfs_reclaim_bgs_work()
1923 btrfs_dec_block_group_ro(bg); in btrfs_reclaim_bgs_work()
1925 bg->start); in btrfs_reclaim_bgs_work()
1937 if (list_empty(&bg->bg_list)) { in btrfs_reclaim_bgs_work()
1938 btrfs_get_block_group(bg); in btrfs_reclaim_bgs_work()
1939 list_add_tail(&bg->bg_list, &retry_list); in btrfs_reclaim_bgs_work()
1943 btrfs_put_block_group(bg); in btrfs_reclaim_bgs_work()
1977 void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg) in btrfs_mark_bg_to_reclaim() argument
1979 struct btrfs_fs_info *fs_info = bg->fs_info; in btrfs_mark_bg_to_reclaim()
1982 if (list_empty(&bg->bg_list)) { in btrfs_mark_bg_to_reclaim()
1983 btrfs_get_block_group(bg); in btrfs_mark_bg_to_reclaim()
1984 trace_btrfs_add_reclaim_block_group(bg); in btrfs_mark_bg_to_reclaim()
1985 list_add_tail(&bg->bg_list, &fs_info->reclaim_bgs); in btrfs_mark_bg_to_reclaim()
1995 struct btrfs_block_group_item bg; in read_bg_from_eb() local
2023 read_extent_buffer(leaf, &bg, btrfs_item_ptr_offset(leaf, slot), in read_bg_from_eb()
2024 sizeof(bg)); in read_bg_from_eb()
2025 flags = btrfs_stack_block_group_flags(&bg) & in read_bg_from_eb()
2267 struct btrfs_block_group *bg; in check_chunk_block_group_mappings() local
2283 bg = btrfs_lookup_block_group(fs_info, em->start); in check_chunk_block_group_mappings()
2284 if (!bg) { in check_chunk_block_group_mappings()
2292 if (bg->start != em->start || bg->length != em->len || in check_chunk_block_group_mappings()
2293 (bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK) != in check_chunk_block_group_mappings()
2299 bg->start, bg->length, in check_chunk_block_group_mappings()
2300 bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK); in check_chunk_block_group_mappings()
2303 btrfs_put_block_group(bg); in check_chunk_block_group_mappings()
2308 btrfs_put_block_group(bg); in check_chunk_block_group_mappings()
2442 struct btrfs_block_group *bg; in fill_dummy_bgs() local
2446 bg = btrfs_create_block_group_cache(fs_info, em->start); in fill_dummy_bgs()
2447 if (!bg) { in fill_dummy_bgs()
2453 bg->length = em->len; in fill_dummy_bgs()
2454 bg->flags = map->type; in fill_dummy_bgs()
2455 bg->cached = BTRFS_CACHE_FINISHED; in fill_dummy_bgs()
2456 bg->used = em->len; in fill_dummy_bgs()
2457 bg->flags = map->type; in fill_dummy_bgs()
2458 ret = btrfs_add_block_group_cache(fs_info, bg); in fill_dummy_bgs()
2465 btrfs_put_block_group(bg); in fill_dummy_bgs()
2470 btrfs_remove_free_space_cache(bg); in fill_dummy_bgs()
2471 btrfs_put_block_group(bg); in fill_dummy_bgs()
2475 btrfs_add_bg_to_space_info(fs_info, bg); in fill_dummy_bgs()
2477 set_avail_alloc_bits(fs_info, bg->flags); in fill_dummy_bgs()
3857 struct btrfs_block_group *bg; in do_chunk_alloc() local
3868 bg = btrfs_create_chunk(trans, flags); in do_chunk_alloc()
3869 if (IS_ERR(bg)) { in do_chunk_alloc()
3870 ret = PTR_ERR(bg); in do_chunk_alloc()
3874 ret = btrfs_chunk_alloc_add_chunk_item(trans, bg); in do_chunk_alloc()
3930 ret = btrfs_chunk_alloc_add_chunk_item(trans, bg); in do_chunk_alloc()
3945 btrfs_get_block_group(bg); in do_chunk_alloc()
3946 return bg; in do_chunk_alloc()
4237 struct btrfs_block_group *bg; in reserve_chunk_space() local
4245 bg = btrfs_create_chunk(trans, flags); in reserve_chunk_space()
4246 if (IS_ERR(bg)) { in reserve_chunk_space()
4247 ret = PTR_ERR(bg); in reserve_chunk_space()
4267 btrfs_chunk_alloc_add_chunk_item(trans, bg); in reserve_chunk_space()
4521 bool btrfs_inc_block_group_swap_extents(struct btrfs_block_group *bg) in btrfs_inc_block_group_swap_extents() argument
4525 spin_lock(&bg->lock); in btrfs_inc_block_group_swap_extents()
4526 if (bg->ro) in btrfs_inc_block_group_swap_extents()
4529 bg->swap_extents++; in btrfs_inc_block_group_swap_extents()
4530 spin_unlock(&bg->lock); in btrfs_inc_block_group_swap_extents()
4535 void btrfs_dec_block_group_swap_extents(struct btrfs_block_group *bg, int amount) in btrfs_dec_block_group_swap_extents() argument
4537 spin_lock(&bg->lock); in btrfs_dec_block_group_swap_extents()
4538 ASSERT(!bg->ro); in btrfs_dec_block_group_swap_extents()
4539 ASSERT(bg->swap_extents >= amount); in btrfs_dec_block_group_swap_extents()
4540 bg->swap_extents -= amount; in btrfs_dec_block_group_swap_extents()
4541 spin_unlock(&bg->lock); in btrfs_dec_block_group_swap_extents()
4572 int btrfs_use_block_group_size_class(struct btrfs_block_group *bg, in btrfs_use_block_group_size_class() argument
4579 if (bg->size_class == size_class) in btrfs_use_block_group_size_class()
4591 if (bg->size_class != BTRFS_BG_SZ_NONE) { in btrfs_use_block_group_size_class()
4600 bg->size_class = size_class; in btrfs_use_block_group_size_class()
4605 bool btrfs_block_group_should_use_size_class(struct btrfs_block_group *bg) in btrfs_block_group_should_use_size_class() argument
4607 if (btrfs_is_zoned(bg->fs_info)) in btrfs_block_group_should_use_size_class()
4609 if (!btrfs_is_block_group_data_only(bg)) in btrfs_block_group_should_use_size_class()