linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ritesh Harjani <riteshh@linux.ibm.com>
To: Gao Xiang <gaoxiang25@huawei.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] ext4: bio_alloc never fails
Date: Wed, 30 Oct 2019 15:43:10 +0530	[thread overview]
Message-ID: <20191030101311.2175EA4055@d06av23.portsmouth.uk.ibm.com> (raw)
In-Reply-To: <20191030042618.124220-1-gaoxiang25@huawei.com>



On 10/30/19 9:56 AM, Gao Xiang wrote:
> Similar to [1] [2], it seems a trivial cleanup since
> bio_alloc can handle memory allocation as mentioned in
> fs/direct-io.c (also see fs/block_dev.c, fs/buffer.c, ..)
> 

AFAIU, the reason is that, bio_alloc with __GFP_DIRECT_RECLAIM
flags guarantees bio allocation under some given restrictions,
as stated in fs/direct-io.c
So here it is ok to not check for NULL value from bio_alloc.

I think we can update above info too in your commit msg.

> [1] https://lore.kernel.org/r/20191030035518.65477-1-gaoxiang25@huawei.com
> [2] https://lore.kernel.org/r/20190830162812.GA10694@infradead.org
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> ---
>   fs/ext4/page-io.c  | 11 +++--------
>   fs/ext4/readpage.c |  2 --
>   2 files changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
> index 12ceadef32c5..f1f7b6601780 100644
> --- a/fs/ext4/page-io.c
> +++ b/fs/ext4/page-io.c
> @@ -358,14 +358,12 @@ void ext4_io_submit_init(struct ext4_io_submit *io,
>   	io->io_end = NULL;
>   }
> 
> -static int io_submit_init_bio(struct ext4_io_submit *io,
> -			      struct buffer_head *bh)
> +static void io_submit_init_bio(struct ext4_io_submit *io,
> +			       struct buffer_head *bh)
>   {
>   	struct bio *bio;
> 
>   	bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
> -	if (!bio)
> -		return -ENOMEM;
>   	bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
>   	bio_set_dev(bio, bh->b_bdev);
>   	bio->bi_end_io = ext4_end_bio;
> @@ -373,7 +371,6 @@ static int io_submit_init_bio(struct ext4_io_submit *io,
>   	io->io_bio = bio;
>   	io->io_next_block = bh->b_blocknr;
>   	wbc_init_bio(io->io_wbc, bio);
> -	return 0;
>   }
> 
>   static int io_submit_add_bh(struct ext4_io_submit *io,
> @@ -388,9 +385,7 @@ static int io_submit_add_bh(struct ext4_io_submit *io,
>   		ext4_io_submit(io);
>   	}
>   	if (io->io_bio == NULL) {
> -		ret = io_submit_init_bio(io, bh);
> -		if (ret)
> -			return ret;
> +		io_submit_init_bio(io, bh);
>   		io->io_bio->bi_write_hint = inode->i_write_hint;
>   	}
>   	ret = bio_add_page(io->io_bio, page, bh->b_size, bh_offset(bh));


Also we can further simplify it like below. Please check.

diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index f1f7b6601780..a3a2edeb3bbf 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -373,7 +373,7 @@ static void io_submit_init_bio(struct ext4_io_submit 
*io,
  	wbc_init_bio(io->io_wbc, bio);
  }

-static int io_submit_add_bh(struct ext4_io_submit *io,
+static void io_submit_add_bh(struct ext4_io_submit *io,
  			    struct inode *inode,
  			    struct page *page,
  			    struct buffer_head *bh)
@@ -393,7 +393,6 @@ static int io_submit_add_bh(struct ext4_io_submit *io,
  		goto submit_and_retry;
  	wbc_account_cgroup_owner(io->io_wbc, page, bh->b_size);
  	io->io_next_block++;
-	return 0;
  }

  int ext4_bio_write_page(struct ext4_io_submit *io,
@@ -495,30 +494,23 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
  	do {
  		if (!buffer_async_write(bh))
  			continue;
-		ret = io_submit_add_bh(io, inode, bounce_page ?: page, bh);
-		if (ret) {
-			/*
-			 * We only get here on ENOMEM.  Not much else
-			 * we can do but mark the page as dirty, and
-			 * better luck next time.
-			 */
-			break;
-		}
+		io_submit_add_bh(io, inode, bounce_page ?: page, bh);
  		nr_submitted++;
  		clear_buffer_dirty(bh);
  	} while ((bh = bh->b_this_page) != head);

-	/* Error stopped previous loop? Clean up buffers... */
-	if (ret) {
-	out:
-		fscrypt_free_bounce_page(bounce_page);
-		printk_ratelimited(KERN_ERR "%s: ret = %d\n", __func__, ret);
-		redirty_page_for_writepage(wbc, page);
-		do {
-			clear_buffer_async_write(bh);
-			bh = bh->b_this_page;
-		} while (bh != head);
-	}
+	goto unlock;
+
+out:
+	fscrypt_free_bounce_page(bounce_page);
+	printk_ratelimited(KERN_ERR "%s: ret = %d\n", __func__, ret);
+	redirty_page_for_writepage(wbc, page);
+	do {
+		clear_buffer_async_write(bh);
+		bh = bh->b_this_page;
+	} while (bh != head);
+
+unlock:
  	unlock_page(page);
  	/* Nothing submitted - we have to end page writeback */
  	if (!nr_submitted)


-ritesh


  reply	other threads:[~2019-10-30 10:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30  4:26 [PATCH] ext4: bio_alloc never fails Gao Xiang
2019-10-30 10:13 ` Ritesh Harjani [this message]
2019-10-30 10:40   ` Gao Xiang
2019-10-30 15:04   ` Theodore Y. Ts'o
2019-10-30 16:12     ` Gao Xiang
2019-10-31  9:23       ` [PATCH v2] ext4: bio_alloc with __GFP_DIRECT_RECLAIM " Gao Xiang
2019-10-31  9:29         ` Chao Yu
2019-11-15  3:19           ` Theodore Y. Ts'o
2019-11-15  3:24             ` Gao Xiang
2019-10-31  2:01 ` [PATCH] ext4: bio_alloc " Chao Yu
2019-10-31  9:10   ` Gao Xiang

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=20191030101311.2175EA4055@d06av23.portsmouth.uk.ibm.com \
    --to=riteshh@linux.ibm.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=gaoxiang25@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).