summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/alloc_background.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-03-05 18:00:55 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:53 -0400
commit59a7405161425df39d33faabf9f97c101fcb75d9 (patch)
treeec21bf092375e2c5d62f40b010da510c95ca64d8 /fs/bcachefs/alloc_background.c
parent18a7b97239b6f0bae3fa1475cb276a273e07597a (diff)
downloadlinux-59a7405161425df39d33faabf9f97c101fcb75d9.tar.gz
linux-59a7405161425df39d33faabf9f97c101fcb75d9.tar.bz2
linux-59a7405161425df39d33faabf9f97c101fcb75d9.zip
bcachefs: Create allocator threads when allocating filesystem
We're seeing failures to mount because of a failure to start the allocator threads, which currently happens fairly late in the mount process, after walking all metadata, and kthread_create() fails if something has tried to kill the mount process, which is probably not what we want. This patch avoids this issue by creating, but not starting, the allocator threads when we preallocate all of our other in memory data structures. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/alloc_background.c')
-rw-r--r--fs/bcachefs/alloc_background.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c
index eac82c9880ba..b9b97cbda177 100644
--- a/fs/bcachefs/alloc_background.c
+++ b/fs/bcachefs/alloc_background.c
@@ -1068,6 +1068,12 @@ static int discard_invalidated_buckets(struct bch_fs *c, struct bch_dev *ca)
return 0;
}
+static inline bool allocator_thread_running(struct bch_dev *ca)
+{
+ return ca->mi.state == BCH_MEMBER_STATE_RW &&
+ test_bit(BCH_FS_ALLOCATOR_RUNNING, &ca->fs->flags);
+}
+
/**
* bch_allocator_thread - move buckets from free_inc to reserves
*
@@ -1084,9 +1090,16 @@ static int bch2_allocator_thread(void *arg)
int ret;
set_freezable();
- ca->allocator_state = ALLOCATOR_RUNNING;
while (1) {
+ if (!allocator_thread_running(ca)) {
+ ca->allocator_state = ALLOCATOR_STOPPED;
+ if (kthread_wait_freezable(allocator_thread_running(ca)))
+ break;
+ }
+
+ ca->allocator_state = ALLOCATOR_RUNNING;
+
cond_resched();
if (kthread_should_stop())
break;