Skip to content

Commit d551d7b

Browse files
committed
Merge tag 'xfs-fixes-6.16-rc7' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull xfs fixes from Carlos Maiolino: "This contains mostly code clean up, refactoring and comments modification. The most important patch in this series is the last one that removes an unnecessary data structure allocation of xfs busy extents which might lead to a memory leak on the zoned allocator code" * tag 'xfs-fixes-6.16-rc7' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: xfs: don't allocate the xfs_extent_busy structure for zoned RTGs xfs: remove the bt_bdev_file buftarg field xfs: rename the bt_bdev_* buftarg fields xfs: refactor xfs_calc_atomic_write_unit_max xfs: add a xfs_group_type_buftarg helper xfs: remove the call to sync_blockdev in xfs_configure_buftarg xfs: clean up the initial read logic in xfs_readsb xfs: replace strncpy with memcpy in xattr listing
2 parents d3d16f3 + 5948705 commit d551d7b

14 files changed

+108
-124
lines changed

fs/xfs/libxfs/xfs_group.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ xfs_group_free(
163163

164164
xfs_defer_drain_free(&xg->xg_intents_drain);
165165
#ifdef __KERNEL__
166-
kfree(xg->xg_busy_extents);
166+
if (xfs_group_has_extent_busy(xg->xg_mount, xg->xg_type))
167+
kfree(xg->xg_busy_extents);
167168
#endif
168169

169170
if (uninit)
@@ -189,9 +190,11 @@ xfs_group_insert(
189190
xg->xg_type = type;
190191

191192
#ifdef __KERNEL__
192-
xg->xg_busy_extents = xfs_extent_busy_alloc();
193-
if (!xg->xg_busy_extents)
194-
return -ENOMEM;
193+
if (xfs_group_has_extent_busy(mp, type)) {
194+
xg->xg_busy_extents = xfs_extent_busy_alloc();
195+
if (!xg->xg_busy_extents)
196+
return -ENOMEM;
197+
}
195198
spin_lock_init(&xg->xg_state_lock);
196199
xfs_hooks_init(&xg->xg_rmap_update_hooks);
197200
#endif
@@ -210,7 +213,8 @@ xfs_group_insert(
210213
out_drain:
211214
xfs_defer_drain_free(&xg->xg_intents_drain);
212215
#ifdef __KERNEL__
213-
kfree(xg->xg_busy_extents);
216+
if (xfs_group_has_extent_busy(xg->xg_mount, xg->xg_type))
217+
kfree(xg->xg_busy_extents);
214218
#endif
215219
return error;
216220
}

fs/xfs/xfs_buf.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ xfs_free_buftarg(
16831683
fs_put_dax(btp->bt_daxdev, btp->bt_mount);
16841684
/* the main block device is closed by kill_block_super */
16851685
if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
1686-
bdev_fput(btp->bt_bdev_file);
1686+
bdev_fput(btp->bt_file);
16871687
kfree(btp);
16881688
}
16891689

@@ -1712,8 +1712,8 @@ xfs_configure_buftarg_atomic_writes(
17121712
max_bytes = 0;
17131713
}
17141714

1715-
btp->bt_bdev_awu_min = min_bytes;
1716-
btp->bt_bdev_awu_max = max_bytes;
1715+
btp->bt_awu_min = min_bytes;
1716+
btp->bt_awu_max = max_bytes;
17171717
}
17181718

17191719
/* Configure a buffer target that abstracts a block device. */
@@ -1738,14 +1738,9 @@ xfs_configure_buftarg(
17381738
return -EINVAL;
17391739
}
17401740

1741-
/*
1742-
* Flush the block device pagecache so our bios see anything dirtied
1743-
* before mount.
1744-
*/
17451741
if (bdev_can_atomic_write(btp->bt_bdev))
17461742
xfs_configure_buftarg_atomic_writes(btp);
1747-
1748-
return sync_blockdev(btp->bt_bdev);
1743+
return 0;
17491744
}
17501745

17511746
int
@@ -1803,7 +1798,7 @@ xfs_alloc_buftarg(
18031798
btp = kzalloc(sizeof(*btp), GFP_KERNEL | __GFP_NOFAIL);
18041799

18051800
btp->bt_mount = mp;
1806-
btp->bt_bdev_file = bdev_file;
1801+
btp->bt_file = bdev_file;
18071802
btp->bt_bdev = file_bdev(bdev_file);
18081803
btp->bt_dev = btp->bt_bdev->bd_dev;
18091804
btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,

fs/xfs/xfs_buf.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ void xfs_buf_cache_destroy(struct xfs_buf_cache *bch);
9494
*/
9595
struct xfs_buftarg {
9696
dev_t bt_dev;
97-
struct file *bt_bdev_file;
9897
struct block_device *bt_bdev;
9998
struct dax_device *bt_daxdev;
10099
struct file *bt_file;
@@ -112,9 +111,9 @@ struct xfs_buftarg {
112111
struct percpu_counter bt_readahead_count;
113112
struct ratelimit_state bt_ioerror_rl;
114113

115-
/* Atomic write unit values, bytes */
116-
unsigned int bt_bdev_awu_min;
117-
unsigned int bt_bdev_awu_max;
114+
/* Hardware atomic write unit values, bytes */
115+
unsigned int bt_awu_min;
116+
unsigned int bt_awu_max;
118117

119118
/* built-in cache, if we're not using the perag one */
120119
struct xfs_buf_cache bt_cache[];
@@ -375,7 +374,6 @@ extern void xfs_buftarg_wait(struct xfs_buftarg *);
375374
extern void xfs_buftarg_drain(struct xfs_buftarg *);
376375
int xfs_configure_buftarg(struct xfs_buftarg *btp, unsigned int sectorsize);
377376

378-
#define xfs_getsize_buftarg(buftarg) block_size((buftarg)->bt_bdev)
379377
#define xfs_readonly_buftarg(buftarg) bdev_read_only((buftarg)->bt_bdev)
380378

381379
int xfs_buf_reverify(struct xfs_buf *bp, const struct xfs_buf_ops *ops);

fs/xfs/xfs_discard.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,6 @@ xfs_discard_endio(
103103
bio_put(bio);
104104
}
105105

106-
static inline struct block_device *
107-
xfs_group_bdev(
108-
const struct xfs_group *xg)
109-
{
110-
struct xfs_mount *mp = xg->xg_mount;
111-
112-
switch (xg->xg_type) {
113-
case XG_TYPE_AG:
114-
return mp->m_ddev_targp->bt_bdev;
115-
case XG_TYPE_RTG:
116-
return mp->m_rtdev_targp->bt_bdev;
117-
default:
118-
ASSERT(0);
119-
break;
120-
}
121-
return NULL;
122-
}
123-
124106
/*
125107
* Walk the discard list and issue discards on all the busy extents in the
126108
* list. We plug and chain the bios so that we only need a single completion
@@ -138,11 +120,14 @@ xfs_discard_extents(
138120

139121
blk_start_plug(&plug);
140122
list_for_each_entry(busyp, &extents->extent_list, list) {
141-
trace_xfs_discard_extent(busyp->group, busyp->bno,
142-
busyp->length);
123+
struct xfs_group *xg = busyp->group;
124+
struct xfs_buftarg *btp =
125+
xfs_group_type_buftarg(xg->xg_mount, xg->xg_type);
126+
127+
trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
143128

144-
error = __blkdev_issue_discard(xfs_group_bdev(busyp->group),
145-
xfs_gbno_to_daddr(busyp->group, busyp->bno),
129+
error = __blkdev_issue_discard(btp->bt_bdev,
130+
xfs_gbno_to_daddr(xg, busyp->bno),
146131
XFS_FSB_TO_BB(mp, busyp->length),
147132
GFP_KERNEL, &bio);
148133
if (error && error != -EOPNOTSUPP) {

fs/xfs/xfs_extent_busy.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,12 @@ static inline void xfs_extent_busy_sort(struct list_head *list)
6868
list_sort(NULL, list, xfs_extent_busy_ag_cmp);
6969
}
7070

71+
/*
72+
* Zoned RTGs don't need to track busy extents, as the actual block freeing only
73+
* happens by a zone reset, which forces out all transactions that touched the
74+
* to be reset zone first.
75+
*/
76+
#define xfs_group_has_extent_busy(mp, type) \
77+
((type) == XG_TYPE_AG || !xfs_has_zoned((mp)))
78+
7179
#endif /* __XFS_EXTENT_BUSY_H__ */

fs/xfs/xfs_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ xfs_file_dio_write_atomic(
752752
* HW offload should be faster, so try that first if it is already
753753
* known that the write length is not too large.
754754
*/
755-
if (ocount > xfs_inode_buftarg(ip)->bt_bdev_awu_max)
755+
if (ocount > xfs_inode_buftarg(ip)->bt_awu_max)
756756
dops = &xfs_atomic_write_cow_iomap_ops;
757757
else
758758
dops = &xfs_direct_write_iomap_ops;

fs/xfs/xfs_inode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ static inline bool xfs_inode_has_bigrtalloc(const struct xfs_inode *ip)
358358

359359
static inline bool xfs_inode_can_hw_atomic_write(const struct xfs_inode *ip)
360360
{
361-
return xfs_inode_buftarg(ip)->bt_bdev_awu_max > 0;
361+
return xfs_inode_buftarg(ip)->bt_awu_max > 0;
362362
}
363363

364364
/*

fs/xfs/xfs_iomap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ xfs_bmap_hw_atomic_write_possible(
827827
/*
828828
* The ->iomap_begin caller should ensure this, but check anyway.
829829
*/
830-
return len <= xfs_inode_buftarg(ip)->bt_bdev_awu_max;
830+
return len <= xfs_inode_buftarg(ip)->bt_awu_max;
831831
}
832832

833833
static int

fs/xfs/xfs_iops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ xfs_get_atomic_write_max_opt(
665665
* less than our out of place write limit, but we don't want to exceed
666666
* the awu_max.
667667
*/
668-
return min(awu_max, xfs_inode_buftarg(ip)->bt_bdev_awu_max);
668+
return min(awu_max, xfs_inode_buftarg(ip)->bt_awu_max);
669669
}
670670

671671
static void

fs/xfs/xfs_mount.c

Lines changed: 39 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,16 @@ xfs_readsb(
171171
ASSERT(mp->m_ddev_targp != NULL);
172172

173173
/*
174-
* For the initial read, we must guess at the sector
175-
* size based on the block device. It's enough to
176-
* get the sb_sectsize out of the superblock and
177-
* then reread with the proper length.
178-
* We don't verify it yet, because it may not be complete.
174+
* In the first pass, use the device sector size to just read enough
175+
* of the superblock to extract the XFS sector size.
176+
*
177+
* The device sector size must be smaller than or equal to the XFS
178+
* sector size and thus we can always read the superblock. Once we know
179+
* the XFS sector size, re-read it and run the buffer verifier.
179180
*/
180-
sector_size = xfs_getsize_buftarg(mp->m_ddev_targp);
181+
sector_size = mp->m_ddev_targp->bt_logical_sectorsize;
181182
buf_ops = NULL;
182183

183-
/*
184-
* Allocate a (locked) buffer to hold the superblock. This will be kept
185-
* around at all times to optimize access to the superblock.
186-
*/
187184
reread:
188185
error = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_SB_DADDR,
189186
BTOBB(sector_size), &bp, buf_ops);
@@ -247,6 +244,10 @@ xfs_readsb(
247244
/* no need to be quiet anymore, so reset the buf ops */
248245
bp->b_ops = &xfs_sb_buf_ops;
249246

247+
/*
248+
* Keep a pointer of the sb buffer around instead of caching it in the
249+
* buffer cache because we access it frequently.
250+
*/
250251
mp->m_sb_bp = bp;
251252
xfs_buf_unlock(bp);
252253
return 0;
@@ -678,68 +679,46 @@ static inline unsigned int max_pow_of_two_factor(const unsigned int nr)
678679
}
679680

680681
/*
681-
* If the data device advertises atomic write support, limit the size of data
682-
* device atomic writes to the greatest power-of-two factor of the AG size so
683-
* that every atomic write unit aligns with the start of every AG. This is
684-
* required so that the per-AG allocations for an atomic write will always be
682+
* If the underlying device advertises atomic write support, limit the size of
683+
* atomic writes to the greatest power-of-two factor of the group size so
684+
* that every atomic write unit aligns with the start of every group. This is
685+
* required so that the allocations for an atomic write will always be
685686
* aligned compatibly with the alignment requirements of the storage.
686687
*
687-
* If the data device doesn't advertise atomic writes, then there are no
688-
* alignment restrictions and the largest out-of-place write we can do
689-
* ourselves is the number of blocks that user files can allocate from any AG.
690-
*/
691-
static inline xfs_extlen_t xfs_calc_perag_awu_max(struct xfs_mount *mp)
692-
{
693-
if (mp->m_ddev_targp->bt_bdev_awu_min > 0)
694-
return max_pow_of_two_factor(mp->m_sb.sb_agblocks);
695-
return rounddown_pow_of_two(mp->m_ag_max_usable);
696-
}
697-
698-
/*
699-
* Reflink on the realtime device requires rtgroups, and atomic writes require
700-
* reflink.
701-
*
702-
* If the realtime device advertises atomic write support, limit the size of
703-
* data device atomic writes to the greatest power-of-two factor of the rtgroup
704-
* size so that every atomic write unit aligns with the start of every rtgroup.
705-
* This is required so that the per-rtgroup allocations for an atomic write
706-
* will always be aligned compatibly with the alignment requirements of the
707-
* storage.
708-
*
709-
* If the rt device doesn't advertise atomic writes, then there are no
710-
* alignment restrictions and the largest out-of-place write we can do
711-
* ourselves is the number of blocks that user files can allocate from any
712-
* rtgroup.
688+
* If the device doesn't advertise atomic writes, then there are no alignment
689+
* restrictions and the largest out-of-place write we can do ourselves is the
690+
* number of blocks that user files can allocate from any group.
713691
*/
714-
static inline xfs_extlen_t xfs_calc_rtgroup_awu_max(struct xfs_mount *mp)
692+
static xfs_extlen_t
693+
xfs_calc_group_awu_max(
694+
struct xfs_mount *mp,
695+
enum xfs_group_type type)
715696
{
716-
struct xfs_groups *rgs = &mp->m_groups[XG_TYPE_RTG];
697+
struct xfs_groups *g = &mp->m_groups[type];
698+
struct xfs_buftarg *btp = xfs_group_type_buftarg(mp, type);
717699

718-
if (rgs->blocks == 0)
700+
if (g->blocks == 0)
719701
return 0;
720-
if (mp->m_rtdev_targp && mp->m_rtdev_targp->bt_bdev_awu_min > 0)
721-
return max_pow_of_two_factor(rgs->blocks);
722-
return rounddown_pow_of_two(rgs->blocks);
702+
if (btp && btp->bt_awu_min > 0)
703+
return max_pow_of_two_factor(g->blocks);
704+
return rounddown_pow_of_two(g->blocks);
723705
}
724706

725707
/* Compute the maximum atomic write unit size for each section. */
726708
static inline void
727709
xfs_calc_atomic_write_unit_max(
728-
struct xfs_mount *mp)
710+
struct xfs_mount *mp,
711+
enum xfs_group_type type)
729712
{
730-
struct xfs_groups *ags = &mp->m_groups[XG_TYPE_AG];
731-
struct xfs_groups *rgs = &mp->m_groups[XG_TYPE_RTG];
713+
struct xfs_groups *g = &mp->m_groups[type];
732714

733715
const xfs_extlen_t max_write = xfs_calc_atomic_write_max(mp);
734716
const xfs_extlen_t max_ioend = xfs_reflink_max_atomic_cow(mp);
735-
const xfs_extlen_t max_agsize = xfs_calc_perag_awu_max(mp);
736-
const xfs_extlen_t max_rgsize = xfs_calc_rtgroup_awu_max(mp);
737-
738-
ags->awu_max = min3(max_write, max_ioend, max_agsize);
739-
rgs->awu_max = min3(max_write, max_ioend, max_rgsize);
717+
const xfs_extlen_t max_gsize = xfs_calc_group_awu_max(mp, type);
740718

741-
trace_xfs_calc_atomic_write_unit_max(mp, max_write, max_ioend,
742-
max_agsize, max_rgsize);
719+
g->awu_max = min3(max_write, max_ioend, max_gsize);
720+
trace_xfs_calc_atomic_write_unit_max(mp, type, max_write, max_ioend,
721+
max_gsize, g->awu_max);
743722
}
744723

745724
/*
@@ -757,7 +736,8 @@ xfs_set_max_atomic_write_opt(
757736
max(mp->m_groups[XG_TYPE_AG].blocks,
758737
mp->m_groups[XG_TYPE_RTG].blocks);
759738
const xfs_extlen_t max_group_write =
760-
max(xfs_calc_perag_awu_max(mp), xfs_calc_rtgroup_awu_max(mp));
739+
max(xfs_calc_group_awu_max(mp, XG_TYPE_AG),
740+
xfs_calc_group_awu_max(mp, XG_TYPE_RTG));
761741
int error;
762742

763743
if (new_max_bytes == 0)
@@ -813,7 +793,8 @@ xfs_set_max_atomic_write_opt(
813793
return error;
814794
}
815795

816-
xfs_calc_atomic_write_unit_max(mp);
796+
xfs_calc_atomic_write_unit_max(mp, XG_TYPE_AG);
797+
xfs_calc_atomic_write_unit_max(mp, XG_TYPE_RTG);
817798
mp->m_awu_max_bytes = new_max_bytes;
818799
return 0;
819800
}

0 commit comments

Comments
 (0)