Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3891012iog; Tue, 28 Jun 2022 05:05:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tQG/4W2Os7kXn6Vcr7DyB87VKiGxiOS3BbaP07det1ddoDNCf6dwCpKeJpZV0r/cU6pqnV X-Received: by 2002:a17:906:7a0b:b0:722:dac6:a8ff with SMTP id d11-20020a1709067a0b00b00722dac6a8ffmr17320727ejo.593.1656417893196; Tue, 28 Jun 2022 05:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656417893; cv=none; d=google.com; s=arc-20160816; b=se+A65YX5dJzPSxH3Mm4WC4P0Hr7HYben+SODgBQun8MmOOeFns5YsumpyKj331enB YJJBdkxovAm3wB+BAiAyATUPsPi3VEfmsUFPO0c0TVImAEz2XTK4RBaSm8xq2H8rIPRE YImQ2EHSGRi2g559dTuNGJgHitNNYhUigs/yzAXF+lfjWb7nGJExlbh7d+uuKO9NJPFm MWBgy8NJUSN/h0QAc/t0iu+/q0oZdOqRggJcNHqP1emCB+y8IF4KT6N/w3qghB148A85 nIRTLfLqQhRfAVR4AurN0WpVB+lqJPAEumTnt5JJoumcfcdVrMiizAKXNFRLUG935yEC 8caA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9DZIBhwK0nu+d+e5Dn67t8pp9MEtfy3sJMXiRir3HYs=; b=ygOJ70ajtJnPhkuNnDCkz8qbvDuqhxiymV0TolxwfyU+6dhPMhnLxUTDAXuZmO23Vg w6hCqiCdyNB715MMOOKMY78wTJdNZ+negzyLPLoAiqWDK2RssDMgXbSHbHrAMld9L52K b0Sf2C1K0lqXUHGZ2kXdIrgeNI1/OIYu66QcGuG3aFAd7kO38Wok48VMLTybGoKqhntY 1n/2CTshxSXUBV5Z3dsRi1ifZJpVF8uXp9qwYe3u2+RZztMszIni0e0zTrDTYB858x+N /7a3PXtXSltRJWYA/4uaH/BHt3/eZvEFi+jhgUwYYb+S3N/PeHyGWAw/b8bQJBPWp4zu 5zfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LNu9OM9c; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p28-20020a50cd9c000000b00435787ae1afsi14618084edi.268.2022.06.28.05.04.26; Tue, 28 Jun 2022 05:04:53 -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=LNu9OM9c; 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 S1345102AbiF1LyA (ORCPT + 99 others); Tue, 28 Jun 2022 07:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230332AbiF1Lx6 (ORCPT ); Tue, 28 Jun 2022 07:53:58 -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 ESMTP id 58C563120A for ; Tue, 28 Jun 2022 04:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656417236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9DZIBhwK0nu+d+e5Dn67t8pp9MEtfy3sJMXiRir3HYs=; b=LNu9OM9cAYgxrfyZeRwLmHBS7TAL0IaUoHUvTrzQ2mE1PK/LeF3yJx2YR+vIcXkeIwejV/ ENAnqxoT2xF+d9rBpu46AxwrezwYDpLgAgh6duPHXQUMf36T2LZw2+XmOcnLANfqi/j07p cXDROtm2cLFqP4OB3XaRwbC+/pvfrjo= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-153-zy5_MC-zMIaJ6es2QX9F7w-1; Tue, 28 Jun 2022 07:53:55 -0400 X-MC-Unique: zy5_MC-zMIaJ6es2QX9F7w-1 Received: by mail-qv1-f70.google.com with SMTP id m1-20020a0cf181000000b0046e65e564cfso12060259qvl.17 for ; Tue, 28 Jun 2022 04:53:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=9DZIBhwK0nu+d+e5Dn67t8pp9MEtfy3sJMXiRir3HYs=; b=bCX8wyLKGNJhAM0plEmwKSsRSKlnqT8ucWXYF0g6+7TI4uHbWEMC05FrRxuxeNBYnt PQ4VSzFs2fjOboX/+Qt30snk4LhsO1Zpoypl8TLd2Q0N33rj4LeFQhG/qfFHmHdcaHKh J7hf6leDYmSci6cns8S7q0j5CzN7kT1Mmdau8iMLLpCIfJ9aCG1jjKgZ8t4umhoO3Nu9 r8ODCWhqnXLfv8pA1tqCNmz8rNu36CL1ZcKEGYLxSgVKpciEgIAzYPwGXXKlNDUxYyZK /VdSmmYku89eeWwX4WoVLfhsovsRf2kiyv/TcCrwTVak2VJPcsMpTpU10qhCTIWoVLZw qcig== X-Gm-Message-State: AJIora/xCoQ4KhpYEvPVscXsuZATVXK6kFW/0siJZJQCP56La2lu+slu 3MpPql4V+1br17HvCQFN/gO4eFYaJBkPDF0O/ZhyljZ8O1TJXiOXw9YCXWAcgbyisL5hlGF2TuS Kh6D6+sm0fWuo6KjeTrd0rPFR X-Received: by 2002:a37:a9d0:0:b0:6af:1ba4:c3e5 with SMTP id s199-20020a37a9d0000000b006af1ba4c3e5mr8500860qke.167.1656417234893; Tue, 28 Jun 2022 04:53:54 -0700 (PDT) X-Received: by 2002:a37:a9d0:0:b0:6af:1ba4:c3e5 with SMTP id s199-20020a37a9d0000000b006af1ba4c3e5mr8500833qke.167.1656417234666; Tue, 28 Jun 2022 04:53:54 -0700 (PDT) Received: from bfoster (c-24-61-119-116.hsd1.ma.comcast.net. [24.61.119.116]) by smtp.gmail.com with ESMTPSA id bw20-20020a05622a099400b00304bc2acc25sm8851128qtb.6.2022.06.28.04.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 04:53:54 -0700 (PDT) Date: Tue, 28 Jun 2022 07:53:51 -0400 From: Brian Foster To: Kalesh Singh Cc: ckoenig.leichtzumerken@gmail.com, christian.koenig@amd.com, viro@zeniv.linux.org.uk, hch@infradead.org, stephen.s.brennan@oracle.com, David.Laight@aculab.com, ilkos@google.com, tjmercier@google.com, surenb@google.com, kernel-team@android.com, Jonathan Corbet , Sumit Semwal , Andrew Morton , Johannes Weiner , Christoph Anton Mitterer , Paul Gortmaker , Mike Rapoport , Randy Dunlap , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: Re: [PATCH v2 1/2] procfs: Add 'size' to /proc//fdinfo/ Message-ID: References: <20220623220613.3014268-1-kaleshsingh@google.com> <20220623220613.3014268-2-kaleshsingh@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220623220613.3014268-2-kaleshsingh@google.com> X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Thu, Jun 23, 2022 at 03:06:06PM -0700, Kalesh Singh wrote: > To be able to account the amount of memory a process is keeping pinned > by open file descriptors add a 'size' field to fdinfo output. > > dmabufs fds already expose a 'size' field for this reason, remove this > and make it a common field for all fds. This allows tracking of > other types of memory (e.g. memfd and ashmem in Android). > > Signed-off-by: Kalesh Singh > Reviewed-by: Christian K?nig > --- > > Changes in v2: > - Add Christian's Reviewed-by > > Changes from rfc: > - Split adding 'size' and 'path' into a separate patches, per Christian > - Split fdinfo seq_printf into separate lines, per Christian > - Fix indentation (use tabs) in documentaion, per Randy > > Documentation/filesystems/proc.rst | 12 ++++++++++-- > drivers/dma-buf/dma-buf.c | 1 - > fs/proc/fd.c | 9 +++++---- > 3 files changed, 15 insertions(+), 7 deletions(-) > ... > diff --git a/fs/proc/fd.c b/fs/proc/fd.c > index 913bef0d2a36..464bc3f55759 100644 > --- a/fs/proc/fd.c > +++ b/fs/proc/fd.c > @@ -54,10 +54,11 @@ static int seq_show(struct seq_file *m, void *v) > if (ret) > return ret; > > - seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\nino:\t%lu\n", > - (long long)file->f_pos, f_flags, > - real_mount(file->f_path.mnt)->mnt_id, > - file_inode(file)->i_ino); > + seq_printf(m, "pos:\t%lli\n", (long long)file->f_pos); > + seq_printf(m, "flags:\t0%o\n", f_flags); > + seq_printf(m, "mnt_id:\t%i\n", real_mount(file->f_path.mnt)->mnt_id); > + seq_printf(m, "ino:\t%lu\n", file_inode(file)->i_ino); > + seq_printf(m, "size:\t%lli\n", (long long)file_inode(file)->i_size); Hi Kalesh, Any reason not to use i_size_read() here? Also not sure if it matters that much for your use case, but something worth noting at least with shmem is that one can do something like: # cat /proc/meminfo | grep Shmem: Shmem: 764 kB # xfs_io -fc "falloc -k 0 10m" ./file # ls -alh file -rw-------. 1 root root 0 Jun 28 07:22 file # stat file File: file Size: 0 Blocks: 20480 IO Block: 4096 regular empty file # cat /proc/meminfo | grep Shmem: Shmem: 11004 kB ... where the resulting memory usage isn't reflected in i_size (but is is in i_blocks/bytes). Brian > > /* show_fd_locks() never deferences files so a stale value is safe */ > show_fd_locks(m, file, files); > -- > 2.37.0.rc0.161.g10f37bed90-goog >