linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <tom.leiming@gmail.com>
To: Jens Axboe <axboe@fb.com>, linux-kernel@vger.kernel.org
Cc: linux-block@vger.kernel.org,
	Christoph Hellwig <hch@infradead.org>,
	Ming Lei <tom.leiming@gmail.com>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH v1 33/54] block: deal with dirtying pages for multipage bvec
Date: Wed, 28 Dec 2016 00:04:42 +0800	[thread overview]
Message-ID: <1482854706-14128-2-git-send-email-tom.leiming@gmail.com> (raw)
In-Reply-To: <1482854706-14128-1-git-send-email-tom.leiming@gmail.com>

In bio_check_pages_dirty(), bvec->bv_page is used as flag
for marking if the page has been dirtied & released, and if
no, it will be dirtied in deferred workqueue.

With multipage bvec, we can't do that any more, so change
the logic into checking all pages in one mp bvec, and only
release all these pages if all are dirtied, otherwise dirty
them all in deferred wrokqueue.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 block/bio.c | 45 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 37 insertions(+), 8 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index a76ed8a780de..e65de53acb9f 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1655,8 +1655,9 @@ void bio_set_pages_dirty(struct bio *bio)
 {
 	struct bio_vec *bvec;
 	int i;
+	struct bvec_iter_all bia;
 
-	bio_for_each_segment_all(bvec, bio, i) {
+	bio_for_each_segment_all_sp(bvec, bio, i, bia) {
 		struct page *page = bvec->bv_page;
 
 		if (page && !PageCompound(page))
@@ -1664,16 +1665,26 @@ void bio_set_pages_dirty(struct bio *bio)
 	}
 }
 
+static inline void release_mp_bvec_pages(struct bio_vec *bvec)
+{
+	struct bio_vec bv;
+	struct bvec_iter iter;
+
+	bvec_for_each_sp_bvec(bv, bvec, iter)
+		put_page(bv.bv_page);
+}
+
 static void bio_release_pages(struct bio *bio)
 {
 	struct bio_vec *bvec;
 	int i;
 
-	bio_for_each_segment_all(bvec, bio, i) {
+	/* iterate each mp bvec */
+	bio_for_each_segment_all_mp(bvec, bio, i) {
 		struct page *page = bvec->bv_page;
 
 		if (page)
-			put_page(page);
+			release_mp_bvec_pages(bvec);
 	}
 }
 
@@ -1717,20 +1728,38 @@ static void bio_dirty_fn(struct work_struct *work)
 	}
 }
 
+static inline void check_mp_bvec_pages(struct bio_vec *bvec,
+		int *nr_dirty, int *nr_pages)
+{
+	struct bio_vec bv;
+	struct bvec_iter iter;
+
+	bvec_for_each_sp_bvec(bv, bvec, iter) {
+		struct page *page = bv.bv_page;
+
+		if (PageDirty(page) || PageCompound(page))
+			(*nr_dirty)++;
+		(*nr_pages)++;
+	}
+}
+
 void bio_check_pages_dirty(struct bio *bio)
 {
 	struct bio_vec *bvec;
 	int nr_clean_pages = 0;
 	int i;
 
-	bio_for_each_segment_all(bvec, bio, i) {
-		struct page *page = bvec->bv_page;
+	bio_for_each_segment_all_mp(bvec, bio, i) {
+		int nr_dirty = 0, nr_pages = 0;
+
+		check_mp_bvec_pages(bvec, &nr_dirty, &nr_pages);
 
-		if (PageDirty(page) || PageCompound(page)) {
-			put_page(page);
+		/* release all pages in the mp bvec if all are dirtied */
+		if (nr_dirty == nr_pages) {
+			release_mp_bvec_pages(bvec);
 			bvec->bv_page = NULL;
 		} else {
-			nr_clean_pages++;
+			nr_clean_pages += nr_pages;
 		}
 	}
 
-- 
2.7.4

  reply	other threads:[~2016-12-27 16:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27 16:04 [PATCH v1 32/54] block: introduce bvec_get_last_sp() Ming Lei
2016-12-27 16:04 ` Ming Lei [this message]
2016-12-27 16:04 ` [PATCH v1 34/54] block: convert to singe/multi page version of bio_for_each_segment_all() Ming Lei
2016-12-27 16:04 ` [PATCH v1 35/54] bcache: convert to bio_for_each_segment_all_sp() Ming Lei
2016-12-27 16:04 ` [PATCH v1 36/54] dm-crypt: don't clear bvec->bv_page in crypt_free_buffer_pages() Ming Lei
2016-12-27 16:04 ` [PATCH v1 37/54] dm-crypt: convert to bio_for_each_segment_all_sp() Ming Lei
2016-12-27 16:04 ` [PATCH v1 38/54] md/raid1.c: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 39/54] fs/mpage: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 40/54] fs/direct-io: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 41/54] ext4: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 42/54] xfs: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 43/54] gfs2: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 44/54] f2fs: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 45/54] exofs: " Ming Lei
2017-01-03 14:58   ` Boaz Harrosh
2016-12-27 16:04 ` [PATCH v1 46/54] fs: crypto: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 47/54] fs/btrfs: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 48/54] fs/block_dev.c: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 49/54] fs/iomap.c: " Ming Lei
2016-12-27 16:04 ` [PATCH v1 50/54] fs/buffer.c: use bvec iterator to truncate the bio Ming Lei
2016-12-27 16:05 ` [PATCH v1 51/54] btrfs: avoid access to .bi_vcnt directly Ming Lei
2016-12-27 16:05 ` [PATCH v1 52/54] btrfs: use bvec_get_last_sp to get the last singlepage bvec Ming Lei
2016-12-27 16:05 ` [PATCH v1 53/54] btrfs: comment on direct access bvec table Ming Lei
2016-12-27 16:05 ` [PATCH v1 54/54] block: enable multipage bvecs Ming Lei

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=1482854706-14128-2-git-send-email-tom.leiming@gmail.com \
    --to=tom.leiming@gmail.com \
    --cc=axboe@fb.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@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).