Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
6e92d155
Commit
6e92d155
authored
Dec 04, 2023
by
Kent Overstreet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcachefs: Refactor trans->paths_allocated to be standard bitmap
Signed-off-by:
Kent Overstreet
<
kent.overstreet@linux.dev
>
parent
0d963a63
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
32 deletions
+18
-32
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_iter.c
+11
-12
fs/bcachefs/btree_iter.h
fs/bcachefs/btree_iter.h
+5
-18
fs/bcachefs/btree_locking.h
fs/bcachefs/btree_locking.h
+1
-1
fs/bcachefs/btree_types.h
fs/bcachefs/btree_types.h
+1
-1
No files found.
fs/bcachefs/btree_iter.c
View file @
6e92d155
...
@@ -1298,7 +1298,7 @@ static inline void __bch2_path_free(struct btree_trans *trans, struct btree_path
...
@@ -1298,7 +1298,7 @@ static inline void __bch2_path_free(struct btree_trans *trans, struct btree_path
{
{
__bch2_btree_path_unlock
(
trans
,
path
);
__bch2_btree_path_unlock
(
trans
,
path
);
btree_path_list_remove
(
trans
,
path
);
btree_path_list_remove
(
trans
,
path
);
trans
->
paths_allocated
&=
~
(
1ULL
<<
path
->
idx
);
__clear_bit
(
path
->
idx
,
trans
->
paths_allocated
);
}
}
void
bch2_path_put
(
struct
btree_trans
*
trans
,
struct
btree_path
*
path
,
bool
intent
)
void
bch2_path_put
(
struct
btree_trans
*
trans
,
struct
btree_path
*
path
,
bool
intent
)
...
@@ -1471,6 +1471,7 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
...
@@ -1471,6 +1471,7 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
{
{
struct
btree_transaction_stats
*
s
=
btree_trans_stats
(
trans
);
struct
btree_transaction_stats
*
s
=
btree_trans_stats
(
trans
);
struct
printbuf
buf
=
PRINTBUF
;
struct
printbuf
buf
=
PRINTBUF
;
size_t
nr
=
bitmap_weight
(
trans
->
paths_allocated
,
BTREE_ITER_MAX
);
if
(
!
s
)
if
(
!
s
)
return
;
return
;
...
@@ -1479,9 +1480,8 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
...
@@ -1479,9 +1480,8 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
if
(
!
buf
.
allocation_failure
)
{
if
(
!
buf
.
allocation_failure
)
{
mutex_lock
(
&
s
->
lock
);
mutex_lock
(
&
s
->
lock
);
if
(
s
->
nr_max_paths
<
hweight64
(
trans
->
paths_allocated
))
{
if
(
nr
>
s
->
nr_max_paths
)
{
s
->
nr_max_paths
=
trans
->
nr_max_paths
=
s
->
nr_max_paths
=
nr
;
hweight64
(
trans
->
paths_allocated
);
swap
(
s
->
max_paths_text
,
buf
.
buf
);
swap
(
s
->
max_paths_text
,
buf
.
buf
);
}
}
mutex_unlock
(
&
s
->
lock
);
mutex_unlock
(
&
s
->
lock
);
...
@@ -1489,7 +1489,7 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
...
@@ -1489,7 +1489,7 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
printbuf_exit
(
&
buf
);
printbuf_exit
(
&
buf
);
trans
->
nr_max_paths
=
hweight64
(
trans
->
paths_allocated
)
;
trans
->
nr_max_paths
=
nr
;
}
}
noinline
__cold
noinline
__cold
...
@@ -1518,13 +1518,12 @@ static inline struct btree_path *btree_path_alloc(struct btree_trans *trans,
...
@@ -1518,13 +1518,12 @@ static inline struct btree_path *btree_path_alloc(struct btree_trans *trans,
struct
btree_path
*
pos
)
struct
btree_path
*
pos
)
{
{
struct
btree_path
*
path
;
struct
btree_path
*
path
;
unsigned
idx
;
size_t
idx
=
find_first_zero_bit
(
trans
->
paths_allocated
,
BTREE_ITER_MAX
)
;
if
(
unlikely
(
trans
->
paths_allocated
==
if
(
unlikely
(
idx
==
BTREE_ITER_MAX
))
~
((
~
0ULL
<<
1
)
<<
(
BTREE_ITER_MAX
-
1
))))
btree_path_overflow
(
trans
);
btree_path_overflow
(
trans
);
idx
=
__ffs64
(
~
trans
->
paths_allocated
);
BUG_ON
(
idx
>
BTREE_ITER_MAX
);
/*
/*
* Do this before marking the new path as allocated, since it won't be
* Do this before marking the new path as allocated, since it won't be
...
@@ -1533,7 +1532,7 @@ static inline struct btree_path *btree_path_alloc(struct btree_trans *trans,
...
@@ -1533,7 +1532,7 @@ static inline struct btree_path *btree_path_alloc(struct btree_trans *trans,
if
(
unlikely
(
idx
>
trans
->
nr_max_paths
))
if
(
unlikely
(
idx
>
trans
->
nr_max_paths
))
bch2_trans_update_max_paths
(
trans
);
bch2_trans_update_max_paths
(
trans
);
trans
->
paths_allocated
|=
1ULL
<<
idx
;
__set_bit
(
idx
,
trans
->
paths_allocated
)
;
path
=
&
trans
->
paths
[
idx
];
path
=
&
trans
->
paths
[
idx
];
path
->
idx
=
idx
;
path
->
idx
=
idx
;
...
@@ -2516,7 +2515,7 @@ static void btree_trans_verify_sorted_refs(struct btree_trans *trans)
...
@@ -2516,7 +2515,7 @@ static void btree_trans_verify_sorted_refs(struct btree_trans *trans)
struct
btree_path
*
path
;
struct
btree_path
*
path
;
unsigned
i
;
unsigned
i
;
BUG_ON
(
trans
->
nr_sorted
!=
hweight64
(
trans
->
paths_allocated
));
BUG_ON
(
trans
->
nr_sorted
!=
bitmap_weight
(
trans
->
paths_allocated
,
BTREE_ITER_MAX
));
trans_for_each_path
(
trans
,
path
)
{
trans_for_each_path
(
trans
,
path
)
{
BUG_ON
(
path
->
sorted_idx
>=
trans
->
nr_sorted
);
BUG_ON
(
path
->
sorted_idx
>=
trans
->
nr_sorted
);
...
@@ -2526,7 +2525,7 @@ static void btree_trans_verify_sorted_refs(struct btree_trans *trans)
...
@@ -2526,7 +2525,7 @@ static void btree_trans_verify_sorted_refs(struct btree_trans *trans)
for
(
i
=
0
;
i
<
trans
->
nr_sorted
;
i
++
)
{
for
(
i
=
0
;
i
<
trans
->
nr_sorted
;
i
++
)
{
unsigned
idx
=
trans
->
sorted
[
i
];
unsigned
idx
=
trans
->
sorted
[
i
];
EBUG_ON
(
!
(
trans
->
paths_allocated
&
(
1ULL
<<
idx
)
));
BUG_ON
(
!
test_bit
(
idx
,
trans
->
paths_allocated
));
BUG_ON
(
trans
->
paths
[
idx
].
sorted_idx
!=
i
);
BUG_ON
(
trans
->
paths
[
idx
].
sorted_idx
!=
i
);
}
}
}
}
...
...
fs/bcachefs/btree_iter.h
View file @
6e92d155
...
@@ -66,17 +66,10 @@ static inline void btree_trans_sort_paths(struct btree_trans *trans)
...
@@ -66,17 +66,10 @@ static inline void btree_trans_sort_paths(struct btree_trans *trans)
static
inline
struct
btree_path
*
static
inline
struct
btree_path
*
__trans_next_path
(
struct
btree_trans
*
trans
,
unsigned
idx
)
__trans_next_path
(
struct
btree_trans
*
trans
,
unsigned
idx
)
{
{
u64
l
;
idx
=
find_next_bit
(
trans
->
paths_allocated
,
BTREE_ITER_MAX
,
idx
);
if
(
idx
==
BTREE_ITER_MAX
)
if
(
idx
==
BTREE_ITER_MAX
)
return
NULL
;
return
NULL
;
EBUG_ON
(
idx
>
BTREE_ITER_MAX
);
l
=
trans
->
paths_allocated
>>
idx
;
if
(
!
l
)
return
NULL
;
idx
+=
__ffs64
(
l
);
EBUG_ON
(
idx
>=
BTREE_ITER_MAX
);
EBUG_ON
(
trans
->
paths
[
idx
].
idx
!=
idx
);
EBUG_ON
(
trans
->
paths
[
idx
].
idx
!=
idx
);
return
&
trans
->
paths
[
idx
];
return
&
trans
->
paths
[
idx
];
}
}
...
@@ -92,17 +85,11 @@ __trans_next_path(struct btree_trans *trans, unsigned idx)
...
@@ -92,17 +85,11 @@ __trans_next_path(struct btree_trans *trans, unsigned idx)
static
inline
struct
btree_path
*
static
inline
struct
btree_path
*
__trans_next_path_safe
(
struct
btree_trans
*
trans
,
unsigned
*
idx
)
__trans_next_path_safe
(
struct
btree_trans
*
trans
,
unsigned
*
idx
)
{
{
u64
l
;
*
idx
=
find_next_bit
(
trans
->
paths_allocated
,
BTREE_ITER_MAX
,
*
idx
);
if
(
*
idx
==
BTREE_ITER_MAX
)
if
(
*
idx
==
BTREE_ITER_MAX
)
return
NULL
;
return
NULL
;
l
=
trans
->
paths_allocated
>>
*
idx
;
EBUG_ON
(
*
idx
>
BTREE_ITER_MAX
);
if
(
!
l
)
return
NULL
;
*
idx
+=
__ffs64
(
l
);
EBUG_ON
(
*
idx
>=
BTREE_ITER_MAX
);
return
&
trans
->
paths
[
*
idx
];
return
&
trans
->
paths
[
*
idx
];
}
}
...
@@ -631,7 +618,7 @@ int __bch2_btree_trans_too_many_iters(struct btree_trans *);
...
@@ -631,7 +618,7 @@ int __bch2_btree_trans_too_many_iters(struct btree_trans *);
static
inline
int
btree_trans_too_many_iters
(
struct
btree_trans
*
trans
)
static
inline
int
btree_trans_too_many_iters
(
struct
btree_trans
*
trans
)
{
{
if
(
hweight64
(
trans
->
paths_allocated
)
>
BTREE_ITER_MAX
-
8
)
if
(
bitmap_weight
(
trans
->
paths_allocated
,
BTREE_ITER_MAX
)
>
BTREE_ITER_MAX
-
8
)
return
__bch2_btree_trans_too_many_iters
(
trans
);
return
__bch2_btree_trans_too_many_iters
(
trans
);
return
0
;
return
0
;
...
...
fs/bcachefs/btree_locking.h
View file @
6e92d155
...
@@ -263,7 +263,7 @@ static inline int btree_node_lock(struct btree_trans *trans,
...
@@ -263,7 +263,7 @@ static inline int btree_node_lock(struct btree_trans *trans,
int
ret
=
0
;
int
ret
=
0
;
EBUG_ON
(
level
>=
BTREE_MAX_DEPTH
);
EBUG_ON
(
level
>=
BTREE_MAX_DEPTH
);
EBUG_ON
(
!
(
trans
->
paths_allocated
&
(
1ULL
<<
path
->
idx
)
));
EBUG_ON
(
!
test_bit
(
path
->
idx
,
trans
->
paths_allocated
));
if
(
likely
(
six_trylock_type
(
&
b
->
lock
,
type
))
||
if
(
likely
(
six_trylock_type
(
&
b
->
lock
,
type
))
||
btree_node_lock_increment
(
trans
,
b
,
level
,
(
enum
btree_node_locked_type
)
type
)
||
btree_node_lock_increment
(
trans
,
b
,
level
,
(
enum
btree_node_locked_type
)
type
)
||
...
...
fs/bcachefs/btree_types.h
View file @
6e92d155
...
@@ -414,7 +414,7 @@ struct btree_trans {
...
@@ -414,7 +414,7 @@ struct btree_trans {
unsigned
extra_journal_res
;
unsigned
extra_journal_res
;
unsigned
nr_max_paths
;
unsigned
nr_max_paths
;
u
64
paths_allocated
;
u
nsigned
long
paths_allocated
[
BITS_TO_LONGS
(
BTREE_ITER_MAX
)]
;
unsigned
mem_top
;
unsigned
mem_top
;
unsigned
mem_max
;
unsigned
mem_max
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment