Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5e49c78
btrfs: add flags to give an hint to the chunk allocator
kreijack Oct 24, 2021
160344a
btrfs: export dev_item.type in /sys/fs/btrfs/<uuid>/devinfo/<devid>/type
kreijack Oct 24, 2021
29637f2
btrfs: change the DEV_ITEM 'type' field via sysfs
kreijack Oct 24, 2021
970b99e
btrfs: add allocator_hint mode
kreijack Oct 24, 2021
1c1f2e2
btrfs: add allocator_hint for no allocation preferred
kakra Jun 27, 2024
82553ef
btrfs: add allocator_hint to disable allocation completely
kakra Dec 5, 2024
10248db
btrfs: simplify output formatting in btrfs_read_policy_show
asj Jan 1, 2025
4a49a27
btrfs: initialize fs_devices->fs_info earlier
asj Jan 1, 2025
ccb2922
btrfs: add btrfs_read_policy_to_enum helper and refactor read policy …
asj Jan 1, 2025
cf73e90
btrfs: add tracking of read blocks for read policy
asj Jan 1, 2025
7070070
btrfs: introduce CONFIG_BTRFS_EXPERIMENTAL from 6.13
kakra Sep 16, 2024
3efa6c7
btrfs: handle value associated with read policy parameter
asj Jan 1, 2025
6f1b9b1
btrfs: introduce RAID1 round-robin read balancing
kakra May 2, 2025
6fcee9b
btrfs: add RAID1 preferred read device
asj Jan 1, 2025
b627950
btrfs: expose experimental mode in module information
asj Jan 1, 2025
108c5e8
btrfs: enable read policy configuration via modprobe parameter
asj Jan 1, 2025
b2c5980
btrfs: modload to print read policy status
asj Jan 1, 2025
65b747f
btrfs: use the path with the lowest latency for RAID1 reads
asj Oct 11, 2024
a6dfeed
btrfs: move latency-based selection into helper
kakra Apr 9, 2025
c9b6612
btrfs: fix btrfs_read_rr to use the actual number of stripes
kakra Apr 9, 2025
5aa9fb5
btrfs: create a helper instead of open coding device latency calculation
kakra Apr 15, 2025
a451102
btrfs: add filtering by latency to btrfs_read_rr
kakra Apr 14, 2025
9e88f8e
btrfs: add hybrid latency-rr read policy
kakra Apr 18, 2025
eee7666
btrfs: add devinfo read stats to sysfs
kakra Apr 16, 2025
7437625
btrfs: add last IO age to sysfs read_stats
kakra Apr 16, 2025
7c776c2
btrfs: probe read latency if device is 1000 IOs behind its siblings
kakra Apr 16, 2025
fbeb5da
btrfs: allow a short burst of IO for probing read latency
kakra Apr 17, 2025
919eaf1
btrfs: use checkpoint latency instead of cumulative latency
kakra Apr 20, 2025
6f8dc12
btrfs: stat latency checkpoints to get more insight
kakra Apr 20, 2025
18c0ef0
btrfs: rename thresholds to better match with the checkpoint logic
kakra Apr 20, 2025
f4f2455
btrfs: add a stripe ignored counter
kakra Apr 20, 2025
db46d71
btrfs: tune age and burst for latency checkpoint
kakra Apr 21, 2025
504aea7
btrfs: add in-flight queue read policy
kakra Apr 25, 2025
e905c0c
btrfs: guard access to bdev in latency stats and inflight calculation
kakra Apr 27, 2025
740955e
btrfs: reduce atomic reads where possible in btrfs_device_read_latency
kakra May 1, 2025
abf6174
TEST: btrfs: btrfs_backref_resched.patch
fdmanana Jun 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
btrfs: add allocator_hint mode
When this mode is enabled, the chunk allocation policy is modified as
follow.

Each disk may have a different tag:
- BTRFS_DEV_ALLOCATION_PREFERRED_METADATA
- BTRFS_DEV_ALLOCATION_METADATA_ONLY
- BTRFS_DEV_ALLOCATION_DATA_ONLY
- BTRFS_DEV_ALLOCATION_PREFERRED_DATA (default)

Where:
- ALLOCATION_PREFERRED_X means that it is preferred to use this disk for
the X chunk type (the other type may be allowed when the space is low)
- ALLOCATION_X_ONLY means that it is used *only* for the X chunk type.
This means also that it is a preferred choice.

Each time the allocator allocates a chunk of type X , first it takes the
disks tagged as ALLOCATION_X_ONLY or ALLOCATION_PREFERRED_X; if the space
is not enough, it uses also the disks tagged as ALLOCATION_METADATA_ONLY;
if the space is not enough, it uses also the other disks, with the
exception of the one marked as ALLOCATION_PREFERRED_Y, where Y the other
type of chunk (i.e. not X).

Signed-off-by: Goffredo Baroncelli <[email protected]>
  • Loading branch information
kreijack authored and kakra committed Nov 18, 2024
commit 970b99e160487e9765b6e7db9f8a89a96ce79811
97 changes: 96 additions & 1 deletion fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
return BTRFS_BG_FLAG_TO_INDEX(profile);
}

#define BTRFS_DEV_ALLOCATION_MASK ((1ULL << \
BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT) - 1)
#define BTRFS_DEV_ALLOCATION_MASK_COUNT (1ULL << \
BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT)

static const char alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
[BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1,
[BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
[BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
[BTRFS_DEV_ALLOCATION_METADATA_ONLY] = 2,
/* the other values are set to 0 */
};

const char *btrfs_bg_type_to_raid_name(u64 flags)
{
const int index = btrfs_bg_flags_to_raid_index(flags);
Expand Down Expand Up @@ -5022,13 +5035,18 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
}

/*
* sort the devices in descending order by max_avail, total_avail
* sort the devices in descending order by alloc_hint,
* max_avail, total_avail
*/
static int btrfs_cmp_device_info(const void *a, const void *b)
{
const struct btrfs_device_info *di_a = a;
const struct btrfs_device_info *di_b = b;

if (di_a->alloc_hint > di_b->alloc_hint)
return -1;
if (di_a->alloc_hint < di_b->alloc_hint)
return 1;
if (di_a->max_avail > di_b->max_avail)
return -1;
if (di_a->max_avail < di_b->max_avail)
Expand Down Expand Up @@ -5181,6 +5199,8 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
int ndevs = 0;
u64 max_avail;
u64 dev_offset;
int hint;
int i;

/*
* in the first pass through the devices list, we gather information
Expand Down Expand Up @@ -5233,16 +5253,91 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
devices_info[ndevs].max_avail = max_avail;
devices_info[ndevs].total_avail = total_avail;
devices_info[ndevs].dev = device;

if ((ctl->type & BTRFS_BLOCK_GROUP_DATA) &&
(ctl->type & BTRFS_BLOCK_GROUP_METADATA)) {
/*
* if mixed bg set all the alloc_hint
* fields to the same value, so the sorting
* is not affected
*/
devices_info[ndevs].alloc_hint = 0;
} else if (ctl->type & BTRFS_BLOCK_GROUP_DATA) {
hint = device->type & BTRFS_DEV_ALLOCATION_MASK;

/*
* skip BTRFS_DEV_METADATA_ONLY disks
*/
if (hint == BTRFS_DEV_ALLOCATION_METADATA_ONLY)
continue;
/*
* if a data chunk must be allocated,
* sort also by hint (data disk
* higher priority)
*/
devices_info[ndevs].alloc_hint = -alloc_hint_map[hint];
} else { /* BTRFS_BLOCK_GROUP_METADATA */
hint = device->type & BTRFS_DEV_ALLOCATION_MASK;

/*
* skip BTRFS_DEV_DATA_ONLY disks
*/
if (hint == BTRFS_DEV_ALLOCATION_DATA_ONLY)
continue;
/*
* if a data chunk must be allocated,
* sort also by hint (metadata hint
* higher priority)
*/
devices_info[ndevs].alloc_hint = alloc_hint_map[hint];
}

++ndevs;
}
ctl->ndevs = ndevs;

/*
* no devices available
*/
if (!ndevs)
return 0;

/*
* now sort the devices by hole size / available space
*/
sort(devices_info, ndevs, sizeof(struct btrfs_device_info),
btrfs_cmp_device_info, NULL);

/*
* select the minimum set of disks grouped by hint that
* can host the chunk
*/
ndevs = 0;
while (ndevs < ctl->ndevs) {
hint = devices_info[ndevs++].alloc_hint;
while (ndevs < ctl->ndevs &&
devices_info[ndevs].alloc_hint == hint)
ndevs++;
if (ndevs >= ctl->devs_min)
break;
}

BUG_ON(ndevs > ctl->ndevs);
ctl->ndevs = ndevs;

/*
* the next layers require the devices_info ordered by
* max_avail. If we are returing two (or more) different
* group of alloc_hint, this is not always true. So sort
* these gain.
*/

for (i = 0 ; i < ndevs ; i++)
devices_info[i].alloc_hint = 0;

sort(devices_info, ndevs, sizeof(struct btrfs_device_info),
btrfs_cmp_device_info, NULL);

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/volumes.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ struct btrfs_device_info {
u64 dev_offset;
u64 max_avail;
u64 total_avail;
int alloc_hint;
};

struct btrfs_raid_attr {
Expand Down