Message ID | 20230404084701.2791683-1-ryasuoka@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2872690vqo; Tue, 4 Apr 2023 01:51:59 -0700 (PDT) X-Google-Smtp-Source: AKy350Y0wKBBNbqHqasSGHf2mFD40eVGZTHkQEPQMi7qV7s+JOTUYLh3B4USSTvwBbfG5xKobWz9 X-Received: by 2002:aa7:d50e:0:b0:4fd:2b05:1722 with SMTP id y14-20020aa7d50e000000b004fd2b051722mr1684067edq.7.1680598319519; Tue, 04 Apr 2023 01:51:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680598319; cv=none; d=google.com; s=arc-20160816; b=Yvq+lWdWOic5pRDNTSQ5/0EHirepA3PcgDaXXjACJ9sTw/8aJIuYwSSbnTzh1buSR8 4GNN1VqKeUyC8+DBwROSvdT3zxjXQAf5fr1bVqVKvL2jHsim0n4Rv0vMfI252MjMy9kO OQ3nHf53uA06g3wqrqvFBivKcYTVbBo6sYlEXBszF07hHtNtFCYH5rGIauTiNASrDrNb pxOATz1/dyPBJbHhlM500DhqyyP2BaxwuR3l0qAlam5lpqsxQIElEHDT80gHEZuAfPfK BAdapZ5Cnd9+iNPrv/AkKs39eV5u9Asx4p6U1dBGXhUceo/esFBCsFDeBX/FpRYMGCS3 Zc3g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=St04fATWGfIT10g6i4L0siP3WzQxgjh0uTI5uZltYvQ=; b=BHQD53AY2T+Z3nhhJEg5s69p55Wkq5BZNuhXHsTw9Zl3bVjD94yJNjZl9Q8JnOHu4Q fHN96ZXWY64NpQln5QbpOFcD6b1/Gce/dYpxkCaMhiz+nKDkitWIu7zXz/oH4Ai2qZUQ YJWPXmdZL5Kko+JdbNDWj1D2I50wyAEBzrUbXVaSqrpTo9wQfxDMXBuVFb/ybXAx0iUY w+dfinYz4KDMT+LIX5cl37NmL8YtwWVqpN8S6mJr9EeqgudPpR08wwyIvXH2yO1D3EkK Xxvufc9hbSlBGXFPv2yZEapVtGschAIpeSkxjnU1ijcbB3NzksdyW+Yz9oz6y5mGnidS /jBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cU7zg75e; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k22-20020aa7c396000000b005024a94026dsi9575930edq.338.2023.04.04.01.51.35; Tue, 04 Apr 2023 01:51:59 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cU7zg75e; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233594AbjDDIsF (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Tue, 4 Apr 2023 04:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234076AbjDDIsD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 4 Apr 2023 04:48:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3DF2197 for <linux-kernel@vger.kernel.org>; Tue, 4 Apr 2023 01:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680598035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=St04fATWGfIT10g6i4L0siP3WzQxgjh0uTI5uZltYvQ=; b=cU7zg75eMs763VHrY2sozQOKDBK8tDlpeUZ2X3nNmjv56Q4d9dv/ip83iUNDAVJgBzsVKY 9x3THEtFPGyc733s92DrSgIC3BwPeB4ioCtlci1JK3DGIqD0PRGsQIMT02vXQ67/IkawSh AXE7k9yWKUe51qztDlKVGMaj2kKYpbc= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-uyj8PsRUP9eMbqVDov0oSg-1; Tue, 04 Apr 2023 04:47:14 -0400 X-MC-Unique: uyj8PsRUP9eMbqVDov0oSg-1 Received: by mail-pf1-f199.google.com with SMTP id o4-20020a056a00214400b00627ddde00f4so14451551pfk.4 for <linux-kernel@vger.kernel.org>; Tue, 04 Apr 2023 01:47:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680598033; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=St04fATWGfIT10g6i4L0siP3WzQxgjh0uTI5uZltYvQ=; b=zKHoUaL/K3/GT1E19HvyQqYfrQWdML4kKi+7YuJxagHhOGRZ1fziwqoTIRE6EoqKhj H/svpS1KqN5rt4x+3ykEXH3dHLTqlZNfsps6xB92/pR2dDq7iqVyXlU605ca3TGQBQl/ LggfmP9vKo7eoGk+7vxW5KQ4qcnuPc3tzWvoAmPIoNe4H8cmy4x6SxpWHWMh3g3QhxWJ l9qwX4gVdzeUckAMTmb0D7vinHzRTHxaaqWOPmE/FPNiPXRSGB8v6cOAVk+R7TMTpkS1 hT3ub53aFcjxIFh1sjkwtQpajmD34+mGEBlNC+10JKZLZIW6l9ancI0KuL13sIXd+MSk IMyQ== X-Gm-Message-State: AAQBX9eSac8DDQW7BH+zjS2my5EXDg2cRUbptKDCNsin3OpSV0VCoL1O mqwUdZYv7j4Kk/8AievJlQyzrg3aUg6yG5DpKh+T1YkgcSexK26m2faGQ3aGD9EjIwmq2lGCsiU /8xafJX8qrudHd9v/6CMaSM1j X-Received: by 2002:a17:90b:3b48:b0:23d:29c7:916f with SMTP id ot8-20020a17090b3b4800b0023d29c7916fmr1944931pjb.32.1680598033474; Tue, 04 Apr 2023 01:47:13 -0700 (PDT) X-Received: by 2002:a17:90b:3b48:b0:23d:29c7:916f with SMTP id ot8-20020a17090b3b4800b0023d29c7916fmr1944909pjb.32.1680598033010; Tue, 04 Apr 2023 01:47:13 -0700 (PDT) Received: from zeus.flets-east.jp ([240b:10:83a2:bd00:6e35:f2f5:2e21:ae3a]) by smtp.gmail.com with ESMTPSA id e5-20020a17090ada0500b00234e6d2de3dsm7352937pjv.11.2023.04.04.01.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 01:47:12 -0700 (PDT) From: Ryosuke Yasuoka <ryasuoka@redhat.com> To: djwong@kernel.org Cc: Ryosuke Yasuoka <ryasuoka@redhat.com>, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] xfs: Use for_each_perag() to iterate all available AGs Date: Tue, 4 Apr 2023 17:47:01 +0900 Message-Id: <20230404084701.2791683-1-ryasuoka@redhat.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1762235063084070352?= X-GMAIL-MSGID: =?utf-8?q?1762235063084070352?= |
Series |
xfs: Use for_each_perag() to iterate all available AGs
|
|
Commit Message
Ryosuke Yasuoka
April 4, 2023, 8:47 a.m. UTC
for_each_perag_wrap() doesn't expect 0 as 2nd arg.
To iterate all the available AGs, just use for_each_perag() instead.
Signed-off-by: Ryosuke Yasuoka <ryasuoka@redhat.com>
---
fs/xfs/xfs_filestream.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 4/4/23 3:47 AM, Ryosuke Yasuoka wrote: > for_each_perag_wrap() doesn't expect 0 as 2nd arg. > To iterate all the available AGs, just use for_each_perag() instead. Can you explain what goes wrong if it is zero? Is there a test for this? If it's a general problem, what if the other 2 callers pass in the variable start_agno with a value of 0? (I may well be missing something obvious as those macros are a bit dense) Thanks, -Eric > Signed-off-by: Ryosuke Yasuoka <ryasuoka@redhat.com> > --- > fs/xfs/xfs_filestream.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c > index 22c13933c8f8..48f43c340c58 100644 > --- a/fs/xfs/xfs_filestream.c > +++ b/fs/xfs/xfs_filestream.c > @@ -151,7 +151,7 @@ xfs_filestream_pick_ag( > * grab. > */ > if (!max_pag) { > - for_each_perag_wrap(args->mp, 0, start_agno, args->pag) > + for_each_perag(args->mp, start_agno, args->pag) > break; > atomic_inc(&args->pag->pagf_fstrms); > *longest = 0;
On Tue, Apr 04, 2023 at 05:47:01PM +0900, Ryosuke Yasuoka wrote: > for_each_perag_wrap() doesn't expect 0 as 2nd arg. > To iterate all the available AGs, just use for_each_perag() instead. Thanks, Ryosuke-san. IIUC, this is a fix for the recent sysbot reported filestreams oops regression? Can you include the context of the failure it reported (i.e. the trace from the oops), and the 'reported-by' tag for the syzbot report? It should probably also include a 'Fixes: bd4f5d09cc93 ("xfs: refactor the filestreams allocator pick functions")' tag as well. > Signed-off-by: Ryosuke Yasuoka <ryasuoka@redhat.com> > --- > fs/xfs/xfs_filestream.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c > index 22c13933c8f8..48f43c340c58 100644 > --- a/fs/xfs/xfs_filestream.c > +++ b/fs/xfs/xfs_filestream.c > @@ -151,7 +151,7 @@ xfs_filestream_pick_ag( > * grab. > */ > if (!max_pag) { > - for_each_perag_wrap(args->mp, 0, start_agno, args->pag) > + for_each_perag(args->mp, start_agno, args->pag) > break; While this will definitely avoid the oops, I don't think it is quite right. If we want to iterate all AGs, then we should be starting the iteration at AG 0, not start_agno. i.e. + for_each_perag(args->mp, 0, args->pag) Cheers, Dave.
On Wed, Apr 05, 2023 at 05:04:14PM +0900, Ryosuke Yasuoka wrote: > Dave, > > Thank you for reviewing my requests. > > > > for_each_perag_wrap() doesn't expect 0 as 2nd arg. > > > To iterate all the available AGs, just use for_each_perag() instead. > > > > Thanks, Ryosuke-san. IIUC, this is a fix for the recent sysbot > > reported filestreams oops regression? > > > > Can you include the context of the failure it reported (i.e. the > > trace from the oops), and the 'reported-by' tag for the syzbot > > report? > > > > It should probably also include a 'Fixes: bd4f5d09cc93 ("xfs: > > refactor the filestreams allocator pick functions")' tag as well. > > No. my request is in the same code area where syzbot bug was reported, > but it might not be relevant. A kernel applying my patch got the same Oops. > > I'm indeed checking the syzbot's bug and I realized that this small bug fix > is not related to it based on my tests. Thus I sent the patch > as a separate one. > > > While this will definitely avoid the oops, I don't think it is quite > > right. If we want to iterate all AGs, then we should be starting the > > iteration at AG 0, not start_agno. i.e. > > > > + for_each_perag(args->mp, 0, args->pag) > > I agree with your proposal because it is more direct. > However, as the current for_each_perag() macro always assigns 0 to (agno), > it will cause compilation errors. Yup, I didn't compile test my suggestion - i just quickly wrote it down to demonstrate what I was thinking. I expect that you have understood that using for_each_perag() was what I was suggesting is used, not that the sample code I wrote is exactly correct. IOWs, for_each_perag(args->mp, start_agno, args->pag) would have worked, even though the code does not do what it looks like it should from the context of start_agno. Which means this would be better: start_agno = 0; for_each_perag_from(args->mp, start_agno, args->pag) because it directly documents the value we are iterating from. > Although I haven't checked other callers deeply, we should modify > the macro as follows: > > #define for_each_perag(mp, agno, pag) \ > - (agno) = 0; \ > for_each_perag_from((mp), (agno), (pag)) That is not correct, either. agno needs to be a variable - it is the loop agno counter that tracks the iteration. Cheers, Dave.
Eric, I failed to reply to you since I got some mistakes. Let me re-send my reply just in case. Thank you for reviewing my requests. > Can you explain what goes wrong if it is zero? Is there a test for this? > > If it's a general problem, what if the other 2 callers pass in the variable > start_agno with a value of 0? Sorry I couldn't prepare any tests to confirm what happens if it is zero because it is a kind of general problem. IIUC, passing zero to for_each_perag_wrap() is not problematic. As the comment describes, this macro iterates all AG from start_agno through wrap_agno, then wrap to restart_agno, and then iterates again toward to start_agno - 1. It looks like some issue occurs when start_agno is zero. However, for_each_perag_wrap() actually won't wrap if start_agno is zero. static inline struct xfs_perag * xfs_perag_next_wrap( struct xfs_perag *pag, xfs_agnumber_t *agno, xfs_agnumber_t stop_agno, xfs_agnumber_t restart_agno, xfs_agnumber_t wrap_agno) { struct xfs_mount *mp = pag->pag_mount; *agno = pag->pag_agno + 1; xfs_perag_rele(pag); while (*agno != stop_agno) { if (*agno >= wrap_agno) { if (restart_agno >= stop_agno) <<<--- HERE break; *agno = restart_agno; } pag = xfs_perag_grab(mp, *agno); if (pag) return pag; (*agno)++; } return NULL; } /* * Iterate all AGs from start_agno through wrap_agno, then restart_agno through * (start_agno - 1). */ #define for_each_perag_wrap_range(mp, start_agno, restart_agno, wrap_agno, agno, pag) \ for ((agno) = (start_agno), (pag) = xfs_perag_grab((mp), (agno)); \ (pag) != NULL; \ (pag) = xfs_perag_next_wrap((pag), &(agno), (start_agno), \ (restart_agno), (wrap_agno))) ... #define for_each_perag_wrap_at(mp, start_agno, wrap_agno, agno, pag) \ for_each_perag_wrap_range((mp), (start_agno), 0, (wrap_agno), (agno), (pag)) ... #define for_each_perag_wrap(mp, start_agno, agno, pag) \ for_each_perag_wrap_at((mp), (start_agno), (mp)->m_sb.sb_agcount, \ (agno), (pag)) OTOH, since we have already a for_each_perag() macro, which just iterates all AG from 0 and doesn't wrap, I think it is simpler to use for_earch_perag(). Regards, Ryosuke
Dave, > On Thu, Apr 6, 2023 at 8:04 AM Dave Chinner <david@fromorbit.com> wrote: > > > > On Wed, Apr 05, 2023 at 05:04:14PM +0900, Ryosuke Yasuoka wrote: > > > Dave, > > > > > > Thank you for reviewing my requests. > > > > > > > > for_each_perag_wrap() doesn't expect 0 as 2nd arg. > > > > > To iterate all the available AGs, just use for_each_perag() instead. > > > > > > > > Thanks, Ryosuke-san. IIUC, this is a fix for the recent sysbot > > > > reported filestreams oops regression? > > > > > > > > Can you include the context of the failure it reported (i.e. the > > > > trace from the oops), and the 'reported-by' tag for the syzbot > > > > report? > > > > > > > > It should probably also include a 'Fixes: bd4f5d09cc93 ("xfs: > > > > refactor the filestreams allocator pick functions")' tag as well. > > > > > > No. my request is in the same code area where syzbot bug was reported, > > > but it might not be relevant. A kernel applying my patch got the same Oops. > > > > > > I'm indeed checking the syzbot's bug and I realized that this small bug fix > > > is not related to it based on my tests. Thus I sent the patch > > > as a separate one. > > > > > > > While this will definitely avoid the oops, I don't think it is quite > > > > right. If we want to iterate all AGs, then we should be starting the > > > > iteration at AG 0, not start_agno. i.e. > > > > > > > > + for_each_perag(args->mp, 0, args->pag) > > > > > > I agree with your proposal because it is more direct. > > > However, as the current for_each_perag() macro always assigns 0 to (agno), > > > it will cause compilation errors. > > > > Yup, I didn't compile test my suggestion - i just quickly wrote it > > down to demonstrate what I was thinking. I expect that you have > > understood that using for_each_perag() was what I was suggesting is > > used, not that the sample code I wrote is exactly correct. IOWs, > > > > for_each_perag(args->mp, start_agno, args->pag) > > > > would have worked, even though the code does not do what it looks > > like it should from the context of start_agno. Which means this > > would be better: > > > > start_agno = 0; > > for_each_perag_from(args->mp, start_agno, args->pag) > > > > because it directly documents the value we are iterating from. OK. I'll update my patch, run a compile test, and then send again as a v2 another thread Thank you for reviewing. Ryosuke
On 4/6/23 11:03 AM, Ryosuke Yasuoka wrote: > Eric, > > I failed to reply to you since I got some mistakes. > Let me re-send my reply just in case. > > Thank you for reviewing my requests. > >> Can you explain what goes wrong if it is zero? Is there a test for this? >> >> If it's a general problem, what if the other 2 callers pass in the variable >> start_agno with a value of 0? > Sorry I couldn't prepare any tests to confirm what happens if it is zero > because it is a kind of general problem. > > IIUC, passing zero to for_each_perag_wrap() is not problematic. ... > OTOH, since we have already a for_each_perag() macro, which just iterates all AG > from 0 and doesn't wrap, I think it is simpler to use for_earch_perag(). > > Regards, > Ryosuke Ok - I couldn't tell from the original email if this was a bugfix or a cleanup, and wanted to be sure. Thanks! -Eric
diff --git a/fs/xfs/xfs_filestream.c b/fs/xfs/xfs_filestream.c index 22c13933c8f8..48f43c340c58 100644 --- a/fs/xfs/xfs_filestream.c +++ b/fs/xfs/xfs_filestream.c @@ -151,7 +151,7 @@ xfs_filestream_pick_ag( * grab. */ if (!max_pag) { - for_each_perag_wrap(args->mp, 0, start_agno, args->pag) + for_each_perag(args->mp, start_agno, args->pag) break; atomic_inc(&args->pag->pagf_fstrms); *longest = 0;