mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
Update bcachefs sources to 55f0b5944b fixup! bcachefs: Run bch2_check_backpointers_to_extents() in multiple passes if necessary
This commit is contained in:
parent
81aef33957
commit
cfd00fa623
@ -1 +1 @@
|
|||||||
47ffed9fad891300a610191602a10ecd1e857cce
|
55f0b5944bb7f02baa6b7b854fd4d294d974bfb6
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "bcachefs.h"
|
#include "bcachefs.h"
|
||||||
|
#include "bbpos.h"
|
||||||
#include "alloc_background.h"
|
#include "alloc_background.h"
|
||||||
#include "backpointers.h"
|
#include "backpointers.h"
|
||||||
#include "btree_cache.h"
|
#include "btree_cache.h"
|
||||||
@ -804,41 +805,6 @@ err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bbpos {
|
|
||||||
enum btree_id btree;
|
|
||||||
struct bpos pos;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline int bbpos_cmp(struct bbpos l, struct bbpos r)
|
|
||||||
{
|
|
||||||
return cmp_int(l.btree, r.btree) ?: bpos_cmp(l.pos, r.pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct bbpos bbpos_successor(struct bbpos pos)
|
|
||||||
{
|
|
||||||
if (bpos_cmp(pos.pos, SPOS_MAX)) {
|
|
||||||
pos.pos = bpos_successor(pos.pos);
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos.btree != BTREE_ID_NR) {
|
|
||||||
pos.btree++;
|
|
||||||
pos.pos = POS_MIN;
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
BUG();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void bbpos_to_text(struct printbuf *out, struct bbpos pos)
|
|
||||||
{
|
|
||||||
prt_str(out, bch2_btree_ids[pos.btree]);
|
|
||||||
prt_char(out, ':');
|
|
||||||
bch2_bpos_to_text(out, pos.pos);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline struct bbpos bp_to_bbpos(struct bch_backpointer bp)
|
static inline struct bbpos bp_to_bbpos(struct bch_backpointer bp)
|
||||||
{
|
{
|
||||||
return (struct bbpos) {
|
return (struct bbpos) {
|
||||||
@ -847,6 +813,14 @@ static inline struct bbpos bp_to_bbpos(struct bch_backpointer bp)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t btree_nodes_fit_in_ram(struct bch_fs *c)
|
||||||
|
{
|
||||||
|
struct sysinfo i;
|
||||||
|
|
||||||
|
si_meminfo(&i);
|
||||||
|
return (i.totalram >> 1) / btree_bytes(c);
|
||||||
|
}
|
||||||
|
|
||||||
int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
|
int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
|
||||||
unsigned btree_leaf_mask,
|
unsigned btree_leaf_mask,
|
||||||
unsigned btree_interior_mask,
|
unsigned btree_interior_mask,
|
||||||
@ -854,15 +828,10 @@ int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
|
|||||||
{
|
{
|
||||||
struct btree_iter iter;
|
struct btree_iter iter;
|
||||||
struct bkey_s_c k;
|
struct bkey_s_c k;
|
||||||
struct sysinfo i;
|
size_t btree_nodes = btree_nodes_fit_in_ram(trans->c);
|
||||||
size_t btree_nodes;
|
|
||||||
enum btree_id btree;
|
enum btree_id btree;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
si_meminfo(&i);
|
|
||||||
|
|
||||||
btree_nodes = (i.totalram >> 1) / btree_bytes(trans->c);
|
|
||||||
|
|
||||||
for (btree = start.btree; btree < BTREE_ID_NR && !ret; btree++) {
|
for (btree = start.btree; btree < BTREE_ID_NR && !ret; btree++) {
|
||||||
unsigned depth = ((1U << btree) & btree_leaf_mask) ? 1 : 2;
|
unsigned depth = ((1U << btree) & btree_leaf_mask) ? 1 : 2;
|
||||||
|
|
||||||
@ -887,8 +856,7 @@ int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
|
|||||||
|
|
||||||
--btree_nodes;
|
--btree_nodes;
|
||||||
if (!btree_nodes) {
|
if (!btree_nodes) {
|
||||||
end->btree = btree;
|
*end = BBPOS(btree, k.k->p);
|
||||||
end->pos = k.k->p;
|
|
||||||
bch2_trans_iter_exit(trans, &iter);
|
bch2_trans_iter_exit(trans, &iter);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -896,8 +864,7 @@ int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
|
|||||||
bch2_trans_iter_exit(trans, &iter);
|
bch2_trans_iter_exit(trans, &iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
end->btree = BTREE_ID_NR;
|
*end = BBPOS_MAX;
|
||||||
end->pos = POS_MIN;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1020,13 +987,35 @@ int bch2_check_backpointers_to_extents(struct bch_fs *c)
|
|||||||
|
|
||||||
bch2_trans_init(&trans, c, 0, 0);
|
bch2_trans_init(&trans, c, 0, 0);
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = bch2_get_btree_in_memory_pos(&trans,
|
ret = bch2_get_btree_in_memory_pos(&trans,
|
||||||
(1U << BTREE_ID_extents)|
|
(1U << BTREE_ID_extents)|
|
||||||
(1U << BTREE_ID_reflink),
|
(1U << BTREE_ID_reflink),
|
||||||
~0,
|
~0,
|
||||||
start, &end) ?:
|
start, &end);
|
||||||
bch2_check_backpointers_to_extents_pass(&trans, start, end);
|
if (ret)
|
||||||
if (ret || end.btree == BTREE_ID_NR)
|
break;
|
||||||
|
|
||||||
|
if (!bbpos_cmp(start, BBPOS_MIN) &&
|
||||||
|
bbpos_cmp(end, BBPOS_MAX))
|
||||||
|
bch_verbose(c, "check_backpointers_to_extents(): extents do not fit in ram,"
|
||||||
|
"running in multiple passes with %zu nodes per pass",
|
||||||
|
btree_nodes_fit_in_ram(c));
|
||||||
|
|
||||||
|
if (bbpos_cmp(start, BBPOS_MIN) ||
|
||||||
|
bbpos_cmp(end, BBPOS_MAX)) {
|
||||||
|
struct printbuf buf = PRINTBUF;
|
||||||
|
|
||||||
|
prt_str(&buf, "check_backointers_to_extents(): ");
|
||||||
|
bch2_bbpos_to_text(&buf, start);
|
||||||
|
prt_str(&buf, "-");
|
||||||
|
bch2_bbpos_to_text(&buf, end);
|
||||||
|
|
||||||
|
bch_verbose(c, "%s", buf.buf);
|
||||||
|
printbuf_exit(&buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = bch2_check_backpointers_to_extents_pass(&trans, start, end);
|
||||||
|
if (ret || !bbpos_cmp(end, BBPOS_MAX))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
start = bbpos_successor(end);
|
start = bbpos_successor(end);
|
||||||
|
46
libbcachefs/bbpos.h
Normal file
46
libbcachefs/bbpos.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0 */
|
||||||
|
#ifndef _BCACHEFS_BBPOS_H
|
||||||
|
#define _BCACHEFS_BBPOS_H
|
||||||
|
|
||||||
|
struct bbpos {
|
||||||
|
enum btree_id btree;
|
||||||
|
struct bpos pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline struct bbpos BBPOS(enum btree_id btree, struct bpos pos)
|
||||||
|
{
|
||||||
|
return (struct bbpos) { btree, pos };
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BBPOS_MIN BBPOS(0, POS_MIN)
|
||||||
|
#define BBPOS_MAX BBPOS(BTREE_ID_NR - 1, POS_MAX)
|
||||||
|
|
||||||
|
static inline int bbpos_cmp(struct bbpos l, struct bbpos r)
|
||||||
|
{
|
||||||
|
return cmp_int(l.btree, r.btree) ?: bpos_cmp(l.pos, r.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct bbpos bbpos_successor(struct bbpos pos)
|
||||||
|
{
|
||||||
|
if (bpos_cmp(pos.pos, SPOS_MAX)) {
|
||||||
|
pos.pos = bpos_successor(pos.pos);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos.btree != BTREE_ID_NR) {
|
||||||
|
pos.btree++;
|
||||||
|
pos.pos = POS_MIN;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
BUG();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bch2_bbpos_to_text(struct printbuf *out, struct bbpos pos)
|
||||||
|
{
|
||||||
|
prt_str(out, bch2_btree_ids[pos.btree]);
|
||||||
|
prt_char(out, ':');
|
||||||
|
bch2_bpos_to_text(out, pos.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _BCACHEFS_BBPOS_H */
|
Loading…
Reference in New Issue
Block a user