From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Ross Zwisler <ross.zwisler@linux.intel.com>,
"karam . lee" <karam.lee@lge.com>,
seungho1.park@lge.com, Matthew Wilcox <willy@infradead.org>,
Christoph Hellwig <hch@lst.de>,
Dan Williams <dan.j.williams@intel.com>,
Dave Chinner <david@fromorbit.com>,
jack@suse.cz, Jens Axboe <axboe@kernel.dk>,
Vishal Verma <vishal.l.verma@intel.com>,
linux-nvdimm@lists.01.org, kernel-team <kernel-team@lge.com>,
Minchan Kim <minchan@kernel.org>
Subject: [PATCH v2 3/7] fs: use on-stack-bio if backing device has BDI_CAP_SYNCHRONOUS capability
Date: Fri, 11 Aug 2017 14:17:23 +0900 [thread overview]
Message-ID: <1502428647-28928-4-git-send-email-minchan@kernel.org> (raw)
In-Reply-To: <1502428647-28928-1-git-send-email-minchan@kernel.org>
There is no need to use dynamic bio allocation for BDI_CAP_SYNCHRONOUS
devices. They can with on-stack bio without concern about waiting
bio allocation from mempool under heavy memory pressure.
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
Hi Mattew,
I didn't use sbvec[nr_pages] as you suggested[1] because I don't think
it's pointless in do_mpage_readpage which works per-page base as
I replied to you.
If I misunderstood something, please correct me.
[1] http://lkml.kernel.org/r/<20170808132904.GC31390@bombadil.infradead.org>
fs/mpage.c | 47 ++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 40 insertions(+), 7 deletions(-)
diff --git a/fs/mpage.c b/fs/mpage.c
index 2e4c41ccb5c9..d3b777fdfd5a 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -162,6 +162,9 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
int fully_mapped = 1;
unsigned nblocks;
unsigned relative_block;
+ /* on-stack bio for synchronous devices */
+ struct bio sbio;
+ struct bio_vec sbvec;
if (page_has_buffers(page))
goto confused;
@@ -282,10 +285,22 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
page))
goto out;
}
- bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
+
+ if (bdi_cap_synchronous_io(inode_to_bdi(inode))) {
+ bio = &sbio;
+ /* mpage_end_io calls bio_put unconditionally */
+ bio_get(&sbio);
+
+ bio_init(&sbio, &sbvec, 1);
+ sbio.bi_bdev = bdev;
+ sbio.bi_iter.bi_sector = blocks[0] << (blkbits - 9);
+ } else {
+
+ bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
min_t(int, nr_pages, BIO_MAX_PAGES), gfp);
- if (bio == NULL)
- goto confused;
+ if (bio == NULL)
+ goto confused;
+ }
}
length = first_hole << blkbits;
@@ -302,6 +317,8 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
else
*last_block_in_bio = blocks[blocks_per_page - 1];
out:
+ if (bio == &sbio)
+ bio = mpage_bio_submit(REQ_OP_READ, 0, bio);
return bio;
confused:
@@ -492,6 +509,9 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
loff_t i_size = i_size_read(inode);
int ret = 0;
int op_flags = wbc_to_write_flags(wbc);
+ /* on-stack-bio */
+ struct bio sbio;
+ struct bio_vec sbvec;
if (page_has_buffers(page)) {
struct buffer_head *head = page_buffers(page);
@@ -610,10 +630,21 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
goto out;
}
}
- bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
- BIO_MAX_PAGES, GFP_NOFS|__GFP_HIGH);
- if (bio == NULL)
- goto confused;
+
+ if (bdi_cap_synchronous_io(inode_to_bdi(inode))) {
+ bio = &sbio;
+ /* mpage_end_io calls bio_put unconditionally */
+ bio_get(&sbio);
+
+ bio_init(&sbio, &sbvec, 1);
+ sbio.bi_bdev = bdev;
+ sbio.bi_iter.bi_sector = blocks[0] << (blkbits - 9);
+ } else {
+ bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
+ BIO_MAX_PAGES, GFP_NOFS|__GFP_HIGH);
+ if (bio == NULL)
+ goto confused;
+ }
wbc_init_bio(wbc, bio);
bio->bi_write_hint = inode->i_write_hint;
@@ -662,6 +693,8 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
*/
mapping_set_error(mapping, ret);
out:
+ if (bio == &sbio)
+ bio = mpage_bio_submit(REQ_OP_WRITE, op_flags, bio);
mpd->bio = bio;
return ret;
}
--
2.7.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-08-11 5:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-11 5:17 [PATCH v2 0/7] Replace rw_page with on-stack bio Minchan Kim
2017-08-11 5:17 ` [PATCH v2 1/7] zram: set BDI_CAP_STABLE_WRITES once Minchan Kim
2017-08-14 1:39 ` Sergey Senozhatsky
2017-08-11 5:17 ` [PATCH v2 2/7] bdi: introduce BDI_CAP_SYNCHRONOUS_IO Minchan Kim
2017-08-11 5:17 ` Minchan Kim [this message]
2017-08-11 5:17 ` [PATCH v2 4/7] mm:swap: remove end_swap_bio_write argument Minchan Kim
2017-08-11 5:17 ` [PATCH v2 5/7] mm:swap: use on-stack-bio for BDI_CAP_SYNCHRONOUS device Minchan Kim
2017-08-12 8:21 ` kbuild test robot
2017-08-12 8:46 ` kbuild test robot
2017-08-14 8:41 ` Minchan Kim
2017-08-11 5:17 ` [PATCH v2 6/7] zram: remove zram_rw_page Minchan Kim
2017-08-11 5:17 ` [PATCH v2 7/7] fs: remove rw_page Minchan Kim
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=1502428647-28928-4-git-send-email-minchan@kernel.org \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=dan.j.williams@intel.com \
--cc=david@fromorbit.com \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=karam.lee@lge.com \
--cc=kernel-team@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nvdimm@lists.01.org \
--cc=ross.zwisler@linux.intel.com \
--cc=seungho1.park@lge.com \
--cc=vishal.l.verma@intel.com \
--cc=willy@infradead.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