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=-5.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 3DA8AC55179 for ; Sun, 25 Oct 2020 19:24:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A42EE2236F for ; Sun, 25 Oct 2020 19:24:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="hmjLI5PQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A42EE2236F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0F3636B0062; Sun, 25 Oct 2020 15:24:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07EE56B0068; Sun, 25 Oct 2020 15:24:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E87106B006C; Sun, 25 Oct 2020 15:24:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id B7AF16B0062 for ; Sun, 25 Oct 2020 15:24:11 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5568F3628 for ; Sun, 25 Oct 2020 19:24:11 +0000 (UTC) X-FDA: 77411423502.27.edge13_030cb722726d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 3AB473D67B for ; Sun, 25 Oct 2020 19:24:11 +0000 (UTC) X-HE-Tag: edge13_030cb722726d X-Filterd-Recvd-Size: 6139 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Sun, 25 Oct 2020 19:24:10 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id r3so3587898plo.1 for ; Sun, 25 Oct 2020 12:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=v0qMtD14nA7HrLM/MdCWb6JdQx3iF+CcKyq2qfja9yM=; b=hmjLI5PQcBXCIPYFwrcxxUyn+bgIfTT5+1VUIwMieE8zkTZfem26vmyWR4YX1M/giX dvWay5fp3eZthz10ozJ1y0/AbyD5Jd8BLlfTpCc/qEPANy1KAMyKvUKIycQppnGXJKrR aU57HbNxDrt/SgCcXslXpU7zkXvMA5m0kLXVaKgK2b9EFSYj67pWwMfruUwnqloyDGkq J2y8p7IASijC+JTKB+QAJPZFFtvrZQ3XXnkBnkiKnuAnnb+H/0D7ExliNgQ4iLNdeFBk 3eorHoS3ooNfCzAZ8JGwuaMAiTNqwc4taevCMMUouogboNGIyRcau93d7MMGjqk9pmuX fWIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=v0qMtD14nA7HrLM/MdCWb6JdQx3iF+CcKyq2qfja9yM=; b=lJK+TiJsvf9hvUqyWnQh0sj5Eq4MsONiaNi3cXwQU+WZ4iFUKvs0psv5meHFW0iAP5 W5YGLOu7OvvvX4Fb65Tysn3iTZPLJWneS6NFtzVLaLdPeephh04g5T/Gzk1WjFFNMXt0 ZA7kKqh4NU37FEuU/J3Cu+jRVfX9TDzomz7WQNS8C9yh14OVIVr/IqKI2yUNk9wUOBss iDC0ZJA3h8jpQhRlBxG6vCMJ5HPhrSTOdRLpvQs9iSokhPkpRyRxa/h5s8QwfX5O0vHU Sd+M1uKmTELB3JboAb0iSFT7CXOCkP81AjbkCwubAutd/h/kbjOEl4Fe2PsWR3SxQWq2 LFIg== X-Gm-Message-State: AOAM530+YUm/VkwcOg1TuSGuzgBvSjcIyHIIYvrL9sbcIN+zmFO1znGo cJsbQwGQcKtnzUHEA42gkXF6oA== X-Google-Smtp-Source: ABdhPJzzmw93U0N+QGMOqFiV/h0ffhblCS3IHUxDYgjlyEE9myUO6NMBDbnxhpz10IVfYfomSrgMzA== X-Received: by 2002:a17:90a:ab86:: with SMTP id n6mr15996092pjq.82.1603653849636; Sun, 25 Oct 2020 12:24:09 -0700 (PDT) Received: from [192.168.1.134] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id x2sm9718314pfc.133.2020.10.25.12.24.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 25 Oct 2020 12:24:08 -0700 (PDT) Subject: Re: [PATCH] mm: bio_alloc never fails when set GFP_NOIO, GFP_KERNEL To: Andrew Morton , Xianting Tian Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20201021031128.14100-1-tian.xianting@h3c.com> <20201025120907.699d178b9d27be114e338680@linux-foundation.org> From: Jens Axboe Message-ID: <53ffff64-da56-7911-ff95-9201476de9e4@kernel.dk> Date: Sun, 25 Oct 2020 13:24:07 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201025120907.699d178b9d27be114e338680@linux-foundation.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US 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 10/25/20 1:09 PM, Andrew Morton wrote: > 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! On the block/bio side, it all boils down to the mempool backing of the bio allocations. If __GFP_DIRECT_RECLAIM is set for that, then we'll always wait on allocations for a bio. That is intentional, by design, to guarantee forward progress. It used to be __GFP_WAIT based, but I guess that changed at some point... -- Jens Axboe