Message ID | 20221026013611.2900-1-zeming@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp152wru; Tue, 25 Oct 2022 18:46:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63iOhWLXfaC5Ptwr8Hs8cIc8/pUqW3sodawGHVPgKUgezaj2Sw8W6UOpQWXcncaIRoiAOA X-Received: by 2002:a17:907:6d9a:b0:7a0:d2d9:31cc with SMTP id sb26-20020a1709076d9a00b007a0d2d931ccmr18294953ejc.747.1666748770406; Tue, 25 Oct 2022 18:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666748770; cv=none; d=google.com; s=arc-20160816; b=Op93OmeBS6rJQelgum9wZboNkICCCmVXx2cUxAfqvsEK39TRYD2ir8Q4RSyEiPQ/0f mcxF+oLdQmNFVU32LZfgusgwwkIeMVy3mNKSuJzNQwi1esHQ5HHldZQbbDQJ2vPylz2S q8Y6hl5jqT15W3KVxQ3LGgmM360842mrTgzksahfxeAM5G4sG5aFHJBCZb2rGR3nQbZL wm3w33AMGVIBWawz4Jb4/QQ91Jh4sJTBYwHZG7c3/LR4sULNp0eT/wdP5nYGA4O/RuUa FfSsopOUdo3todmhOGiDLfDZb3RtqusBSjItqcA3ZodeaJmojwp/TxHwqp1lLeRE0bYf IY9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=CmnGB8Ef9xIBgvOIYcA1q+YLYrkt8iiGUsnzYQspaWM=; b=uMbspibUWaVCHXKPn4AfW7v4LILuYV/o2vIi7C9jXuMEa3fqCnePWlRvTq49PcwigS e9Am6M9/09zsquDLMjME6KmYSvoos9i0aB9Aov8JMUGAlPX2c1WkDbBWamn9uRQcPA5E JPfNxdBwDBvTLngiPpjLH0rm1kobMU7KnXtlJS9zBjuenUosQ+xGxstvhpTNiGU5u5vD Peo8skMAGpfX8YkzqbbrgyVyTie6/j9gFS9EJslnPSXKU5CrNx2W+w+jlfBTTKCpTXLd sYtnQgutaq4K5Y2y+/Yi/T+0WWuYKqpCELzNibxk91bu1qXiZlYWn1fGEC6nlPRuk/mf 7Xpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp41-20020a1709071b2900b007acdb4016e0si2470314ejc.224.2022.10.25.18.45.44; Tue, 25 Oct 2022 18:46:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232380AbiJZBgW (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Tue, 25 Oct 2022 21:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbiJZBgT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Oct 2022 21:36:19 -0400 Received: from mail.nfschina.com (unknown [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F0D136A514; Tue, 25 Oct 2022 18:36:18 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id AD1D31E80C9B; Wed, 26 Oct 2022 09:34:52 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id No9tDtmXi6nw; Wed, 26 Oct 2022 09:34:50 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id CD88C1E80C8E; Wed, 26 Oct 2022 09:34:49 +0800 (CST) From: Li zeming <zeming@nfschina.com> To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Li zeming <zeming@nfschina.com> Subject: [PATCH v3] btrfs: volumes: Increase bioc pointer check Date: Wed, 26 Oct 2022 09:36:11 +0800 Message-Id: <20221026013611.2900-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747712758810629800?= X-GMAIL-MSGID: =?utf-8?q?1747712758810629800?= |
Series |
[v3] btrfs: volumes: Increase bioc pointer check
|
|
Commit Message
Li zeming
Oct. 26, 2022, 1:36 a.m. UTC
The __GFP_NOFAIL flag will cause memory to be allocated an infinite
number of times until the allocation is successful, but it is best to
use it only for very necessary code, and try not to use it.
The alloc_btrfs_io_context function looks a little closer to normal
(excuse my analysis), but I think we can remove __GFP_NOFAIL from it and
add a bioc pointer allocation check that returns NULL if the allocation
fails.
Signed-off-by: Li zeming <zeming@nfschina.com>
---
v2: Add annotation vocabulary modify, remove __GFP_NOFAIL flag.
v3: Modifying the Description.
fs/btrfs/volumes.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On 2022/10/26 09:36, Li zeming wrote: > The __GFP_NOFAIL flag will cause memory to be allocated an infinite > number of times until the allocation is successful, but it is best to > use it only for very necessary code, and try not to use it. > > The alloc_btrfs_io_context function looks a little closer to normal > (excuse my analysis), but I think we can remove __GFP_NOFAIL from it and > add a bioc pointer allocation check that returns NULL if the allocation > fails. > > Signed-off-by: Li zeming <zeming@nfschina.com> > --- > v2: Add annotation vocabulary modify, remove __GFP_NOFAIL flag. > v3: Modifying the Description. > > fs/btrfs/volumes.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 064ab2a79c80..b8d901f58995 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -5891,7 +5891,9 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ > * and the stripes. > */ > sizeof(u64) * (total_stripes), > - GFP_NOFS|__GFP_NOFAIL); > + GFP_NOFS); > + if (!bioc) > + return NULL; > > atomic_set(&bioc->error, 0); > refcount_set(&bioc->refs, 1); > @@ -6071,7 +6073,7 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info, > * array of stripes. > * For READ, it also needs to be supported using the same mirror number. > * > - * If the requested block is not left of the left cursor, EIO is returned. This > + * If the requested block is not left of the left cursor, EIO should be returned. This Is there any need for this change? I don't think your patch has even touched the call chain of get_extra_mirror_from_replace(). Thanks, Qu > * can happen because btrfs_num_copies() returns one more in the dev-replace > * case. > */
On Wed, Oct 26, 2022 at 02:42:51PM +0800, Qu Wenruo wrote: > On 2022/10/26 09:36, Li zeming wrote: > > The __GFP_NOFAIL flag will cause memory to be allocated an infinite > > number of times until the allocation is successful, but it is best to > > use it only for very necessary code, and try not to use it. > > > > The alloc_btrfs_io_context function looks a little closer to normal > > (excuse my analysis), but I think we can remove __GFP_NOFAIL from it and > > add a bioc pointer allocation check that returns NULL if the allocation > > fails. > > > > Signed-off-by: Li zeming <zeming@nfschina.com> > > --- > > v2: Add annotation vocabulary modify, remove __GFP_NOFAIL flag. > > v3: Modifying the Description. > > > > fs/btrfs/volumes.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > > index 064ab2a79c80..b8d901f58995 100644 > > --- a/fs/btrfs/volumes.c > > +++ b/fs/btrfs/volumes.c > > @@ -5891,7 +5891,9 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ > > * and the stripes. > > */ > > sizeof(u64) * (total_stripes), > > - GFP_NOFS|__GFP_NOFAIL); > > + GFP_NOFS); > > + if (!bioc) > > + return NULL; > > > > atomic_set(&bioc->error, 0); > > refcount_set(&bioc->refs, 1); > > @@ -6071,7 +6073,7 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info, > > * array of stripes. > > * For READ, it also needs to be supported using the same mirror number. > > * > > - * If the requested block is not left of the left cursor, EIO is returned. This > > + * If the requested block is not left of the left cursor, EIO should be returned. This > > Is there any need for this change? > > I don't think your patch has even touched the call chain of > get_extra_mirror_from_replace(). That's maybe an accidental change, not relevant to the NOFAIL removal.
On Wed, Oct 26, 2022 at 09:36:11AM +0800, Li zeming wrote: > The __GFP_NOFAIL flag will cause memory to be allocated an infinite > number of times until the allocation is successful, but it is best to > use it only for very necessary code, and try not to use it. > > The alloc_btrfs_io_context function looks a little closer to normal > (excuse my analysis), but I think we can remove __GFP_NOFAIL from it and > add a bioc pointer allocation check that returns NULL if the allocation > fails. > > Signed-off-by: Li zeming <zeming@nfschina.com> I've reworded the subject and changelog and patch is now in misc-next, thanks.
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 064ab2a79c80..b8d901f58995 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5891,7 +5891,9 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ * and the stripes. */ sizeof(u64) * (total_stripes), - GFP_NOFS|__GFP_NOFAIL); + GFP_NOFS); + if (!bioc) + return NULL; atomic_set(&bioc->error, 0); refcount_set(&bioc->refs, 1); @@ -6071,7 +6073,7 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info, * array of stripes. * For READ, it also needs to be supported using the same mirror number. * - * If the requested block is not left of the left cursor, EIO is returned. This + * If the requested block is not left of the left cursor, EIO should be returned. This * can happen because btrfs_num_copies() returns one more in the dev-replace * case. */