From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org,
torvalds@linux-foundation.org,
Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH 02/17] iomap: Protect read_bytes_pending with the state_lock
Date: Fri, 15 Sep 2023 19:36:52 +0100 [thread overview]
Message-ID: <20230915183707.2707298-3-willy@infradead.org> (raw)
In-Reply-To: <20230915183707.2707298-1-willy@infradead.org>
Perform one atomic operation (acquiring the spinlock) instead of
two (spinlock & atomic_sub) per read completion.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/iomap/buffered-io.c | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 4c05fd457ee7..cade15b70627 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -29,9 +29,9 @@ typedef int (*iomap_punch_t)(struct inode *inode, loff_t offset, loff_t length);
* and I/O completions.
*/
struct iomap_folio_state {
- atomic_t read_bytes_pending;
- atomic_t write_bytes_pending;
spinlock_t state_lock;
+ unsigned int read_bytes_pending;
+ atomic_t write_bytes_pending;
/*
* Each block has two bits in this bitmap:
@@ -183,7 +183,7 @@ static void ifs_free(struct folio *folio)
if (!ifs)
return;
- WARN_ON_ONCE(atomic_read(&ifs->read_bytes_pending));
+ WARN_ON_ONCE(ifs->read_bytes_pending != 0);
WARN_ON_ONCE(atomic_read(&ifs->write_bytes_pending));
WARN_ON_ONCE(ifs_is_fully_uptodate(folio, ifs) !=
folio_test_uptodate(folio));
@@ -250,19 +250,33 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
*lenp = plen;
}
-static void iomap_finish_folio_read(struct folio *folio, size_t offset,
+static void iomap_finish_folio_read(struct folio *folio, size_t off,
size_t len, int error)
{
struct iomap_folio_state *ifs = folio->private;
+ unsigned long flags;
+ bool uptodate;
+ bool finished = true;
+
+ if (ifs)
+ spin_lock_irqsave(&ifs->state_lock, flags);
if (unlikely(error)) {
- folio_clear_uptodate(folio);
+ uptodate = false;
folio_set_error(folio);
} else {
- iomap_set_range_uptodate(folio, offset, len);
+ uptodate = !ifs || ifs_set_range_uptodate(folio, ifs, off, len);
}
- if (!ifs || atomic_sub_and_test(len, &ifs->read_bytes_pending))
+ if (ifs) {
+ ifs->read_bytes_pending -= len;
+ finished = !ifs->read_bytes_pending;
+ spin_unlock_irqrestore(&ifs->state_lock, flags);
+ }
+
+ if (uptodate)
+ folio_mark_uptodate(folio);
+ if (finished)
folio_unlock(folio);
}
@@ -360,8 +374,11 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter,
}
ctx->cur_folio_in_bio = true;
- if (ifs)
- atomic_add(plen, &ifs->read_bytes_pending);
+ if (ifs) {
+ spin_lock_irq(&ifs->state_lock);
+ ifs->read_bytes_pending += plen;
+ spin_unlock_irq(&ifs->state_lock);
+ }
sector = iomap_sector(iomap, pos);
if (!ctx->bio ||
--
2.40.1
next prev parent reply other threads:[~2023-09-15 18:38 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-15 18:36 [PATCH 00/17] Add folio_end_read Matthew Wilcox (Oracle)
2023-09-15 18:36 ` [PATCH 01/17] iomap: Hold state_lock over call to ifs_set_range_uptodate() Matthew Wilcox (Oracle)
2023-09-15 18:36 ` Matthew Wilcox (Oracle) [this message]
2023-09-16 0:11 ` [PATCH 02/17] iomap: Protect read_bytes_pending with the state_lock Linus Torvalds
2023-09-16 0:15 ` Linus Torvalds
2023-09-16 15:50 ` Matthew Wilcox
2023-09-15 18:36 ` [PATCH 03/17] mm: Add folio_end_read() Matthew Wilcox (Oracle)
2023-09-15 18:36 ` [PATCH 04/17] ext4: Use folio_end_read() Matthew Wilcox (Oracle)
2023-09-15 18:36 ` [PATCH 05/17] buffer: " Matthew Wilcox (Oracle)
2023-09-15 18:36 ` [PATCH 06/17] iomap: " Matthew Wilcox (Oracle)
2023-09-15 18:36 ` [PATCH 07/17] bitops: Add xor_unlock_is_negative_byte() Matthew Wilcox (Oracle)
2023-09-15 18:36 ` [PATCH 08/17] alpha: Implement xor_unlock_is_negative_byte Matthew Wilcox (Oracle)
2023-09-16 0:27 ` Linus Torvalds
2023-09-16 0:38 ` Matthew Wilcox
2023-09-16 2:01 ` Linus Torvalds
2023-09-16 2:14 ` Linus Torvalds
2023-09-16 15:59 ` Matthew Wilcox
2023-09-15 18:36 ` [PATCH 09/17] m68k: " Matthew Wilcox (Oracle)
2023-09-16 13:11 ` Greg Ungerer
2023-09-16 14:34 ` Matthew Wilcox
2023-09-18 14:37 ` Greg Ungerer
2023-09-20 7:45 ` Greg Ungerer
2023-09-20 16:58 ` Linus Torvalds
2023-09-19 13:23 ` David Laight
2023-09-19 14:26 ` Matthew Wilcox
2023-09-19 14:35 ` David Laight
2023-09-19 15:14 ` Matthew Wilcox
2023-09-19 15:22 ` David Laight
2023-09-19 15:47 ` Matthew Wilcox
2023-09-19 15:57 ` David Laight
2023-09-20 7:15 ` Greg Ungerer
2023-09-20 7:22 ` Greg Ungerer
2023-10-02 20:07 ` Matthew Wilcox
2023-10-03 14:14 ` Greg Ungerer
2023-10-03 20:07 ` Matthew Wilcox
2023-10-04 12:06 ` Greg Ungerer
2023-09-15 18:37 ` [PATCH 10/17] mips: " Matthew Wilcox (Oracle)
2023-09-15 18:37 ` [PATCH 11/17] powerpc: Implement arch_xor_unlock_is_negative_byte on 32-bit Matthew Wilcox (Oracle)
2023-09-15 18:37 ` [PATCH 12/17] riscv: Implement xor_unlock_is_negative_byte Matthew Wilcox (Oracle)
2023-09-15 18:37 ` [PATCH 13/17] s390: Implement arch_xor_unlock_is_negative_byte Matthew Wilcox (Oracle)
2023-09-15 18:37 ` [PATCH 14/17] mm: Delete checks for xor_unlock_is_negative_byte() Matthew Wilcox (Oracle)
2023-09-15 18:37 ` [PATCH 15/17] mm: Add folio_xor_flags_has_waiters() Matthew Wilcox (Oracle)
2023-09-15 18:37 ` [PATCH 16/17] mm: Make __end_folio_writeback() return void Matthew Wilcox (Oracle)
2023-09-15 18:37 ` [PATCH 17/17] mm: Use folio_xor_flags_has_waiters() in folio_end_writeback() Matthew Wilcox (Oracle)
2023-09-16 0:31 ` [PATCH 00/17] Add folio_end_read Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230915183707.2707298-3-willy@infradead.org \
--to=willy@infradead.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=npiggin@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).