Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7022850rwb; Mon, 12 Dec 2022 09:07:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf4KzULsh9HyNlCwGpJN5EkIk9sSlbjJMdaQjBR7rxMjV7e5VNcnfdHDJiCf4Mk9ySp1Dnnr X-Received: by 2002:a17:906:1716:b0:78d:f459:716d with SMTP id c22-20020a170906171600b0078df459716dmr17569464eje.24.1670864840679; Mon, 12 Dec 2022 09:07:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670864840; cv=none; d=google.com; s=arc-20160816; b=X6RafzKVAhbb79M01fPgVTGeZo+O6nn5D8nw3gd+rF3Tz3lHmZRBmM6/m5j27YCqvy 67JQ8yzsOxi2MDmmLHTPNgWmCvGE7isBeQJsGOgY8QImv1GZ1DDoNfmdatKy+8yPno4F BQcOcv1kX9pP1lX+tB4QPkD/8a24i0a7cPPAnzbNc/72n/4YrYqOpdqXJMcIckEYh0+E LAC0gK8gzRmntuSrNTVBWF+7u3er3C5GbU9QKyU/tfwGkGIWWKruJecJ7DFksZgI2rS7 XsPWcaFCsj3elMRWxZ91o/zQMcJRTa5pzTESwJWU03yibmjK34TGw4vsdoiqUMiX76JZ ZrNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rH+nad7vc6EA7K3ETqSp5AKWpi1iWQe2NlaqEfA8K0Q=; b=0TpabOrpCjzeQedt3af17mmZGzvfP4rSgwqWFye0QtJXbsCF59wuTtexXJyjEW3VEn LJ4r3w+8Xqu4INdd/o2cqGNSgTQ79KjNuBmuFbyocOBfiywlAw351sxiRXVDv6q9mx6c qN9IjPIpHXxJGqEjDy5MP9f1OrteZnvGJOF+QCNq+/xxj/8RIQ255l2I/uHJFqAX9j0D dBUTiRpkVr5XskFf7odfy++RZMsp8gvMXMsT2Cd505dFPAslKZBpa8RFF6TXOaxSy6JJ 8tE5rwAoqTSMckXFg8U9yEBNWtdPFbrOYuYzga+6NJUIiJAP2fZ8JMX7lg3ZItI8SYbG pbvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MDnmIaP5; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a50e60b000000b004549b880c67si7457014edm.42.2022.12.12.09.07.02; Mon, 12 Dec 2022 09:07:20 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=MDnmIaP5; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbiLLQko (ORCPT + 74 others); Mon, 12 Dec 2022 11:40:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232908AbiLLQkO (ORCPT ); Mon, 12 Dec 2022 11:40:14 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87A54167D6 for ; Mon, 12 Dec 2022 08:37:52 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id m14so12682432wrh.7 for ; Mon, 12 Dec 2022 08:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rH+nad7vc6EA7K3ETqSp5AKWpi1iWQe2NlaqEfA8K0Q=; b=MDnmIaP5XogOAs8wBNdcSSfDn0cyV8chPS19FHHFZhlyE/T3tvknyiLf4ZGxGbOSBU W4wfvVp24QBuo67GcT2a7buqSQ9BkwZOyjos0YZrsTdYtKDKMpW1d4wS+xpZ2oDKbcaY bCrrMm6AansBYrC+oD5mJ+n5uDlw3D9TP1kc5NtrJ2+DyKPlfcofyDRp/67E2VD4/yk1 fULS+Dv2f/CJ2hanYcj1hK1TOsj2Wpquaa6Jz1kPUE4xJ/0tS8krYMEeZynSzXPmaPyH qN0EFFxluy0msAVc9CluIMvPHwwomFFFkBsAtbYc28FMJJfwmKGOLml5U0BY7jK88fRQ qvGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rH+nad7vc6EA7K3ETqSp5AKWpi1iWQe2NlaqEfA8K0Q=; b=7BWta21uvvlZ+SuydaFr91htsIsMHH3oosBSdkdPmpWmog7wV4cofhR0rPGVp+LzBL eNJ76+7TaRoFgGrmE7Rtpd+5ARTEJbS6hu77m8BHklynwZROJW27bOtQWrH6sIMFEI3U CPXOPDNH+1ew0ra/4Fz4JjfH47EaCKJ4jfdl15AeUfUSrvEcB5F1dBIqzWoIXr8z2Wvm rQyIs4k1kVqbJtJQ5nR8lOlRx97VzUSvt0J+NQsufjoNYZ9sX9nU4MZ6yqVjP8/ylwPS XSyvC2sNK6S+SPRQV3uPx7hhkkrB4dUYNt6mNpDsYrGkmEAyydbA2QR9OMsMUnxgPOc2 coVQ== X-Gm-Message-State: ANoB5pmR0pFpjLkLoUDckl+YL0rO85MI+G9O2cC/xyuQ9JNRSfhA7Ai0 ILmSWWm0SnzDpJL2yTJO55hGKPy4NdVOmq86+Pm2MpWLtLM= X-Received: by 2002:adf:df81:0:b0:242:6553:668e with SMTP id z1-20020adfdf81000000b002426553668emr10671811wrl.131.1670863070984; Mon, 12 Dec 2022 08:37:50 -0800 (PST) MIME-Version: 1.0 References: <20221205175140.1543229-1-nphamcs@gmail.com> <20221205175140.1543229-4-nphamcs@gmail.com> In-Reply-To: From: Nhat Pham Date: Mon, 12 Dec 2022 08:37:39 -0800 Message-ID: Subject: Re: [PATCH v2 3/4] cachestat: implement cachestat syscall To: Matthew Wilcox Cc: Al Viro , akpm@linux-foundation.org, hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bfoster@redhat.com, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 12, 2022 at 8:24 AM Matthew Wilcox wrote: > > On Mon, Dec 12, 2022 at 08:23:31AM -0800, Nhat Pham wrote: > > > It would be easier to read if you inverted the condition here. > > > > Oh I think I tried > > > > if (!f.file) > > return -EBADF; > > > > here, but there are some mixing-code-with-decl warnings. > > If I recall correctly, the problem is with this line: > > > > XA_STATE(xas, &mapping->i_pages, first_index); > > > > which is expanded into a declaration: > > > > #define XA_STATE(name, array, index) \ > > struct xa_state name = __XA_STATE(array, index, 0, 0) > > > > It requires a valid mapping though, which is > > obtained from f.file: > > > > struct address_space *mapping = f.file->f_mapping; > > > > so it cannot be moved above the if(!f.file) check either... > > Perhaps you're trying to do too much in a single function? That's fair. In an ancient version of this, I did try to separate the folio-walking logic into its own function, but then decided against it because it seemed unnecessary. That was before the complexity of that piece of logic blew up to the current situation though, so perhaps it is time to revisit this decision and refactor it.