Skip to content

Commit 7e69dd6

Browse files
committed
Merge patch series "fs/buffer: misc optimizations"
Davidlohr Bueso <[email protected]> says: Four small patches - the first could be sent to Linus for v6.15 considering it is a missing nonblocking lookup conversion in the getblk slowpath I had missed. The other two patches are small optimizations found while reading the code, and one rocket science cleanup patch. * patches from https://lore.kernel.org/[email protected]: fs/buffer: optimize discard_buffer() fs/buffer: remove superfluous statements fs/buffer: avoid redundant lookup in getblk slowpath fs/buffer: use sleeping lookup in __getblk_slowpath() Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents a5806cd + 8e184bf commit 7e69dd6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

fs/buffer.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
297297

298298
still_busy:
299299
spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
300-
return;
301300
}
302301

303302
struct postprocess_bh_ctx {
@@ -422,7 +421,6 @@ static void end_buffer_async_write(struct buffer_head *bh, int uptodate)
422421

423422
still_busy:
424423
spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
425-
return;
426424
}
427425

428426
/*
@@ -1122,6 +1120,8 @@ static struct buffer_head *
11221120
__getblk_slow(struct block_device *bdev, sector_t block,
11231121
unsigned size, gfp_t gfp)
11241122
{
1123+
bool blocking = gfpflags_allow_blocking(gfp);
1124+
11251125
/* Size must be multiple of hard sectorsize */
11261126
if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
11271127
(size < 512 || size > PAGE_SIZE))) {
@@ -1137,12 +1137,15 @@ __getblk_slow(struct block_device *bdev, sector_t block,
11371137
for (;;) {
11381138
struct buffer_head *bh;
11391139

1140-
bh = __find_get_block(bdev, block, size);
1141-
if (bh)
1142-
return bh;
1143-
11441140
if (!grow_buffers(bdev, block, size, gfp))
11451141
return NULL;
1142+
1143+
if (blocking)
1144+
bh = __find_get_block_nonatomic(bdev, block, size);
1145+
else
1146+
bh = __find_get_block(bdev, block, size);
1147+
if (bh)
1148+
return bh;
11461149
}
11471150
}
11481151

@@ -1611,8 +1614,8 @@ static void discard_buffer(struct buffer_head * bh)
16111614
bh->b_bdev = NULL;
16121615
b_state = READ_ONCE(bh->b_state);
16131616
do {
1614-
} while (!try_cmpxchg(&bh->b_state, &b_state,
1615-
b_state & ~BUFFER_FLAGS_DISCARD));
1617+
} while (!try_cmpxchg_relaxed(&bh->b_state, &b_state,
1618+
b_state & ~BUFFER_FLAGS_DISCARD));
16161619
unlock_buffer(bh);
16171620
}
16181621

@@ -1677,7 +1680,6 @@ void block_invalidate_folio(struct folio *folio, size_t offset, size_t length)
16771680
filemap_release_folio(folio, 0);
16781681
out:
16791682
folio_clear_mappedtodisk(folio);
1680-
return;
16811683
}
16821684
EXPORT_SYMBOL(block_invalidate_folio);
16831685

0 commit comments

Comments
 (0)