mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-12 08:46:38 +07:00
7ec1536e80
commit 2187374f35fe9cadbddaa9fcf0c4121365d914e8 upstream. Currently we pass things around to figure out if we maybe freeing data based on the state of the delayed refs head. This makes the accounting sort of confusing and hard to follow, as it's distinctly separate from the delayed ref heads stuff, but also depends on it entirely. Fix this by explicitly adjusting the space_info->total_bytes_pinned in the delayed refs code. We now have two places where we modify this counter, once where we create the delayed and destroy the delayed refs, and once when we pin and unpin the extents. This means there is a slight overlap between delayed refs and the pin/unpin mechanisms, but this is simply used by the ENOSPC infrastructure to determine if we need to commit the transaction, so there's no adverse affect from this, we might simply commit thinking it will give us enough space when it might not. CC: stable@vger.kernel.org # 5.10 Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
173 lines
5.5 KiB
C
173 lines
5.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef BTRFS_SPACE_INFO_H
|
|
#define BTRFS_SPACE_INFO_H
|
|
|
|
struct btrfs_space_info {
|
|
spinlock_t lock;
|
|
|
|
u64 total_bytes; /* total bytes in the space,
|
|
this doesn't take mirrors into account */
|
|
u64 bytes_used; /* total bytes used,
|
|
this doesn't take mirrors into account */
|
|
u64 bytes_pinned; /* total bytes pinned, will be freed when the
|
|
transaction finishes */
|
|
u64 bytes_reserved; /* total bytes the allocator has reserved for
|
|
current allocations */
|
|
u64 bytes_may_use; /* number of bytes that may be used for
|
|
delalloc/allocations */
|
|
u64 bytes_readonly; /* total bytes that are read only */
|
|
|
|
u64 max_extent_size; /* This will hold the maximum extent size of
|
|
the space info if we had an ENOSPC in the
|
|
allocator. */
|
|
|
|
unsigned int full:1; /* indicates that we cannot allocate any more
|
|
chunks for this space */
|
|
unsigned int chunk_alloc:1; /* set if we are allocating a chunk */
|
|
|
|
unsigned int flush:1; /* set if we are trying to make space */
|
|
|
|
unsigned int force_alloc; /* set if we need to force a chunk
|
|
alloc for this space */
|
|
|
|
u64 disk_used; /* total bytes used on disk */
|
|
u64 disk_total; /* total bytes on disk, takes mirrors into
|
|
account */
|
|
|
|
u64 flags;
|
|
|
|
/*
|
|
* bytes_pinned is kept in line with what is actually pinned, as in
|
|
* we've called update_block_group and dropped the bytes_used counter
|
|
* and increased the bytes_pinned counter. However this means that
|
|
* bytes_pinned does not reflect the bytes that will be pinned once the
|
|
* delayed refs are flushed, so this counter is inc'ed every time we
|
|
* call btrfs_free_extent so it is a realtime count of what will be
|
|
* freed once the transaction is committed. It will be zeroed every
|
|
* time the transaction commits.
|
|
*/
|
|
struct percpu_counter total_bytes_pinned;
|
|
|
|
struct list_head list;
|
|
/* Protected by the spinlock 'lock'. */
|
|
struct list_head ro_bgs;
|
|
struct list_head priority_tickets;
|
|
struct list_head tickets;
|
|
|
|
/*
|
|
* Size of space that needs to be reclaimed in order to satisfy pending
|
|
* tickets
|
|
*/
|
|
u64 reclaim_size;
|
|
|
|
/*
|
|
* tickets_id just indicates the next ticket will be handled, so note
|
|
* it's not stored per ticket.
|
|
*/
|
|
u64 tickets_id;
|
|
|
|
struct rw_semaphore groups_sem;
|
|
/* for block groups in our same type */
|
|
struct list_head block_groups[BTRFS_NR_RAID_TYPES];
|
|
|
|
struct kobject kobj;
|
|
struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES];
|
|
};
|
|
|
|
struct reserve_ticket {
|
|
u64 bytes;
|
|
int error;
|
|
bool steal;
|
|
struct list_head list;
|
|
wait_queue_head_t wait;
|
|
};
|
|
|
|
static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
|
|
{
|
|
return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) &&
|
|
(space_info->flags & BTRFS_BLOCK_GROUP_DATA));
|
|
}
|
|
|
|
/*
|
|
*
|
|
* Declare a helper function to detect underflow of various space info members
|
|
*/
|
|
#define DECLARE_SPACE_INFO_UPDATE(name, trace_name) \
|
|
static inline void \
|
|
btrfs_space_info_update_##name(struct btrfs_fs_info *fs_info, \
|
|
struct btrfs_space_info *sinfo, \
|
|
s64 bytes) \
|
|
{ \
|
|
const u64 abs_bytes = (bytes < 0) ? -bytes : bytes; \
|
|
lockdep_assert_held(&sinfo->lock); \
|
|
trace_update_##name(fs_info, sinfo, sinfo->name, bytes); \
|
|
trace_btrfs_space_reservation(fs_info, trace_name, \
|
|
sinfo->flags, abs_bytes, \
|
|
bytes > 0); \
|
|
if (bytes < 0 && sinfo->name < -bytes) { \
|
|
WARN_ON(1); \
|
|
sinfo->name = 0; \
|
|
return; \
|
|
} \
|
|
sinfo->name += bytes; \
|
|
}
|
|
|
|
DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info");
|
|
DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
|
|
|
|
int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
|
|
void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags,
|
|
u64 total_bytes, u64 bytes_used,
|
|
u64 bytes_readonly,
|
|
struct btrfs_space_info **space_info);
|
|
struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
|
|
u64 flags);
|
|
u64 __pure btrfs_space_info_used(struct btrfs_space_info *s_info,
|
|
bool may_use_included);
|
|
void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
|
|
void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
|
|
struct btrfs_space_info *info, u64 bytes,
|
|
int dump_block_groups);
|
|
int btrfs_reserve_metadata_bytes(struct btrfs_root *root,
|
|
struct btrfs_block_rsv *block_rsv,
|
|
u64 orig_bytes,
|
|
enum btrfs_reserve_flush_enum flush);
|
|
void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
|
|
struct btrfs_space_info *space_info);
|
|
int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
|
|
struct btrfs_space_info *space_info, u64 bytes,
|
|
enum btrfs_reserve_flush_enum flush);
|
|
|
|
static inline void btrfs_space_info_free_bytes_may_use(
|
|
struct btrfs_fs_info *fs_info,
|
|
struct btrfs_space_info *space_info,
|
|
u64 num_bytes)
|
|
{
|
|
spin_lock(&space_info->lock);
|
|
btrfs_space_info_update_bytes_may_use(fs_info, space_info, -num_bytes);
|
|
btrfs_try_granting_tickets(fs_info, space_info);
|
|
spin_unlock(&space_info->lock);
|
|
}
|
|
int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes,
|
|
enum btrfs_reserve_flush_enum flush);
|
|
|
|
static inline void __btrfs_mod_total_bytes_pinned(
|
|
struct btrfs_space_info *space_info,
|
|
s64 mod)
|
|
{
|
|
percpu_counter_add_batch(&space_info->total_bytes_pinned, mod,
|
|
BTRFS_TOTAL_BYTES_PINNED_BATCH);
|
|
}
|
|
|
|
static inline void btrfs_mod_total_bytes_pinned(struct btrfs_fs_info *fs_info,
|
|
u64 flags, s64 mod)
|
|
{
|
|
struct btrfs_space_info *space_info = btrfs_find_space_info(fs_info, flags);
|
|
|
|
ASSERT(space_info);
|
|
__btrfs_mod_total_bytes_pinned(space_info, mod);
|
|
}
|
|
|
|
#endif /* BTRFS_SPACE_INFO_H */
|