Skip to content

Commit 088d0de

Browse files
author
Kent Overstreet
committed
bcachefs: btree_gc can now handle unknown btrees
Compatibility fix - we no longer have a separate table for which order gc walks btrees in, and special case the stripes btree directly. Signed-off-by: Kent Overstreet <[email protected]>
1 parent b413107 commit 088d0de

File tree

5 files changed

+55
-73
lines changed

5 files changed

+55
-73
lines changed

fs/bcachefs/bcachefs.h

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ enum bch_time_stats {
457457
};
458458

459459
#include "alloc_types.h"
460+
#include "btree_gc_types.h"
460461
#include "btree_types.h"
461462
#include "btree_node_scan_types.h"
462463
#include "btree_write_buffer_types.h"
@@ -488,49 +489,6 @@ enum bch_time_stats {
488489

489490
struct btree;
490491

491-
enum gc_phase {
492-
GC_PHASE_NOT_RUNNING,
493-
GC_PHASE_START,
494-
GC_PHASE_SB,
495-
496-
GC_PHASE_BTREE_stripes,
497-
GC_PHASE_BTREE_extents,
498-
GC_PHASE_BTREE_inodes,
499-
GC_PHASE_BTREE_dirents,
500-
GC_PHASE_BTREE_xattrs,
501-
GC_PHASE_BTREE_alloc,
502-
GC_PHASE_BTREE_quotas,
503-
GC_PHASE_BTREE_reflink,
504-
GC_PHASE_BTREE_subvolumes,
505-
GC_PHASE_BTREE_snapshots,
506-
GC_PHASE_BTREE_lru,
507-
GC_PHASE_BTREE_freespace,
508-
GC_PHASE_BTREE_need_discard,
509-
GC_PHASE_BTREE_backpointers,
510-
GC_PHASE_BTREE_bucket_gens,
511-
GC_PHASE_BTREE_snapshot_trees,
512-
GC_PHASE_BTREE_deleted_inodes,
513-
GC_PHASE_BTREE_logged_ops,
514-
GC_PHASE_BTREE_rebalance_work,
515-
GC_PHASE_BTREE_subvolume_children,
516-
517-
GC_PHASE_PENDING_DELETE,
518-
};
519-
520-
struct gc_pos {
521-
enum gc_phase phase;
522-
u16 level;
523-
struct bpos pos;
524-
};
525-
526-
struct reflink_gc {
527-
u64 offset;
528-
u32 size;
529-
u32 refcount;
530-
};
531-
532-
typedef GENRADIX(struct reflink_gc) reflink_gc_table;
533-
534492
struct io_count {
535493
u64 sectors[2][BCH_DATA_NR];
536494
};

fs/bcachefs/btree_gc.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,7 @@ static int bch2_gc_btree(struct btree_trans *trans, enum btree_id btree, bool in
673673

674674
static inline int btree_id_gc_phase_cmp(enum btree_id l, enum btree_id r)
675675
{
676-
return (int) btree_id_to_gc_phase(l) -
677-
(int) btree_id_to_gc_phase(r);
676+
return cmp_int(gc_btree_order(l), gc_btree_order(r));
678677
}
679678

680679
static int bch2_gc_btrees(struct bch_fs *c)
@@ -711,7 +710,7 @@ static int bch2_gc_btrees(struct bch_fs *c)
711710
static int bch2_mark_superblocks(struct bch_fs *c)
712711
{
713712
mutex_lock(&c->sb_lock);
714-
gc_pos_set(c, gc_phase(GC_PHASE_SB));
713+
gc_pos_set(c, gc_phase(GC_PHASE_sb));
715714

716715
int ret = bch2_trans_mark_dev_sbs_flags(c, BTREE_TRIGGER_gc);
717716
mutex_unlock(&c->sb_lock);
@@ -1209,7 +1208,7 @@ int bch2_check_allocations(struct bch_fs *c)
12091208
if (ret)
12101209
goto out;
12111210

1212-
gc_pos_set(c, gc_phase(GC_PHASE_START));
1211+
gc_pos_set(c, gc_phase(GC_PHASE_start));
12131212

12141213
ret = bch2_mark_superblocks(c);
12151214
BUG_ON(ret);
@@ -1231,7 +1230,7 @@ int bch2_check_allocations(struct bch_fs *c)
12311230

12321231
percpu_down_write(&c->mark_lock);
12331232
/* Indicates that gc is no longer in progress: */
1234-
__gc_pos_set(c, gc_phase(GC_PHASE_NOT_RUNNING));
1233+
__gc_pos_set(c, gc_phase(GC_PHASE_not_running));
12351234

12361235
bch2_gc_free(c);
12371236
percpu_up_write(&c->mark_lock);

fs/bcachefs/btree_gc.h

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _BCACHEFS_BTREE_GC_H
44

55
#include "bkey.h"
6+
#include "btree_gc_types.h"
67
#include "btree_types.h"
78

89
int bch2_check_topology(struct bch_fs *);
@@ -32,36 +33,15 @@ int bch2_check_allocations(struct bch_fs *);
3233
/* Position of (the start of) a gc phase: */
3334
static inline struct gc_pos gc_phase(enum gc_phase phase)
3435
{
35-
return (struct gc_pos) {
36-
.phase = phase,
37-
.level = 0,
38-
.pos = POS_MIN,
39-
};
40-
}
41-
42-
static inline int gc_pos_cmp(struct gc_pos l, struct gc_pos r)
43-
{
44-
return cmp_int(l.phase, r.phase) ?:
45-
-cmp_int(l.level, r.level) ?:
46-
bpos_cmp(l.pos, r.pos);
47-
}
48-
49-
static inline enum gc_phase btree_id_to_gc_phase(enum btree_id id)
50-
{
51-
switch (id) {
52-
#define x(name, v, ...) case BTREE_ID_##name: return GC_PHASE_BTREE_##name;
53-
BCH_BTREE_IDS()
54-
#undef x
55-
default:
56-
BUG();
57-
}
36+
return (struct gc_pos) { .phase = phase, };
5837
}
5938

6039
static inline struct gc_pos gc_pos_btree(enum btree_id btree, unsigned level,
6140
struct bpos pos)
6241
{
6342
return (struct gc_pos) {
64-
.phase = btree_id_to_gc_phase(btree),
43+
.phase = GC_PHASE_btree,
44+
.btree = btree,
6545
.level = level,
6646
.pos = pos,
6747
};
@@ -76,6 +56,22 @@ static inline struct gc_pos gc_pos_btree_node(struct btree *b)
7656
return gc_pos_btree(b->c.btree_id, b->c.level, b->key.k.p);
7757
}
7858

59+
static inline int gc_btree_order(enum btree_id btree)
60+
{
61+
if (btree == BTREE_ID_stripes)
62+
return -1;
63+
return btree;
64+
}
65+
66+
static inline int gc_pos_cmp(struct gc_pos l, struct gc_pos r)
67+
{
68+
return cmp_int(l.phase, r.phase) ?:
69+
cmp_int(gc_btree_order(l.btree),
70+
gc_btree_order(r.btree)) ?:
71+
-cmp_int(l.level, r.level) ?:
72+
bpos_cmp(l.pos, r.pos);
73+
}
74+
7975
static inline bool gc_visited(struct bch_fs *c, struct gc_pos pos)
8076
{
8177
unsigned seq;

fs/bcachefs/btree_gc_types.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _BCACHEFS_BTREE_GC_TYPES_H
3+
#define _BCACHEFS_BTREE_GC_TYPES_H
4+
5+
#include <linux/generic-radix-tree.h>
6+
7+
enum gc_phase {
8+
GC_PHASE_not_running,
9+
GC_PHASE_start,
10+
GC_PHASE_sb,
11+
GC_PHASE_btree,
12+
};
13+
14+
struct gc_pos {
15+
enum gc_phase phase:8;
16+
enum btree_id btree:8;
17+
u16 level;
18+
struct bpos pos;
19+
};
20+
21+
struct reflink_gc {
22+
u64 offset;
23+
u32 size;
24+
u32 refcount;
25+
};
26+
27+
typedef GENRADIX(struct reflink_gc) reflink_gc_table;
28+
29+
#endif /* _BCACHEFS_BTREE_GC_TYPES_H */

fs/bcachefs/ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ static int __ec_stripe_mem_alloc(struct bch_fs *c, size_t idx, gfp_t gfp)
908908
if (!genradix_ptr_alloc(&c->stripes, idx, gfp))
909909
return -BCH_ERR_ENOMEM_ec_stripe_mem_alloc;
910910

911-
if (c->gc_pos.phase != GC_PHASE_NOT_RUNNING &&
911+
if (c->gc_pos.phase != GC_PHASE_not_running &&
912912
!genradix_ptr_alloc(&c->gc_stripes, idx, gfp))
913913
return -BCH_ERR_ENOMEM_ec_stripe_mem_alloc;
914914

0 commit comments

Comments
 (0)