Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5652534rwi; Tue, 18 Oct 2022 02:06:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6rJ2XZziRHPbWqDuCw8igyS92XxtgaYqaDiU0AKagMbOcV5iSE0L5aYDUeMfzEBupOn/YR X-Received: by 2002:a50:eb81:0:b0:458:e40e:68d7 with SMTP id y1-20020a50eb81000000b00458e40e68d7mr1632396edr.131.1666083983201; Tue, 18 Oct 2022 02:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666083983; cv=none; d=google.com; s=arc-20160816; b=ug0HCShVigXqiI0MkAGZUoA1v+B+eHjEpO8IlxmW11uUcN0ZevuOlO2t8+0ZiZAkHL CX40qzAmDZmn6X1HqCy78fmNveXZQltSCenQPVZ1VtypMSQfFvANOyhO1qqIgVHU3PsN B2ZeR+fFEhs592JNCYflI8mt92EFBrkgie0FDSdQXOC8r3HS3tOcQ4dsxf6YXh8Fzx0A zg6iwdHz5/W4rjxqLg2QkqHdltqbVuA/Jp5oh5nVx6WLTjsDLkr0cSuiAXIud0LRNtTQ ELnjwtxD3w4Vs5WnucNqinY3uaouF6lmuaAfpbe26D3q214rV48Lifi0t/zAlkZqKwsP sw0w== 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=eoRiuU9V2WhvCPPrdX4BURCWAuCZBmpxPF9L89jLsOQ=; b=MpDrclMMvDlOmXxS6DYca2pzSImTqtHm642YXr0AN7pDePUERI4yYMGwlaaDTrwiBv tBDzmteONGqnMuc873YW3xd0jXlj7acOxjVrVHsHxLsrNBgLY3mKsZuvG7XrM2ZT+Sh7 JUPW0NVX8p403H6v0Ko64sEMNTsN5KRmfaH9rGVjiVR5sd+iEHIO0xxIkETvkpoEIJEA gD/bYvPFSjqvDhwJlGHULE+Sc9Wka0dZib527foFNgJLijKV8N81s1vW145GUpGbuSzG wQqOp1SbOI4vyAyLHbNCkYlDJzios0Pe73Dwc8fujIoITaM5Y0T41LbCaS8ci+fHuzza MOEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=gUmSCUCJ; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh15-20020a1709076e8f00b007804f3dafbesi13364974ejc.587.2022.10.18.02.05.58; Tue, 18 Oct 2022 02:06:23 -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=@cloudflare.com header.s=google header.b=gUmSCUCJ; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbiJRIsc (ORCPT + 99 others); Tue, 18 Oct 2022 04:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiJRIs3 (ORCPT ); Tue, 18 Oct 2022 04:48:29 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF43220F67 for ; Tue, 18 Oct 2022 01:48:28 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id a13so19493852edj.0 for ; Tue, 18 Oct 2022 01:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eoRiuU9V2WhvCPPrdX4BURCWAuCZBmpxPF9L89jLsOQ=; b=gUmSCUCJbOcxJXEEgGaETNcA07Tv9Z/WeSqkgNfjCccoOupnpdmXsDO2JVMUbmEuut rBPlCkB5uuPqgqgjMvdMEXqn8+MEpcpNsDX8JXOwd8o1uyPHmyjK0L9Fe1FU700xg6n/ fqRDbwucSCpw8P8EWxE3ZJb8TBSgoQTtNz4f8= 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=eoRiuU9V2WhvCPPrdX4BURCWAuCZBmpxPF9L89jLsOQ=; b=MyfV1FbnGM7TWB4C3eb+f5r0mcVr7Bg3CSBU528jY7dOdxwrrsgSJDPv3FfQE2w17w +Ft5R+GHRFl14zc9lhvcpx/UWfrNNgFPEUwGoqX775JAj9LEpQpeBBclIS8EW3Y+eypg /aTtYmSJaDdB1KBUqwZPJd7jwGF2CIAvW11sEIGcP9W9XD3sVXBofX2h6qESsA35gCsl Js6Z/yftBxsVMrDyfaSmDwbZ6/Nx3nJbdxkQ0o9XM6pVsLev+j8Iz+iGZe39uBhESz1J rVc/TpVXnntDdLpN0NgqipyQYaFYdNHyYCKJ4g6t5um5vaknDqZLJKhj3t4NBapcK7K1 qxYA== X-Gm-Message-State: ACrzQf3wNUqhtHdUlQz5LGY4sEaSkQM3AOSiVSDI53ecb/imFFWNuXC2 flFDHFDL3ftzSRPIKSg7i1KB5/FQZT8Azr+nuaDmpw== X-Received: by 2002:a05:6402:3896:b0:45c:93c3:3569 with SMTP id fd22-20020a056402389600b0045c93c33569mr1659759edb.37.1666082907394; Tue, 18 Oct 2022 01:48:27 -0700 (PDT) MIME-Version: 1.0 References: <20220922224027.59266-1-ivan@cloudflare.com> <20221017184700.e1e6944e743bfc38e9abd953@linux-foundation.org> <57b146037b5744d4877fd77b1e4db262@AcuMS.aculab.com> In-Reply-To: <57b146037b5744d4877fd77b1e4db262@AcuMS.aculab.com> From: Frank Hofmann Date: Tue, 18 Oct 2022 09:48:15 +0100 Message-ID: Subject: Re: [PATCH v2] proc: report open files as size in stat() for /proc/pid/fd To: David Laight Cc: Ivan Babrou , Andrew Morton , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "kernel-team@cloudflare.com" , Alexey Dobriyan , Al Viro , "Theodore Ts'o" , Jonathan Corbet , David Hildenbrand , Johannes Weiner , Christoph Anton Mitterer , Mike Rapoport , Paul Gortmaker , Kalesh Singh Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 18, 2022 at 9:25 AM David Laight wrote: > > From: Frank Hofmann > > Sent: 18 October 2022 09:13 > > > > On Tue, Oct 18, 2022 at 6:02 AM Ivan Babrou wrote: > > > > > > On Mon, Oct 17, 2022 at 6:47 PM Andrew Morton wrote: > > > > > + > > > > > + fdt = files_fdtable(p->files); > > > > > + size = fdt->max_fds; > > > > > + > > > > > + for (i = size / BITS_PER_LONG; i > 0;) > > > > > + open_fds += hweight64(fdt->open_fds[--i]); > > > > > > > > Could BITMAP_WEIGHT() or __bitmap_weight() or bitmap_weight() be used here? > > > > > > That's a great suggestion. I tested it with bitmap_weight() and it > > > looks much cleaner while providing the same result. > > > > > > I just sent the v3 with this suggestion applied. > > > > +1 from me on using bitmap_weight() - good spotting that. > > Does that have the optimisations for the value being 0, ~0u > or 2**n-1 all of which are likely for the fd table. > (Especially if there is no 'popcnt' instruction.) > > David bitmap_weight() uses hweight_*() under the hood, which then falls through to platform-specific popcnt where available. Re, lib/bitmap.c and arch/.../asm/bitops.h or arch/.../hweight.S, for the impl details. FrankH. > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)