From: Christoph Hellwig <hch@lst.de>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
"Darrick J. Wong" <djwong@kernel.org>
Cc: linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 4/5] btrfs: allocate dio_data on stack
Date: Wed, 4 May 2022 09:23:41 -0700 [thread overview]
Message-ID: <20220504162342.573651-5-hch@lst.de> (raw)
In-Reply-To: <20220504162342.573651-1-hch@lst.de>
Make use of the new iomap_iter->private field to avoid a memory
allocation per iomap range.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/btrfs/inode.c | 33 +++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index cdf96a2472821..6ecff32c1fc22 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7546,10 +7546,11 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
loff_t length, unsigned int flags, struct iomap *iomap,
struct iomap *srcmap)
{
+ struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct extent_map *em;
struct extent_state *cached_state = NULL;
- struct btrfs_dio_data *dio_data = NULL;
+ struct btrfs_dio_data *dio_data = iter->private;
u64 lockstart, lockend;
const bool write = !!(flags & IOMAP_WRITE);
int ret = 0;
@@ -7595,17 +7596,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
}
}
- if (flags & IOMAP_NOWAIT) {
- dio_data = kzalloc(sizeof(*dio_data), GFP_NOWAIT);
- if (!dio_data)
- return -EAGAIN;
- } else {
- dio_data = kzalloc(sizeof(*dio_data), GFP_NOFS);
- if (!dio_data)
- return -ENOMEM;
- }
-
- iomap->private = dio_data;
+ memset(dio_data, 0, sizeof(*dio_data));
/*
* We always try to allocate data space and must do it before locking
@@ -7769,23 +7760,22 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
extent_changeset_free(dio_data->data_reserved);
}
- kfree(dio_data);
-
return ret;
}
static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length,
ssize_t written, unsigned int flags, struct iomap *iomap)
{
- int ret = 0;
- struct btrfs_dio_data *dio_data = iomap->private;
+ struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
+ struct btrfs_dio_data *dio_data = iter->private;
size_t submitted = dio_data->submitted;
const bool write = !!(flags & IOMAP_WRITE);
+ int ret = 0;
if (!write && (iomap->type == IOMAP_HOLE)) {
/* If reading from a hole, unlock and return */
unlock_extent(&BTRFS_I(inode)->io_tree, pos, pos + length - 1);
- goto out;
+ return 0;
}
if (submitted < length) {
@@ -7802,10 +7792,6 @@ static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length,
if (write)
extent_changeset_free(dio_data->data_reserved);
-out:
- kfree(dio_data);
- iomap->private = NULL;
-
return ret;
}
@@ -8041,7 +8027,7 @@ static void btrfs_submit_direct(const struct iomap_iter *iter,
int ret;
blk_status_t status;
struct btrfs_io_geometry geom;
- struct btrfs_dio_data *dio_data = iter->iomap.private;
+ struct btrfs_dio_data *dio_data = iter->private;
struct extent_map *em = NULL;
dip = btrfs_create_dio_private(dio_bio, inode, file_offset);
@@ -8167,6 +8153,9 @@ static const struct iomap_dio_ops btrfs_dio_ops = {
ssize_t btrfs_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
size_t done_before)
{
+ struct btrfs_dio_data data;
+
+ iocb->private = &data;
return iomap_dio_rw(iocb, iter, &btrfs_dio_iomap_ops, &btrfs_dio_ops,
IOMAP_DIO_PARTIAL, done_before);
}
--
2.30.2
next prev parent reply other threads:[~2022-05-04 16:23 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-04 16:23 reduce memory allocation in the btrfs direct I/O path Christoph Hellwig
2022-05-04 16:23 ` [PATCH 1/5] iomap: allow the file system to provide a bio_set for direct I/O Christoph Hellwig
2022-05-05 15:38 ` Darrick J. Wong
2022-05-04 16:23 ` [PATCH 2/5] iomap: add per-iomap_iter private data Christoph Hellwig
2022-05-05 8:06 ` Nikolay Borisov
2022-05-05 15:06 ` Christoph Hellwig
2022-05-05 15:41 ` Darrick J. Wong
2022-05-05 15:45 ` Christoph Hellwig
2022-05-05 16:32 ` Darrick J. Wong
2022-05-05 18:15 ` Christoph Hellwig
2022-05-05 18:18 ` Darrick J. Wong
2022-05-04 16:23 ` [PATCH 3/5] btrfs: add a btrfs_dio_rw wrapper Christoph Hellwig
2022-05-04 16:23 ` Christoph Hellwig [this message]
2022-05-04 16:23 ` [PATCH 5/5] btrfs: allocate the btrfs_dio_private as part of the iomap dio bio Christoph Hellwig
2022-05-05 8:12 ` Nikolay Borisov
2022-05-05 15:07 ` Christoph Hellwig
2022-05-05 15:20 ` David Sterba
2022-05-05 15:52 ` David Sterba
2022-05-05 8:33 ` reduce memory allocation in the btrfs direct I/O path Nikolay Borisov
2022-05-05 15:55 ` David Sterba
2022-05-06 17:18 ` Darrick J. Wong
2022-05-07 5:26 ` Christoph Hellwig
2022-05-09 18:46 ` David Sterba
2022-05-10 3:33 ` Darrick J. Wong
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=20220504162342.573651-5-hch@lst.de \
--to=hch@lst.de \
--cc=clm@fb.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.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).