Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp643614pxu; Sun, 25 Oct 2020 12:12:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYmMVOW34eeddjSdEHFAyqCuChmT0QeQ85HIhbV3pj82mDJMxLODm4ph0toKuGrIW67AFx X-Received: by 2002:a17:906:f0d8:: with SMTP id dk24mr12301066ejb.492.1603653159236; Sun, 25 Oct 2020 12:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603653159; cv=none; d=google.com; s=arc-20160816; b=gyiegNswF3muhsaWbuOlqbQo10+isToANSffEAowFbQ96nIWJN7oShArJV1uE9baZN VN1QGueZnCZ6o5yjs+P/vSWJdluNpcHFxWCZgDoVETsb0FbXhfu1xOEw56tFEsMinAm/ V+P/LGJ82pDn7sdYRhGudCyxFAajOcHdPmtqCH83BhzgUiBYPbjsoYHR2ddLFYPZIfT9 XgCFQny2bbuEaib4iZ3BIKOYd3NH2QsKj8aSiGCjHGKj9X3WXF6jNl/MEwlyeHjV0j1P Kk/xMDqxdWRBNsj0PkFwjRS/sfsOK7aP8DDkQyarCMSvAazB6eya3TWFkgudlETEr/MA PALg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=/bDeNq1jPsHNPYwxNGQr42o6QaO/P6FeGcsCrheQBig=; b=nbDDZZCh02b2XrMu9+hWo6hxhDg/EtLy/RPhgPjKAWA2pGIBSumM4owgiadarpy6Ch 4wT2Ch7cnbOb9rtRc2J8OYI3AIlb3TSOGw8NM9UaK/uXCf334A84To3VFOGKXDWlX6Dc MZE1jQ6RddKdjracYERYx1AIiVUSRW8Q2a4E+xUIBuKfCbi/B4SY3cLUEe++/qkuAthF 5Uc7aLadbc/nMRWtVYEJXBJoj7mklbxtuWqvhJYVrZC3OvEo205Xj1lDkvtvQBPVaYa6 P86zrXN9gXxAHcRNnyYtWnuSQD8fmLCQyOnaxPx/ITklW0txg3LBfW3d4nkpfkQ3aNTe Ir6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vRYoT5Ly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k26si7336836eds.235.2020.10.25.12.12.17; Sun, 25 Oct 2020 12:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vRYoT5Ly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1418448AbgJYTJJ (ORCPT + 99 others); Sun, 25 Oct 2020 15:09:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:54644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1418418AbgJYTJJ (ORCPT ); Sun, 25 Oct 2020 15:09:09 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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!