Skip to content

Commit 43a7548

Browse files
committed
Merge tag 'for-6.9-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs updates from David Sterba: "Mostly stabilization, refactoring and cleanup changes. There rest are minor performance optimizations due to caching or lock contention reduction and a few notable fixes. Performance improvements: - minor speedup in logging when repeatedly allocated structure is preallocated only once, improves latency and decreases lock contention - minor throughput increase (+6%), reduced lock contention after clearing delayed allocation bits, applies to several common workload types - skip full quota rescan if a new relation is added in the same transaction Fixes: - zstd fix for inline compressed file in subpage mode, updated version from the 6.8 time - proper qgroup inheritance ioctl parameter validation - more fiemap followup fixes after reduced locking done in 6.8: - fix race when detecting delalloc ranges Core changes: - more debugging code: - added assertions for a very rare crash in raid56 calculation - tree-checker dumps page state to give more insights into possible reference counting issues - add checksum calculation offloading sysfs knob, for now enabled under DEBUG only to determine a good heuristic for deciding the offload or synchronous, depends on various factors (block group profile, device speed) and is not as clear as initially thought (checksum type) - error handling improvements, added assertions - more page to folio conversion (defrag, truncate), cached size and shift - preparation for more fine grained locking of sectors in subpage mode - cleanups and refactoring: - include cleanups, forward declarations - pointer-to-structure helpers - redundant argument removals - removed unused code - slab cache updates, last use of SLAB_MEM_SPREAD removed" * tag 'for-6.9-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (114 commits) btrfs: reuse cloned extent buffer during fiemap to avoid re-allocations btrfs: fix race when detecting delalloc ranges during fiemap btrfs: fix off-by-one chunk length calculation at contains_pending_extent() btrfs: qgroup: allow quick inherit if snapshot is created and added to the same parent btrfs: qgroup: validate btrfs_qgroup_inherit parameter btrfs: include device major and minor numbers in the device scan notice btrfs: mark btrfs_put_caching_control() static btrfs: remove SLAB_MEM_SPREAD flag use btrfs: qgroup: always free reserved space for extent records btrfs: tree-checker: dump the page status if hit something wrong btrfs: compression: remove dead comments in btrfs_compress_heuristic() btrfs: subpage: make writer lock utilize bitmap btrfs: subpage: make reader lock utilize bitmap btrfs: unexport btrfs_subpage_start_writer() and btrfs_subpage_end_and_test_writer() btrfs: pass a valid extent map cache pointer to __get_extent_map() btrfs: merge btrfs_del_delalloc_inode() helpers btrfs: pass btrfs_device to btrfs_scratch_superblocks() btrfs: handle transaction commit errors in flush_reservations() btrfs: use KMEM_CACHE() to create btrfs_free_space cache btrfs: use KMEM_CACHE() to create delayed ref caches ...
2 parents 35d4aee + 1cab137 commit 43a7548

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+2132
-1117
lines changed

fs/btrfs/accessors.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
#include <asm/unaligned.h>
77
#include "messages.h"
8-
#include "ctree.h"
8+
#include "extent_io.h"
9+
#include "fs.h"
910
#include "accessors.h"
1011

1112
static bool check_setget_bounds(const struct extent_buffer *eb,
@@ -63,8 +64,8 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
6364
const unsigned long idx = get_eb_folio_index(token->eb, member_offset); \
6465
const unsigned long oil = get_eb_offset_in_folio(token->eb, \
6566
member_offset);\
66-
const int unit_size = folio_size(token->eb->folios[0]); \
67-
const int unit_shift = folio_shift(token->eb->folios[0]); \
67+
const int unit_size = token->eb->folio_size; \
68+
const int unit_shift = token->eb->folio_shift; \
6869
const int size = sizeof(u##bits); \
6970
u8 lebytes[sizeof(u##bits)]; \
7071
const int part = unit_size - oil; \
@@ -94,7 +95,7 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
9495
const unsigned long idx = get_eb_folio_index(eb, member_offset);\
9596
const unsigned long oil = get_eb_offset_in_folio(eb, \
9697
member_offset);\
97-
const int unit_size = folio_size(eb->folios[0]); \
98+
const int unit_size = eb->folio_size; \
9899
char *kaddr = folio_address(eb->folios[idx]); \
99100
const int size = sizeof(u##bits); \
100101
const int part = unit_size - oil; \
@@ -117,8 +118,8 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \
117118
const unsigned long idx = get_eb_folio_index(token->eb, member_offset); \
118119
const unsigned long oil = get_eb_offset_in_folio(token->eb, \
119120
member_offset);\
120-
const int unit_size = folio_size(token->eb->folios[0]); \
121-
const int unit_shift = folio_shift(token->eb->folios[0]); \
121+
const int unit_size = token->eb->folio_size; \
122+
const int unit_shift = token->eb->folio_shift; \
122123
const int size = sizeof(u##bits); \
123124
u8 lebytes[sizeof(u##bits)]; \
124125
const int part = unit_size - oil; \
@@ -151,7 +152,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
151152
const unsigned long idx = get_eb_folio_index(eb, member_offset);\
152153
const unsigned long oil = get_eb_offset_in_folio(eb, \
153154
member_offset);\
154-
const int unit_size = folio_size(eb->folios[0]); \
155+
const int unit_size = eb->folio_size; \
155156
char *kaddr = folio_address(eb->folios[idx]); \
156157
const int size = sizeof(u##bits); \
157158
const int part = unit_size - oil; \

fs/btrfs/accessors.h

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
#ifndef BTRFS_ACCESSORS_H
44
#define BTRFS_ACCESSORS_H
55

6-
#include <linux/stddef.h>
76
#include <asm/unaligned.h>
7+
#include <linux/stddef.h>
8+
#include <linux/types.h>
9+
#include <linux/align.h>
10+
#include <linux/build_bug.h>
11+
#include <linux/compiler.h>
12+
#include <linux/string.h>
13+
#include <linux/mm.h>
14+
#include <uapi/linux/btrfs_tree.h>
15+
16+
struct extent_buffer;
817

918
struct btrfs_map_token {
1019
struct extent_buffer *eb;
@@ -844,45 +853,6 @@ static inline void btrfs_set_balance_sys(struct extent_buffer *eb,
844853
write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
845854
}
846855

847-
static inline void btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu,
848-
const struct btrfs_disk_balance_args *disk)
849-
{
850-
memset(cpu, 0, sizeof(*cpu));
851-
852-
cpu->profiles = le64_to_cpu(disk->profiles);
853-
cpu->usage = le64_to_cpu(disk->usage);
854-
cpu->devid = le64_to_cpu(disk->devid);
855-
cpu->pstart = le64_to_cpu(disk->pstart);
856-
cpu->pend = le64_to_cpu(disk->pend);
857-
cpu->vstart = le64_to_cpu(disk->vstart);
858-
cpu->vend = le64_to_cpu(disk->vend);
859-
cpu->target = le64_to_cpu(disk->target);
860-
cpu->flags = le64_to_cpu(disk->flags);
861-
cpu->limit = le64_to_cpu(disk->limit);
862-
cpu->stripes_min = le32_to_cpu(disk->stripes_min);
863-
cpu->stripes_max = le32_to_cpu(disk->stripes_max);
864-
}
865-
866-
static inline void btrfs_cpu_balance_args_to_disk(
867-
struct btrfs_disk_balance_args *disk,
868-
const struct btrfs_balance_args *cpu)
869-
{
870-
memset(disk, 0, sizeof(*disk));
871-
872-
disk->profiles = cpu_to_le64(cpu->profiles);
873-
disk->usage = cpu_to_le64(cpu->usage);
874-
disk->devid = cpu_to_le64(cpu->devid);
875-
disk->pstart = cpu_to_le64(cpu->pstart);
876-
disk->pend = cpu_to_le64(cpu->pend);
877-
disk->vstart = cpu_to_le64(cpu->vstart);
878-
disk->vend = cpu_to_le64(cpu->vend);
879-
disk->target = cpu_to_le64(cpu->target);
880-
disk->flags = cpu_to_le64(cpu->flags);
881-
disk->limit = cpu_to_le64(cpu->limit);
882-
disk->stripes_min = cpu_to_le32(cpu->stripes_min);
883-
disk->stripes_max = cpu_to_le32(cpu->stripes_max);
884-
}
885-
886856
/* struct btrfs_super_block */
887857
BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
888858
BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);

fs/btrfs/acl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/sched/mm.h>
1313
#include <linux/slab.h>
1414
#include "ctree.h"
15-
#include "btrfs_inode.h"
1615
#include "xattr.h"
1716
#include "acl.h"
1817

fs/btrfs/acl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
#ifndef BTRFS_ACL_H
44
#define BTRFS_ACL_H
55

6+
struct posix_acl;
7+
struct inode;
8+
struct btrfs_trans_handle;
9+
610
#ifdef CONFIG_BTRFS_FS_POSIX_ACL
711

12+
struct mnt_idmap;
13+
struct dentry;
14+
815
struct posix_acl *btrfs_get_acl(struct inode *inode, int type, bool rcu);
916
int btrfs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
1017
struct posix_acl *acl, int type);
@@ -13,6 +20,10 @@ int __btrfs_set_acl(struct btrfs_trans_handle *trans, struct inode *inode,
1320

1421
#else
1522

23+
#include <linux/errno.h>
24+
25+
struct btrfs_trans_handle;
26+
1627
#define btrfs_get_acl NULL
1728
#define btrfs_set_acl NULL
1829
static inline int __btrfs_set_acl(struct btrfs_trans_handle *trans,

fs/btrfs/async-thread.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/freezer.h>
1212
#include <trace/events/btrfs.h>
1313
#include "async-thread.h"
14-
#include "ctree.h"
1514

1615
enum {
1716
WORK_DONE_BIT,

fs/btrfs/async-thread.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#ifndef BTRFS_ASYNC_THREAD_H
88
#define BTRFS_ASYNC_THREAD_H
99

10+
#include <linux/compiler_types.h>
1011
#include <linux/workqueue.h>
12+
#include <linux/list.h>
1113

1214
struct btrfs_fs_info;
1315
struct btrfs_workqueue;
1416
struct btrfs_work;
17+
1518
typedef void (*btrfs_func_t)(struct btrfs_work *arg);
1619
typedef void (*btrfs_ordered_func_t)(struct btrfs_work *arg, bool);
1720

fs/btrfs/backref.c

Lines changed: 108 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ static struct kmem_cache *btrfs_prelim_ref_cache;
198198
int __init btrfs_prelim_ref_init(void)
199199
{
200200
btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref",
201-
sizeof(struct prelim_ref),
202-
0,
203-
SLAB_MEM_SPREAD,
204-
NULL);
201+
sizeof(struct prelim_ref), 0, 0, NULL);
205202
if (!btrfs_prelim_ref_cache)
206203
return -ENOMEM;
207204
return 0;
@@ -1036,8 +1033,6 @@ static int add_inline_refs(struct btrfs_backref_walk_ctx *ctx,
10361033
slot = path->slots[0];
10371034

10381035
item_size = btrfs_item_size(leaf, slot);
1039-
BUG_ON(item_size < sizeof(*ei));
1040-
10411036
ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item);
10421037

10431038
if (ctx->check_extent_item) {
@@ -1435,8 +1430,10 @@ static int find_parent_nodes(struct btrfs_backref_walk_ctx *ctx,
14351430
if (ret < 0)
14361431
goto out;
14371432
if (ret == 0) {
1438-
/* This shouldn't happen, indicates a bug or fs corruption. */
1439-
ASSERT(ret != 0);
1433+
/*
1434+
* Key with offset -1 found, there would have to exist an extent
1435+
* item with such offset, but this is out of the valid range.
1436+
*/
14401437
ret = -EUCLEAN;
14411438
goto out;
14421439
}
@@ -2225,6 +2222,13 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
22252222
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
22262223
if (ret < 0)
22272224
return ret;
2225+
if (ret == 0) {
2226+
/*
2227+
* Key with offset -1 found, there would have to exist an extent
2228+
* item with such offset, but this is out of the valid range.
2229+
*/
2230+
return -EUCLEAN;
2231+
}
22282232

22292233
ret = btrfs_previous_extent_item(extent_root, path, 0);
22302234
if (ret) {
@@ -2247,7 +2251,6 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
22472251

22482252
eb = path->nodes[0];
22492253
item_size = btrfs_item_size(eb, path->slots[0]);
2250-
BUG_ON(item_size < sizeof(*ei));
22512254

22522255
ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item);
22532256
flags = btrfs_extent_flags(eb, ei);
@@ -2850,6 +2853,16 @@ struct btrfs_backref_iter *btrfs_backref_iter_alloc(struct btrfs_fs_info *fs_inf
28502853
return ret;
28512854
}
28522855

2856+
static void btrfs_backref_iter_release(struct btrfs_backref_iter *iter)
2857+
{
2858+
iter->bytenr = 0;
2859+
iter->item_ptr = 0;
2860+
iter->cur_ptr = 0;
2861+
iter->end_ptr = 0;
2862+
btrfs_release_path(iter->path);
2863+
memset(&iter->cur_key, 0, sizeof(iter->cur_key));
2864+
}
2865+
28532866
int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
28542867
{
28552868
struct btrfs_fs_info *fs_info = iter->fs_info;
@@ -2868,6 +2881,10 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
28682881
if (ret < 0)
28692882
return ret;
28702883
if (ret == 0) {
2884+
/*
2885+
* Key with offset -1 found, there would have to exist an extent
2886+
* item with such offset, but this is out of the valid range.
2887+
*/
28712888
ret = -EUCLEAN;
28722889
goto release;
28732890
}
@@ -2938,6 +2955,14 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
29382955
return ret;
29392956
}
29402957

2958+
static bool btrfs_backref_iter_is_inline_ref(struct btrfs_backref_iter *iter)
2959+
{
2960+
if (iter->cur_key.type == BTRFS_EXTENT_ITEM_KEY ||
2961+
iter->cur_key.type == BTRFS_METADATA_ITEM_KEY)
2962+
return true;
2963+
return false;
2964+
}
2965+
29412966
/*
29422967
* Go to the next backref item of current bytenr, can be either inlined or
29432968
* keyed.
@@ -2950,7 +2975,7 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
29502975
*/
29512976
int btrfs_backref_iter_next(struct btrfs_backref_iter *iter)
29522977
{
2953-
struct extent_buffer *eb = btrfs_backref_get_eb(iter);
2978+
struct extent_buffer *eb = iter->path->nodes[0];
29542979
struct btrfs_root *extent_root;
29552980
struct btrfs_path *path = iter->path;
29562981
struct btrfs_extent_inline_ref *iref;
@@ -3038,6 +3063,19 @@ struct btrfs_backref_node *btrfs_backref_alloc_node(
30383063
return node;
30393064
}
30403065

3066+
void btrfs_backref_free_node(struct btrfs_backref_cache *cache,
3067+
struct btrfs_backref_node *node)
3068+
{
3069+
if (node) {
3070+
ASSERT(list_empty(&node->list));
3071+
ASSERT(list_empty(&node->lower));
3072+
ASSERT(node->eb == NULL);
3073+
cache->nr_nodes--;
3074+
btrfs_put_root(node->root);
3075+
kfree(node);
3076+
}
3077+
}
3078+
30413079
struct btrfs_backref_edge *btrfs_backref_alloc_edge(
30423080
struct btrfs_backref_cache *cache)
30433081
{
@@ -3049,6 +3087,52 @@ struct btrfs_backref_edge *btrfs_backref_alloc_edge(
30493087
return edge;
30503088
}
30513089

3090+
void btrfs_backref_free_edge(struct btrfs_backref_cache *cache,
3091+
struct btrfs_backref_edge *edge)
3092+
{
3093+
if (edge) {
3094+
cache->nr_edges--;
3095+
kfree(edge);
3096+
}
3097+
}
3098+
3099+
void btrfs_backref_unlock_node_buffer(struct btrfs_backref_node *node)
3100+
{
3101+
if (node->locked) {
3102+
btrfs_tree_unlock(node->eb);
3103+
node->locked = 0;
3104+
}
3105+
}
3106+
3107+
void btrfs_backref_drop_node_buffer(struct btrfs_backref_node *node)
3108+
{
3109+
if (node->eb) {
3110+
btrfs_backref_unlock_node_buffer(node);
3111+
free_extent_buffer(node->eb);
3112+
node->eb = NULL;
3113+
}
3114+
}
3115+
3116+
/*
3117+
* Drop the backref node from cache without cleaning up its children
3118+
* edges.
3119+
*
3120+
* This can only be called on node without parent edges.
3121+
* The children edges are still kept as is.
3122+
*/
3123+
void btrfs_backref_drop_node(struct btrfs_backref_cache *tree,
3124+
struct btrfs_backref_node *node)
3125+
{
3126+
ASSERT(list_empty(&node->upper));
3127+
3128+
btrfs_backref_drop_node_buffer(node);
3129+
list_del_init(&node->list);
3130+
list_del_init(&node->lower);
3131+
if (!RB_EMPTY_NODE(&node->rb_node))
3132+
rb_erase(&node->rb_node, &tree->rb_root);
3133+
btrfs_backref_free_node(tree, node);
3134+
}
3135+
30523136
/*
30533137
* Drop the backref node from cache, also cleaning up all its
30543138
* upper edges and any uncached nodes in the path.
@@ -3120,6 +3204,19 @@ void btrfs_backref_release_cache(struct btrfs_backref_cache *cache)
31203204
ASSERT(!cache->nr_edges);
31213205
}
31223206

3207+
void btrfs_backref_link_edge(struct btrfs_backref_edge *edge,
3208+
struct btrfs_backref_node *lower,
3209+
struct btrfs_backref_node *upper,
3210+
int link_which)
3211+
{
3212+
ASSERT(upper && lower && upper->level == lower->level + 1);
3213+
edge->node[LOWER] = lower;
3214+
edge->node[UPPER] = upper;
3215+
if (link_which & LINK_LOWER)
3216+
list_add_tail(&edge->list[LOWER], &lower->upper);
3217+
if (link_which & LINK_UPPER)
3218+
list_add_tail(&edge->list[UPPER], &upper->lower);
3219+
}
31233220
/*
31243221
* Handle direct tree backref
31253222
*
@@ -3428,7 +3525,7 @@ int btrfs_backref_add_tree_node(struct btrfs_trans_handle *trans,
34283525
int type;
34293526

34303527
cond_resched();
3431-
eb = btrfs_backref_get_eb(iter);
3528+
eb = iter->path->nodes[0];
34323529

34333530
key.objectid = iter->bytenr;
34343531
if (btrfs_backref_iter_is_inline_ref(iter)) {

0 commit comments

Comments
 (0)