Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp695757ybx; Wed, 30 Oct 2019 03:38:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWmjXXiVpFXg4m99dzKr3puOrpAF6ROIFQ1FrAiFxt+O12/cIgjHYF2C68NUrdHtPgsVhN X-Received: by 2002:a17:906:c08:: with SMTP id s8mr8243173ejf.73.1572431920143; Wed, 30 Oct 2019 03:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572431920; cv=none; d=google.com; s=arc-20160816; b=WBNsliTyn2yOz31fXJNWJKNtZSPnRsu1Nlt6hGaIkg3afaBnFRoH7UTAx6ApmBLP2g bO49r36EPyrBeVotchoyGuiWweBSX+xky4pK6RjiztgQsiEuv2DyGj2MVQjeWdeowI1+ H/2EIMgDcorXF02EEijZYqmFmUmYH0FGvhOaYjiXyK/0gsYO7VD+Hm3ZyfrhbmH9Z6oB rSPxaa/1uuZrlp5q+2NuMkxoqP6qjxiERZ8/RrJigyG4mYOqWBYx+QwLs1WRJxfKMn7q MwDpGiE2NHgLzT2jyEr7yxyaS47aDG6mb3VTUMixQmz+Tf4e0UL+75WLyYeT6KMcLGej zwAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=lW8YTMz3IUNCGgAyajQprLfJLCGG70czInEs2CcFENk=; b=B2xPmr9gefzKrtk4XIGXkKGU6XzhMb0dKsv7qWIKYjZOHSnFzxprO46ZgHnXL0ZC4G T+sDKltOf2awolNnl71nRpfaZKRLTxBWyRHUw9Gi3iSz5yL/0pGNbBUlD0QGp/P3WFNq Tb9UdTalNVF9BVvbWoQJaOWZXIPGtEPYfZTT5wYaTFuWCS1AiCyplgxP/8Nhpw1FRErL ZzbftR04BBNZLaOD8eHAEbzHLWqmnmjJIrdp4vttWIOopGltHyAfv65eoHLcWDiToW4w tX4tqDulunI2alDfJqVQgjJqBPVSfNxbrq/+wB3KWxJ+uoMdAAYip9iPYtznwOPKr2oN TLTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o28si1084722edc.353.2019.10.30.03.38.10; Wed, 30 Oct 2019 03:38:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726082AbfJ3KiH (ORCPT + 99 others); Wed, 30 Oct 2019 06:38:07 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2501 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726046AbfJ3KiH (ORCPT ); Wed, 30 Oct 2019 06:38:07 -0400 Received: from DGGEMM406-HUB.china.huawei.com (unknown [172.30.72.55]) by Forcepoint Email with ESMTP id 180FDFE20842B11A1B1F; Wed, 30 Oct 2019 18:38:05 +0800 (CST) Received: from dggeme762-chm.china.huawei.com (10.3.19.108) by DGGEMM406-HUB.china.huawei.com (10.3.20.214) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 30 Oct 2019 18:38:04 +0800 Received: from architecture4 (10.140.130.215) by dggeme762-chm.china.huawei.com (10.3.19.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 30 Oct 2019 18:38:04 +0800 Date: Wed, 30 Oct 2019 18:40:49 +0800 From: Gao Xiang To: Ritesh Harjani CC: Theodore Ts'o , Andreas Dilger , , , Subject: Re: [PATCH] ext4: bio_alloc never fails Message-ID: <20191030104049.GA170703@architecture4> References: <20191030042618.124220-1-gaoxiang25@huawei.com> <20191030101311.2175EA4055@d06av23.portsmouth.uk.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20191030101311.2175EA4055@d06av23.portsmouth.uk.ibm.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [10.140.130.215] X-ClientProxiedBy: dggeme709-chm.china.huawei.com (10.1.199.105) To dggeme762-chm.china.huawei.com (10.3.19.108) X-CFilter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Hi Ritech, On Wed, Oct 30, 2019 at 03:43:10PM +0530, Ritesh Harjani wrote: > > > 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. Ok, I will update commit msg as you suggested. > > > [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 > > --- > > 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. Got it, let me update the patch later. :-) Thanks for your suggestion. I will wait for a while and see if other opinions raise up... Thanks, Gao Xiang > > 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 >