From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45926C55178 for ; Sun, 25 Oct 2020 19:09:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A9E3E22365 for ; Sun, 25 Oct 2020 19:09:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="vRYoT5Ly" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9E3E22365 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AB88D6B005D; Sun, 25 Oct 2020 15:09:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A69856B0062; Sun, 25 Oct 2020 15:09:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9573B6B0068; Sun, 25 Oct 2020 15:09:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0025.hostedemail.com [216.40.44.25]) by kanga.kvack.org (Postfix) with ESMTP id 689C06B005D for ; Sun, 25 Oct 2020 15:09:10 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EE29A180AD806 for ; Sun, 25 Oct 2020 19:09:09 +0000 (UTC) X-FDA: 77411385618.15.truck18_4e07f8b2726d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id CE4961814B0C7 for ; Sun, 25 Oct 2020 19:09:09 +0000 (UTC) X-HE-Tag: truck18_4e07f8b2726d X-Filterd-Recvd-Size: 3955 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Sun, 25 Oct 2020 19:09:09 +0000 (UTC) Received: from X1 (nat-ab2241.sltdut.senawave.net [162.218.216.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4C29322260; Sun, 25 Oct 2020 19:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603652948; bh=ddZPlRqimDU7rLmpMhXbvcFt4mtSB1kneJwidpS5uPM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=vRYoT5LyFwn/q/sz2HWHGF270bB/S51nax4AnxJMRmBlrRExFv/DILuauxfgVynMz Ez6EbZ4vSpOe7R99yfmwyCwIOEoI3NOJfh15aFGqKx4Qa0hdRWv7zyfR8ahPjIvO5e alxd0EOirg9UEbC+NLsd4hbhPMbO2C6P5yfYSuus= Date: Sun, 25 Oct 2020 12:09:07 -0700 From: Andrew Morton To: Xianting Tian Cc: , , Jens Axboe Subject: Re: [PATCH] mm: bio_alloc never fails when set GFP_NOIO, GFP_KERNEL Message-Id: <20201025120907.699d178b9d27be114e338680@linux-foundation.org> In-Reply-To: <20201021031128.14100-1-tian.xianting@h3c.com> References: <20201021031128.14100-1-tian.xianting@h3c.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, 21 Oct 2020 11:11:28 +0800 Xianting Tian wrote: > bio_alloc with __GFP_DIRECT_RECLAIM(which is included in GFP_NOIO, > GFP_KERNEL) never fails, as stated in the comments of bio_alloc_bioset. > > So we can remove multiple unneeded null checks of bio_alloc and simplify > the code. > > We have done it in fs/ext4/readpage.c, fs/ext4/page-io.c, fs/direct-io.c, > and so forth. > (cc Jens) > --- a/mm/page_io.c > +++ b/mm/page_io.c > @@ -30,18 +30,20 @@ static struct bio *get_swap_bio(gfp_t gfp_flags, > struct page *page, bio_end_io_t end_io) > { > struct bio *bio; > + struct block_device *bdev; > > + /* > + * bio_alloc will _always_ be able to allocate a bio if > + * __GFP_DIRECT_RECLAIM is set, see comments for bio_alloc_bioset(). > + */ > bio = bio_alloc(gfp_flags, 1); > - if (bio) { > - struct block_device *bdev; > + bio->bi_iter.bi_sector = map_swap_page(page, &bdev); > + bio_set_dev(bio, bdev); > + bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9; > + bio->bi_end_io = end_io; > > - bio->bi_iter.bi_sector = map_swap_page(page, &bdev); > - bio_set_dev(bio, bdev); > - bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9; > - bio->bi_end_io = end_io; > + bio_add_page(bio, page, thp_size(page), 0); > > - bio_add_page(bio, page, thp_size(page), 0); > - } > return bio; > } > > @@ -351,19 +353,13 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, > > ret = 0; > bio = get_swap_bio(GFP_NOIO, page, end_write_func); > - if (bio == NULL) { > - set_page_dirty(page); > - unlock_page(page); > - ret = -ENOMEM; > - goto out; > - } > bio->bi_opf = REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc); > bio_associate_blkg_from_page(bio, page); > count_swpout_vm_event(page); > set_page_writeback(page); > unlock_page(page); > submit_bio(bio); > -out: > + > return ret; > } > > @@ -416,11 +412,6 @@ int swap_readpage(struct page *page, bool synchronous) > > ret = 0; > bio = get_swap_bio(GFP_KERNEL, page, end_swap_bio_read); > - if (bio == NULL) { > - unlock_page(page); > - ret = -ENOMEM; > - goto out; > - } > disk = bio->bi_disk; > /* > * Keep this task valid during swap readpage because the oom killer may I'm reluctant to remove these checks - yours is a fairly subtle discovery and things might change in the future. Intentionally or otherwise!