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=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 D5CEFC388F9 for ; Fri, 23 Oct 2020 16:40:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2B84F22210 for ; Fri, 23 Oct 2020 16:40:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B84F22210 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=h3c.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3C9AA6B006C; Fri, 23 Oct 2020 12:40:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 379E26B0070; Fri, 23 Oct 2020 12:40:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26A356B0071; Fri, 23 Oct 2020 12:40:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id E9F9C6B006C for ; Fri, 23 Oct 2020 12:40:40 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 405F1362E for ; Fri, 23 Oct 2020 16:40:40 +0000 (UTC) X-FDA: 77403753840.08.pen11_0e07da02725b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 0C6D51819E793 for ; Fri, 23 Oct 2020 16:40:40 +0000 (UTC) X-HE-Tag: pen11_0e07da02725b X-Filterd-Recvd-Size: 4647 Received: from h3cspam01-ex.h3c.com (smtp.h3c.com [60.191.123.56]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Fri, 23 Oct 2020 16:40:35 +0000 (UTC) Received: from DAG2EX07-IDC.srv.huawei-3com.com ([10.8.0.70]) by h3cspam01-ex.h3c.com with ESMTPS id 09NGdvON035320 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 24 Oct 2020 00:39:57 +0800 (GMT-8) (envelope-from tian.xianting@h3c.com) Received: from DAG2EX03-BASE.srv.huawei-3com.com (10.8.0.66) by DAG2EX07-IDC.srv.huawei-3com.com (10.8.0.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Sat, 24 Oct 2020 00:40:02 +0800 Received: from DAG2EX03-BASE.srv.huawei-3com.com ([fe80::5d18:e01c:bbbd:c074]) by DAG2EX03-BASE.srv.huawei-3com.com ([fe80::5d18:e01c:bbbd:c074%7]) with mapi id 15.01.2106.002; Sat, 24 Oct 2020 00:40:02 +0800 From: Tianxianting To: "akpm@linux-foundation.org" CC: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] mm: bio_alloc never fails when set GFP_NOIO, GFP_KERNEL Thread-Topic: [PATCH] mm: bio_alloc never fails when set GFP_NOIO, GFP_KERNEL Thread-Index: AQHWp1lEOcaxBjwhyUKPdENxUdfPnqmlZyxg Date: Fri, 23 Oct 2020 16:40:01 +0000 Message-ID: <02af899a94624d85a19b6510060c8b06@h3c.com> References: <20201021031128.14100-1-tian.xianting@h3c.com> In-Reply-To: <20201021031128.14100-1-tian.xianting@h3c.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.99.141.128] x-sender-location: DAG2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DNSRBL: X-MAIL:h3cspam01-ex.h3c.com 09NGdvON035320 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: Hi Andrew Could I get your comments for this patch? Thanks in advance. -----Original Message----- From: tianxianting (RD)=20 Sent: Wednesday, October 21, 2020 11:11 AM To: akpm@linux-foundation.org Cc: linux-mm@kvack.org; linux-kernel@vger.kernel.org; tianxianting (RD) Subject: [PATCH] mm: bio_alloc never fails when set GFP_NOIO, GFP_KERNEL 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 th= e code. We have done it in fs/ext4/readpage.c, fs/ext4/page-io.c, fs/direct-io.c, a= nd so forth. Signed-off-by: Xianting Tian --- mm/page_io.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index e485a6e8a..9215bb356 100644 --- 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; =20 + /* + * bio_alloc will _always_ be able to allocate a bio if + * __GFP_DIRECT_RECLAIM is set, see comments for bio_alloc_bioset(). + */ bio =3D bio_alloc(gfp_flags, 1); - if (bio) { - struct block_device *bdev; + bio->bi_iter.bi_sector =3D map_swap_page(page, &bdev); + bio_set_dev(bio, bdev); + bio->bi_iter.bi_sector <<=3D PAGE_SHIFT - 9; + bio->bi_end_io =3D end_io; =20 - bio->bi_iter.bi_sector =3D map_swap_page(page, &bdev); - bio_set_dev(bio, bdev); - bio->bi_iter.bi_sector <<=3D PAGE_SHIFT - 9; - bio->bi_end_io =3D end_io; + bio_add_page(bio, page, thp_size(page), 0); =20 - bio_add_page(bio, page, thp_size(page), 0); - } return bio; } =20 @@ -351,19 +353,13 @@ int __swap_writepage(struct page *page, struct writeb= ack_control *wbc, =20 ret =3D 0; bio =3D get_swap_bio(GFP_NOIO, page, end_write_func); - if (bio =3D=3D NULL) { - set_page_dirty(page); - unlock_page(page); - ret =3D -ENOMEM; - goto out; - } bio->bi_opf =3D 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; } =20 @@ -416,11 +412,6 @@ int swap_readpage(struct page *page, bool synchronous) =20 ret =3D 0; bio =3D get_swap_bio(GFP_KERNEL, page, end_swap_bio_read); - if (bio =3D=3D NULL) { - unlock_page(page); - ret =3D -ENOMEM; - goto out; - } disk =3D bio->bi_disk; /* * Keep this task valid during swap readpage because the oom killer may -- 2.17.1