Skip to content

Commit cecf727

Browse files
author
Kent Overstreet
committed
bcachefs: Make allocator stuck timeout configurable, ratelimit messages
Limit these messages to once every 2 minutes to avoid spamming logs; with multiple devices the output can be quite significant. Also, up the default timeout to 30 seconds from 10 seconds. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 6d496e0 commit cecf727

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

fs/bcachefs/alloc_foreground.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,11 +1758,12 @@ void bch2_dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
17581758
prt_printf(out, "buckets to invalidate\t%llu\r\n", should_invalidate_buckets(ca, stats));
17591759
}
17601760

1761-
void bch2_print_allocator_stuck(struct bch_fs *c)
1761+
static noinline void bch2_print_allocator_stuck(struct bch_fs *c)
17621762
{
17631763
struct printbuf buf = PRINTBUF;
17641764

1765-
prt_printf(&buf, "Allocator stuck? Waited for 10 seconds\n");
1765+
prt_printf(&buf, "Allocator stuck? Waited for %u seconds\n",
1766+
c->opts.allocator_stuck_timeout);
17661767

17671768
prt_printf(&buf, "Allocator debug:\n");
17681769
printbuf_indent_add(&buf, 2);
@@ -1792,3 +1793,24 @@ void bch2_print_allocator_stuck(struct bch_fs *c)
17921793
bch2_print_string_as_lines(KERN_ERR, buf.buf);
17931794
printbuf_exit(&buf);
17941795
}
1796+
1797+
static inline unsigned allocator_wait_timeout(struct bch_fs *c)
1798+
{
1799+
if (c->allocator_last_stuck &&
1800+
time_after(c->allocator_last_stuck + HZ * 60 * 2, jiffies))
1801+
return 0;
1802+
1803+
return c->opts.allocator_stuck_timeout * HZ;
1804+
}
1805+
1806+
void __bch2_wait_on_allocator(struct bch_fs *c, struct closure *cl)
1807+
{
1808+
unsigned t = allocator_wait_timeout(c);
1809+
1810+
if (t && closure_sync_timeout(cl, t)) {
1811+
c->allocator_last_stuck = jiffies;
1812+
bch2_print_allocator_stuck(c);
1813+
}
1814+
1815+
closure_sync(cl);
1816+
}

fs/bcachefs/alloc_foreground.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ void bch2_write_points_to_text(struct printbuf *, struct bch_fs *);
231231
void bch2_fs_alloc_debug_to_text(struct printbuf *, struct bch_fs *);
232232
void bch2_dev_alloc_debug_to_text(struct printbuf *, struct bch_dev *);
233233

234-
void bch2_print_allocator_stuck(struct bch_fs *);
234+
void __bch2_wait_on_allocator(struct bch_fs *, struct closure *);
235+
static inline void bch2_wait_on_allocator(struct bch_fs *c, struct closure *cl)
236+
{
237+
if (cl->closure_get_happened)
238+
__bch2_wait_on_allocator(c, cl);
239+
}
235240

236241
#endif /* _BCACHEFS_ALLOC_FOREGROUND_H */

fs/bcachefs/bcachefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ struct bch_fs {
893893
struct bch_fs_usage_base __percpu *usage;
894894
u64 __percpu *online_reserved;
895895

896+
unsigned long allocator_last_stuck;
897+
896898
struct io_clock io_clock[2];
897899

898900
/* JOURNAL SEQ BLACKLIST */

fs/bcachefs/bcachefs_format.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,8 @@ LE64_BITMASK(BCH_SB_BACKGROUND_COMPRESSION_TYPE_HI,
836836

837837
LE64_BITMASK(BCH_SB_VERSION_UPGRADE_COMPLETE,
838838
struct bch_sb, flags[5], 0, 16);
839+
LE64_BITMASK(BCH_SB_ALLOCATOR_STUCK_TIMEOUT,
840+
struct bch_sb, flags[5], 16, 32);
839841

840842
static inline __u64 BCH_SB_COMPRESSION_TYPE(const struct bch_sb *sb)
841843
{

fs/bcachefs/io_misc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ int bch2_extent_fallocate(struct btree_trans *trans,
126126

127127
if (closure_nr_remaining(&cl) != 1) {
128128
bch2_trans_unlock_long(trans);
129-
130-
if (closure_sync_timeout(&cl, HZ * 10)) {
131-
bch2_print_allocator_stuck(c);
132-
closure_sync(&cl);
133-
}
129+
bch2_wait_on_allocator(c, &cl);
134130
}
135131

136132
return ret;

fs/bcachefs/io_write.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,10 +1503,7 @@ static void __bch2_write(struct bch_write_op *op)
15031503
if ((op->flags & BCH_WRITE_SYNC) ||
15041504
(!(op->flags & BCH_WRITE_SUBMITTED) &&
15051505
!(op->flags & BCH_WRITE_IN_WORKER))) {
1506-
if (closure_sync_timeout(&op->cl, HZ * 10)) {
1507-
bch2_print_allocator_stuck(c);
1508-
closure_sync(&op->cl);
1509-
}
1506+
bch2_wait_on_allocator(c, &op->cl);
15101507

15111508
__bch2_write_index(op);
15121509

fs/bcachefs/opts.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ enum fsck_err_opts {
391391
OPT_BOOL(), \
392392
BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
393393
NULL, "Log transaction function names in journal") \
394+
x(allocator_stuck_timeout, u16, \
395+
OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
396+
OPT_UINT(0, U16_MAX), \
397+
BCH_SB_ALLOCATOR_STUCK_TIMEOUT, 30, \
398+
NULL, "Default timeout in seconds for stuck allocator messages")\
394399
x(noexcl, u8, \
395400
OPT_FS|OPT_MOUNT, \
396401
OPT_BOOL(), \

fs/bcachefs/super-io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb,
414414

415415
if (!BCH_SB_VERSION_UPGRADE_COMPLETE(sb))
416416
SET_BCH_SB_VERSION_UPGRADE_COMPLETE(sb, le16_to_cpu(sb->version));
417+
418+
if (le16_to_cpu(sb->version) <= bcachefs_metadata_version_disk_accounting_v2 &&
419+
!BCH_SB_ALLOCATOR_STUCK_TIMEOUT(sb))
420+
SET_BCH_SB_ALLOCATOR_STUCK_TIMEOUT(sb, 30);
417421
}
418422

419423
for (opt_id = 0; opt_id < bch2_opts_nr; opt_id++) {

0 commit comments

Comments
 (0)