From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F575C43334 for ; Tue, 28 Jun 2022 11:54:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345113AbiF1LyB (ORCPT ); Tue, 28 Jun 2022 07:54:01 -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-Google-Smtp-Source: AGRyM1tsML0jjLfuArn0V98uqgHi7yCfymN14awwvePjx5qt4Ac2aBE1EXWTFaiUYpN07axMfRvatg== 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> 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 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 254AFCCA479 for ; Tue, 28 Jun 2022 11:54:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8009110F521; Tue, 28 Jun 2022 11:53:59 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5393B10F6FD for ; Tue, 28 Jun 2022 11:53:57 +0000 (UTC) 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-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-434-30RF8yP-MqKaOA6AYQLxFw-1; Tue, 28 Jun 2022 07:53:55 -0400 X-MC-Unique: 30RF8yP-MqKaOA6AYQLxFw-1 Received: by mail-qv1-f69.google.com with SMTP id w18-20020a0ce112000000b0046e7f2c5a06so12062145qvk.0 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=wVgbbezzeketgoz4s3dAaVOcVtEnIHY6aCxBRH8uLEovGD/fp7b0Trv9Q+JmqguWLf XtPHXm4w2POf0qrNxWujEUTeWsM10UYG6blTBPLGJEWw5P4p8t4vwAHuUV3qCa/w4AyA DHQtCiqBGOzeE3NrHy+JqB/0qOfZpBlSqlAuvAEttgIw18Sc8SswkGIOqcQjm0wj8JJR AuSSytfrDybynCx117PtDqrCgBaCtewHfq6wMDMOj0ixzIUaDMl2HmEl/VfJtaG5fj0B GQMJKFXabydX4jV8J5iz3ZCObBT9Q8mMd7JWLv5+ARdV2YYEmP1OtZtfFxE7ocz7O01r KcHw== X-Gm-Message-State: AJIora8KkAsJciHW2UUJy904zvdNll+Enw5MvFIVpuv7xY+uBfEpduuO 8E4mad7x65Go/N/IHD73BBcKzEFuGUugC74vgHHtJteb7X4AK3leqWWMyyrw5l5ttGyJfgEaI2I x5R4TW0EkzEYWRe4XzIyhql7YjSeS X-Received: by 2002:a37:a9d0:0:b0:6af:1ba4:c3e5 with SMTP id s199-20020a37a9d0000000b006af1ba4c3e5mr8500843qke.167.1656417234891; Tue, 28 Jun 2022 04:53:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tsML0jjLfuArn0V98uqgHi7yCfymN14awwvePjx5qt4Ac2aBE1EXWTFaiUYpN07axMfRvatg== 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 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 In-Reply-To: <20220623220613.3014268-2-kaleshsingh@google.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=bfoster@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, stephen.s.brennan@oracle.com, Paul Gortmaker , Sumit Semwal , Jonathan Corbet , Christoph Anton Mitterer , hch@infradead.org, kernel-team@android.com, linux-media@vger.kernel.org, ckoenig.leichtzumerken@gmail.com, linaro-mm-sig@lists.linaro.org, viro@zeniv.linux.org.uk, surenb@google.com, tjmercier@google.com, Randy Dunlap , ilkos@google.com, linux-kernel@vger.kernel.org, David.Laight@aculab.com, Johannes Weiner , linux-fsdevel@vger.kernel.org, Andrew Morton , christian.koenig@amd.com, Mike Rapoport Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 >