Commit 7b3f84ea authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Split out alloc_background.c

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f43cc5be
...@@ -3,7 +3,8 @@ obj-$(CONFIG_BCACHEFS_FS) += bcachefs.o ...@@ -3,7 +3,8 @@ obj-$(CONFIG_BCACHEFS_FS) += bcachefs.o
bcachefs-y := \ bcachefs-y := \
acl.o \ acl.o \
alloc.o \ alloc_background.o \
alloc_foreground.o \
bkey.o \ bkey.o \
bkey_methods.o \ bkey_methods.o \
bset.o \ bset.o \
......
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BCACHEFS_ALLOC_BACKGROUND_H
#define _BCACHEFS_ALLOC_BACKGROUND_H
#include "bcachefs.h"
#include "alloc_types.h"
#include "debug.h"
#define ALLOC_SCAN_BATCH(ca) ((ca)->mi.nbuckets >> 9)
const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);
int bch2_alloc_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
#define bch2_bkey_alloc_ops (struct bkey_ops) { \
.key_invalid = bch2_alloc_invalid, \
.val_to_text = bch2_alloc_to_text, \
}
int bch2_alloc_read(struct bch_fs *, struct list_head *);
int bch2_alloc_replay_key(struct bch_fs *, struct bpos);
static inline void bch2_wake_allocator(struct bch_dev *ca)
{
struct task_struct *p;
rcu_read_lock();
p = rcu_dereference(ca->alloc_thread);
if (p)
wake_up_process(p);
rcu_read_unlock();
}
static inline void verify_not_on_freelist(struct bch_fs *c, struct bch_dev *ca,
size_t bucket)
{
if (expensive_debug_checks(c) &&
test_bit(BCH_FS_ALLOCATOR_STARTED, &c->flags)) {
size_t iter;
long i;
unsigned j;
for (j = 0; j < RESERVE_NR; j++)
fifo_for_each_entry(i, &ca->free[j], iter)
BUG_ON(i == bucket);
fifo_for_each_entry(i, &ca->free_inc, iter)
BUG_ON(i == bucket);
}
}
void bch2_recalc_capacity(struct bch_fs *);
void bch2_dev_allocator_remove(struct bch_fs *, struct bch_dev *);
void bch2_dev_allocator_add(struct bch_fs *, struct bch_dev *);
void bch2_dev_allocator_stop(struct bch_dev *);
int bch2_dev_allocator_start(struct bch_dev *);
int bch2_alloc_write(struct bch_fs *);
int bch2_fs_allocator_start(struct bch_fs *);
void bch2_fs_allocator_init(struct bch_fs *);
#endif /* _BCACHEFS_ALLOC_BACKGROUND_H */
This diff is collapsed.
#ifndef _BCACHEFS_ALLOC_H /* SPDX-License-Identifier: GPL-2.0 */
#define _BCACHEFS_ALLOC_H #ifndef _BCACHEFS_ALLOC_FOREGROUND_H
#define _BCACHEFS_ALLOC_FOREGROUND_H
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_types.h" #include "alloc_types.h"
...@@ -9,16 +10,6 @@ struct bch_dev; ...@@ -9,16 +10,6 @@ struct bch_dev;
struct bch_fs; struct bch_fs;
struct bch_devs_List; struct bch_devs_List;
#define ALLOC_SCAN_BATCH(ca) ((ca)->mi.nbuckets >> 9)
const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);
int bch2_alloc_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
#define bch2_bkey_alloc_ops (struct bkey_ops) { \
.key_invalid = bch2_alloc_invalid, \
.val_to_text = bch2_alloc_to_text, \
}
struct dev_alloc_list { struct dev_alloc_list {
unsigned nr; unsigned nr;
u8 devs[BCH_SB_MEMBERS_MAX]; u8 devs[BCH_SB_MEMBERS_MAX];
...@@ -30,16 +21,6 @@ struct dev_alloc_list bch2_wp_alloc_list(struct bch_fs *, ...@@ -30,16 +21,6 @@ struct dev_alloc_list bch2_wp_alloc_list(struct bch_fs *,
void bch2_wp_rescale(struct bch_fs *, struct bch_dev *, void bch2_wp_rescale(struct bch_fs *, struct bch_dev *,
struct write_point *); struct write_point *);
int bch2_alloc_read(struct bch_fs *, struct list_head *);
int bch2_alloc_replay_key(struct bch_fs *, struct bpos);
enum bucket_alloc_ret {
ALLOC_SUCCESS = 0,
OPEN_BUCKETS_EMPTY = -1,
FREELIST_EMPTY = -2, /* Allocator thread not keeping up */
NO_DEVICES = -3, /* -EROFS */
};
long bch2_bucket_alloc_new_fs(struct bch_dev *); long bch2_bucket_alloc_new_fs(struct bch_dev *);
int bch2_bucket_alloc(struct bch_fs *, struct bch_dev *, enum alloc_reserve, bool, int bch2_bucket_alloc(struct bch_fs *, struct bch_dev *, enum alloc_reserve, bool,
...@@ -100,15 +81,19 @@ void bch2_alloc_sectors_append_ptrs(struct bch_fs *, struct write_point *, ...@@ -100,15 +81,19 @@ void bch2_alloc_sectors_append_ptrs(struct bch_fs *, struct write_point *,
struct bkey_i_extent *, unsigned); struct bkey_i_extent *, unsigned);
void bch2_alloc_sectors_done(struct bch_fs *, struct write_point *); void bch2_alloc_sectors_done(struct bch_fs *, struct write_point *);
static inline void bch2_wake_allocator(struct bch_dev *ca) void bch2_writepoint_stop(struct bch_fs *, struct bch_dev *,
struct write_point *);
void bch2_writepoint_drop_ptrs(struct bch_fs *, struct write_point *,
u16, bool);
static inline struct hlist_head *writepoint_hash(struct bch_fs *c,
unsigned long write_point)
{ {
struct task_struct *p; unsigned hash =
hash_long(write_point, ilog2(ARRAY_SIZE(c->write_points_hash)));
rcu_read_lock(); return &c->write_points_hash[hash];
p = rcu_dereference(ca->alloc_thread);
if (p)
wake_up_process(p);
rcu_read_unlock();
} }
static inline struct write_point_specifier writepoint_hashed(unsigned long v) static inline struct write_point_specifier writepoint_hashed(unsigned long v)
...@@ -121,14 +106,6 @@ static inline struct write_point_specifier writepoint_ptr(struct write_point *wp ...@@ -121,14 +106,6 @@ static inline struct write_point_specifier writepoint_ptr(struct write_point *wp
return (struct write_point_specifier) { .v = (unsigned long) wp }; return (struct write_point_specifier) { .v = (unsigned long) wp };
} }
void bch2_recalc_capacity(struct bch_fs *);
void bch2_dev_allocator_remove(struct bch_fs *, struct bch_dev *);
void bch2_dev_allocator_add(struct bch_fs *, struct bch_dev *);
void bch2_dev_allocator_stop(struct bch_dev *);
int bch2_dev_allocator_start(struct bch_dev *);
static inline void writepoint_init(struct write_point *wp, static inline void writepoint_init(struct write_point *wp,
enum bch_data_type type) enum bch_data_type type)
{ {
...@@ -136,8 +113,4 @@ static inline void writepoint_init(struct write_point *wp, ...@@ -136,8 +113,4 @@ static inline void writepoint_init(struct write_point *wp,
wp->type = type; wp->type = type;
} }
int bch2_alloc_write(struct bch_fs *); #endif /* _BCACHEFS_ALLOC_FOREGROUND_H */
int bch2_fs_allocator_start(struct bch_fs *);
void bch2_fs_allocator_init(struct bch_fs *);
#endif /* _BCACHEFS_ALLOC_H */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_methods.h" #include "bkey_methods.h"
#include "btree_types.h" #include "btree_types.h"
#include "alloc.h" #include "alloc_background.h"
#include "dirent.h" #include "dirent.h"
#include "error.h" #include "error.h"
#include "extents.h" #include "extents.h"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_background.h"
#include "bkey_methods.h" #include "bkey_methods.h"
#include "btree_locking.h" #include "btree_locking.h"
#include "btree_update_interior.h" #include "btree_update_interior.h"
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_foreground.h"
#include "bkey_methods.h" #include "bkey_methods.h"
#include "btree_cache.h" #include "btree_cache.h"
#include "btree_gc.h" #include "btree_gc.h"
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
*/ */
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_background.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "buckets.h" #include "buckets.h"
#include "error.h" #include "error.h"
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#ifndef NO_BCACHEFS_CHARDEV #ifndef NO_BCACHEFS_CHARDEV
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h"
#include "bcachefs_ioctl.h" #include "bcachefs_ioctl.h"
#include "buckets.h" #include "buckets.h"
#include "chardev.h" #include "chardev.h"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#ifndef NO_BCACHEFS_FS #ifndef NO_BCACHEFS_FS
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_foreground.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
#include "clock.h" #include "clock.h"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
*/ */
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_foreground.h"
#include "bset.h" #include "bset.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#ifndef _BCACHEFS_IO_H #ifndef _BCACHEFS_IO_H
#define _BCACHEFS_IO_H #define _BCACHEFS_IO_H
#include "alloc.h"
#include "checksum.h" #include "checksum.h"
#include "io_types.h" #include "io_types.h"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
*/ */
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_foreground.h"
#include "bkey_methods.h" #include "bkey_methods.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "buckets.h" #include "buckets.h"
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_background.h"
#include "alloc_foreground.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_foreground.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc_foreground.h"
#include "btree_iter.h" #include "btree_iter.h"
#include "btree_update.h" #include "btree_update.h"
#include "buckets.h" #include "buckets.h"
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_foreground.h"
#include "btree_iter.h" #include "btree_iter.h"
#include "buckets.h" #include "buckets.h"
#include "clock.h" #include "clock.h"
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_background.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "btree_update.h" #include "btree_update.h"
#include "btree_update_interior.h" #include "btree_update_interior.h"
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
*/ */
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_background.h"
#include "alloc_foreground.h"
#include "btree_cache.h" #include "btree_cache.h"
#include "btree_gc.h" #include "btree_gc.h"
#include "btree_update_interior.h" #include "btree_update_interior.h"
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef NO_BCACHEFS_SYSFS #ifndef NO_BCACHEFS_SYSFS
#include "bcachefs.h" #include "bcachefs.h"
#include "alloc.h" #include "alloc_background.h"
#include "compress.h" #include "compress.h"
#include "sysfs.h" #include "sysfs.h"
#include "btree_cache.h" #include "btree_cache.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment