2019-06-19 04:09:16 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
|
|
|
#ifndef BTRFS_SPACE_INFO_H
|
|
|
|
#define BTRFS_SPACE_INFO_H
|
|
|
|
|
2022-04-20 16:08:27 +08:00
|
|
|
#include "volumes.h"
|
|
|
|
|
2019-06-19 04:09:16 +08:00
|
|
|
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 */
|
2022-07-09 07:18:45 +08:00
|
|
|
/* Total bytes in the space, but only accounts active block groups. */
|
|
|
|
u64 active_total_bytes;
|
2021-02-04 18:21:52 +08:00
|
|
|
u64 bytes_zone_unusable; /* total bytes that are unusable until
|
|
|
|
resetting the device zone */
|
2019-06-19 04:09:16 +08:00
|
|
|
|
|
|
|
u64 max_extent_size; /* This will hold the maximum extent size of
|
|
|
|
the space info if we had an ENOSPC in the
|
|
|
|
allocator. */
|
2022-02-09 03:31:20 +08:00
|
|
|
/* Chunk size in bytes */
|
|
|
|
u64 chunk_size;
|
2019-06-19 04:09:16 +08:00
|
|
|
|
2022-03-29 16:56:06 +08:00
|
|
|
/*
|
|
|
|
* Once a block group drops below this threshold (percents) we'll
|
|
|
|
* schedule it for reclaim.
|
|
|
|
*/
|
|
|
|
int bg_reclaim_threshold;
|
|
|
|
|
2020-10-09 21:28:27 +08:00
|
|
|
int clamp; /* Used to scale our threshold for preemptive
|
|
|
|
flushing. The value is >> clamp, so turns
|
|
|
|
out to be a 2^clamp divisor. */
|
|
|
|
|
2019-06-19 04:09:16 +08:00
|
|
|
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;
|
|
|
|
|
|
|
|
struct list_head list;
|
|
|
|
/* Protected by the spinlock 'lock'. */
|
|
|
|
struct list_head ro_bgs;
|
|
|
|
struct list_head priority_tickets;
|
|
|
|
struct list_head tickets;
|
2020-03-10 17:00:35 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Size of space that needs to be reclaimed in order to satisfy pending
|
|
|
|
* tickets
|
|
|
|
*/
|
|
|
|
u64 reclaim_size;
|
|
|
|
|
2019-06-19 04:09:16 +08:00
|
|
|
/*
|
|
|
|
* 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];
|
|
|
|
};
|
|
|
|
|
2019-06-19 04:09:22 +08:00
|
|
|
struct reserve_ticket {
|
|
|
|
u64 bytes;
|
|
|
|
int error;
|
2020-03-14 03:58:05 +08:00
|
|
|
bool steal;
|
2019-06-19 04:09:22 +08:00
|
|
|
struct list_head list;
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
};
|
|
|
|
|
2019-06-19 04:09:16 +08:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2019-06-19 04:09:21 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Declare a helper function to detect underflow of various space info members
|
|
|
|
*/
|
2019-08-23 03:10:55 +08:00
|
|
|
#define DECLARE_SPACE_INFO_UPDATE(name, trace_name) \
|
2019-06-19 04:09:21 +08:00
|
|
|
static inline void \
|
|
|
|
btrfs_space_info_update_##name(struct btrfs_fs_info *fs_info, \
|
|
|
|
struct btrfs_space_info *sinfo, \
|
|
|
|
s64 bytes) \
|
|
|
|
{ \
|
2019-08-23 03:10:55 +08:00
|
|
|
const u64 abs_bytes = (bytes < 0) ? -bytes : bytes; \
|
2019-06-19 04:09:21 +08:00
|
|
|
lockdep_assert_held(&sinfo->lock); \
|
|
|
|
trace_update_##name(fs_info, sinfo, sinfo->name, bytes); \
|
2019-08-23 03:10:55 +08:00
|
|
|
trace_btrfs_space_reservation(fs_info, trace_name, \
|
|
|
|
sinfo->flags, abs_bytes, \
|
|
|
|
bytes > 0); \
|
2019-06-19 04:09:21 +08:00
|
|
|
if (bytes < 0 && sinfo->name < -bytes) { \
|
|
|
|
WARN_ON(1); \
|
|
|
|
sinfo->name = 0; \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
sinfo->name += bytes; \
|
|
|
|
}
|
|
|
|
|
2019-08-23 03:10:55 +08:00
|
|
|
DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info");
|
|
|
|
DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
|
2019-06-19 04:09:21 +08:00
|
|
|
|
2019-06-19 04:09:19 +08:00
|
|
|
int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
|
2022-07-16 03:45:22 +08:00
|
|
|
void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
|
2022-07-16 03:45:23 +08:00
|
|
|
struct btrfs_block_group *block_group);
|
2022-02-09 03:31:20 +08:00
|
|
|
void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
|
|
|
|
u64 chunk_size);
|
2019-06-19 04:09:19 +08:00
|
|
|
struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
|
|
|
|
u64 flags);
|
2019-10-02 01:57:39 +08:00
|
|
|
u64 __pure btrfs_space_info_used(struct btrfs_space_info *s_info,
|
2019-06-19 04:09:19 +08:00
|
|
|
bool may_use_included);
|
|
|
|
void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
|
2019-06-19 04:09:24 +08:00
|
|
|
void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_space_info *info, u64 bytes,
|
|
|
|
int dump_block_groups);
|
2021-11-09 23:12:07 +08:00
|
|
|
int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
|
2019-06-19 04:09:25 +08:00
|
|
|
struct btrfs_block_rsv *block_rsv,
|
|
|
|
u64 orig_bytes,
|
|
|
|
enum btrfs_reserve_flush_enum flush);
|
2019-08-23 03:10:58 +08:00
|
|
|
void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_space_info *space_info);
|
2020-01-17 22:07:39 +08:00
|
|
|
int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_space_info *space_info, u64 bytes,
|
|
|
|
enum btrfs_reserve_flush_enum flush);
|
2019-08-23 03:10:58 +08:00
|
|
|
|
2019-08-23 03:11:02 +08:00
|
|
|
static inline void btrfs_space_info_free_bytes_may_use(
|
2019-08-23 03:10:58 +08:00
|
|
|
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);
|
|
|
|
}
|
2020-07-21 22:22:25 +08:00
|
|
|
int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes,
|
|
|
|
enum btrfs_reserve_flush_enum flush);
|
btrfs: dump all space infos if we abort transaction due to ENOSPC
We have hit some transaction abort due to -ENOSPC internally.
Normally we should always reserve enough space for metadata for every
transaction, thus hitting -ENOSPC should really indicate some cases we
didn't expect.
But unfortunately current error reporting will only give a kernel
warning and stack trace, not really helpful to debug what's causing the
problem.
And mount option debug_enospc can only help when user can reproduce the
problem, but under most cases, such transaction abort by -ENOSPC is
really hard to reproduce.
So this patch will dump all space infos (data, metadata, system) when we
abort the first transaction with -ENOSPC.
This should at least provide some clue to us.
The example of a dump would look like this:
BTRFS: Transaction aborted (error -28)
WARNING: CPU: 8 PID: 3366 at fs/btrfs/transaction.c:2137 btrfs_commit_transaction+0xf81/0xfb0 [btrfs]
<call trace skipped>
---[ end trace 0000000000000000 ]---
BTRFS info (device dm-1: state A): dumping space info:
BTRFS info (device dm-1: state A): space_info DATA has 6791168 free, is not full
BTRFS info (device dm-1: state A): space_info total=8388608, used=1597440, pinned=0, reserved=0, may_use=0, readonly=0 zone_unusable=0
BTRFS info (device dm-1: state A): space_info METADATA has 257114112 free, is not full
BTRFS info (device dm-1: state A): space_info total=268435456, used=131072, pinned=180224, reserved=65536, may_use=10878976, readonly=65536 zone_unusable=0
BTRFS info (device dm-1: state A): space_info SYSTEM has 8372224 free, is not full
BTRFS info (device dm-1: state A): space_info total=8388608, used=16384, pinned=0, reserved=0, may_use=0, readonly=0 zone_unusable=0
BTRFS info (device dm-1: state A): global_block_rsv: size 3670016 reserved 3670016
BTRFS info (device dm-1: state A): trans_block_rsv: size 0 reserved 0
BTRFS info (device dm-1: state A): chunk_block_rsv: size 0 reserved 0
BTRFS info (device dm-1: state A): delayed_block_rsv: size 4063232 reserved 4063232
BTRFS info (device dm-1: state A): delayed_refs_rsv: size 3145728 reserved 3145728
BTRFS: error (device dm-1: state A) in btrfs_commit_transaction:2137: errno=-28 No space left
BTRFS info (device dm-1: state EA): forced readonly
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-25 15:09:10 +08:00
|
|
|
void btrfs_dump_space_info_for_trans_abort(struct btrfs_fs_info *fs_info);
|
2022-09-15 07:04:39 +08:00
|
|
|
void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info);
|
btrfs: dump all space infos if we abort transaction due to ENOSPC
We have hit some transaction abort due to -ENOSPC internally.
Normally we should always reserve enough space for metadata for every
transaction, thus hitting -ENOSPC should really indicate some cases we
didn't expect.
But unfortunately current error reporting will only give a kernel
warning and stack trace, not really helpful to debug what's causing the
problem.
And mount option debug_enospc can only help when user can reproduce the
problem, but under most cases, such transaction abort by -ENOSPC is
really hard to reproduce.
So this patch will dump all space infos (data, metadata, system) when we
abort the first transaction with -ENOSPC.
This should at least provide some clue to us.
The example of a dump would look like this:
BTRFS: Transaction aborted (error -28)
WARNING: CPU: 8 PID: 3366 at fs/btrfs/transaction.c:2137 btrfs_commit_transaction+0xf81/0xfb0 [btrfs]
<call trace skipped>
---[ end trace 0000000000000000 ]---
BTRFS info (device dm-1: state A): dumping space info:
BTRFS info (device dm-1: state A): space_info DATA has 6791168 free, is not full
BTRFS info (device dm-1: state A): space_info total=8388608, used=1597440, pinned=0, reserved=0, may_use=0, readonly=0 zone_unusable=0
BTRFS info (device dm-1: state A): space_info METADATA has 257114112 free, is not full
BTRFS info (device dm-1: state A): space_info total=268435456, used=131072, pinned=180224, reserved=65536, may_use=10878976, readonly=65536 zone_unusable=0
BTRFS info (device dm-1: state A): space_info SYSTEM has 8372224 free, is not full
BTRFS info (device dm-1: state A): space_info total=8388608, used=16384, pinned=0, reserved=0, may_use=0, readonly=0 zone_unusable=0
BTRFS info (device dm-1: state A): global_block_rsv: size 3670016 reserved 3670016
BTRFS info (device dm-1: state A): trans_block_rsv: size 0 reserved 0
BTRFS info (device dm-1: state A): chunk_block_rsv: size 0 reserved 0
BTRFS info (device dm-1: state A): delayed_block_rsv: size 4063232 reserved 4063232
BTRFS info (device dm-1: state A): delayed_refs_rsv: size 3145728 reserved 3145728
BTRFS: error (device dm-1: state A) in btrfs_commit_transaction:2137: errno=-28 No space left
BTRFS info (device dm-1: state EA): forced readonly
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-25 15:09:10 +08:00
|
|
|
|
2019-06-19 04:09:16 +08:00
|
|
|
#endif /* BTRFS_SPACE_INFO_H */
|