2017-03-16 22:18:50 -08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _BCACHEFS_REBALANCE_H
|
|
|
|
#define _BCACHEFS_REBALANCE_H
|
|
|
|
|
2024-10-26 01:42:57 -04:00
|
|
|
#include "compress.h"
|
|
|
|
#include "disk_groups.h"
|
2025-01-25 21:29:45 -05:00
|
|
|
#include "opts.h"
|
2017-03-16 22:18:50 -08:00
|
|
|
#include "rebalance_types.h"
|
|
|
|
|
2025-01-25 21:29:45 -05:00
|
|
|
static inline struct bch_extent_rebalance io_opts_to_rebalance_opts(struct bch_fs *c,
|
|
|
|
struct bch_io_opts *opts)
|
|
|
|
{
|
|
|
|
struct bch_extent_rebalance r = {
|
|
|
|
.type = BIT(BCH_EXTENT_ENTRY_rebalance),
|
|
|
|
#define x(_name) \
|
|
|
|
._name = opts->_name, \
|
|
|
|
._name##_from_inode = opts->_name##_from_inode,
|
|
|
|
BCH_REBALANCE_OPTS()
|
|
|
|
#undef x
|
|
|
|
};
|
|
|
|
|
|
|
|
if (r.background_target &&
|
|
|
|
!bch2_target_accepts_data(c, BCH_DATA_user, r.background_target))
|
|
|
|
r.background_target = 0;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
2024-10-28 23:23:18 -04:00
|
|
|
u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *, struct bkey_s_c);
|
|
|
|
int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bch_io_opts *, struct bkey_i *);
|
|
|
|
int bch2_get_update_rebalance_opts(struct btree_trans *,
|
|
|
|
struct bch_io_opts *,
|
|
|
|
struct btree_iter *,
|
|
|
|
struct bkey_s_c);
|
2024-10-26 01:42:57 -04:00
|
|
|
|
2024-10-20 20:53:53 -04:00
|
|
|
int bch2_set_rebalance_needs_scan_trans(struct btree_trans *, u64);
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 13:33:14 -04:00
|
|
|
int bch2_set_rebalance_needs_scan(struct bch_fs *, u64 inum);
|
|
|
|
int bch2_set_fs_needs_rebalance(struct bch_fs *);
|
|
|
|
|
2025-04-15 10:26:05 -04:00
|
|
|
static inline void bch2_rebalance_wakeup(struct bch_fs *c)
|
2017-03-16 22:18:50 -08:00
|
|
|
{
|
2025-05-24 15:29:50 -04:00
|
|
|
c->rebalance.kick++;
|
|
|
|
guard(rcu)();
|
|
|
|
struct task_struct *p = rcu_dereference(c->rebalance.thread);
|
2017-03-16 22:18:50 -08:00
|
|
|
if (p)
|
|
|
|
wake_up_process(p);
|
|
|
|
}
|
|
|
|
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 13:33:14 -04:00
|
|
|
void bch2_rebalance_status_to_text(struct printbuf *, struct bch_fs *);
|
2017-03-16 22:18:50 -08:00
|
|
|
|
|
|
|
void bch2_rebalance_stop(struct bch_fs *);
|
|
|
|
int bch2_rebalance_start(struct bch_fs *);
|
2025-05-05 20:35:36 -04:00
|
|
|
|
|
|
|
void bch2_fs_rebalance_exit(struct bch_fs *);
|
|
|
|
int bch2_fs_rebalance_init(struct bch_fs *);
|
2017-03-16 22:18:50 -08:00
|
|
|
|
2025-03-14 09:46:25 -04:00
|
|
|
int bch2_check_rebalance_work(struct bch_fs *);
|
|
|
|
|
2017-03-16 22:18:50 -08:00
|
|
|
#endif /* _BCACHEFS_REBALANCE_H */
|