Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1246534lfc; Wed, 1 Jun 2022 12:59:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPri7GFwGhEeQvSNApBXK1eOPNhyy/C9HAyJ7BE//GkZE3Li96UEqWHiJouBs+iWEkDzHH X-Received: by 2002:a63:f07:0:b0:3fc:ca1b:feb2 with SMTP id e7-20020a630f07000000b003fcca1bfeb2mr895178pgl.211.1654113563049; Wed, 01 Jun 2022 12:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654113563; cv=none; d=google.com; s=arc-20160816; b=LsrJADk5Sx/V+8Svpq7nRZX5K3JrJnnRV0u1K3HU9wKeKhc5gKg70yEDc2atOS7Lyo p2Q/4AGHxmj4Jb8iX6Yl1r4IXnM5k0tfL+e9Vk1WGksoeJFSdNWrtSVBBVcfCLZOmuKq Kn/ECO905Cq8ag9opW7yvtAV6mvpP89ZXLnzZDCjJVb8mjvJeqAtHr+Ojk8v23DGOVnF Qh4wVKbO2v3iIueO9QfG++NxHho0n0CMELglprgqvXZ1ajnznFMi7DOWFfdNN3vJKYDo kbQe16ZahPtSV2Ph+Yc/TSoaAskpjyUiFqhTgMxXosV5qguPPlX6LpcLMzN7jGS7eo7d tyxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=bcxJZOoEGdj9HHyfjULCcOOxYPoZGRjHpoFm81lNVOs=; b=LXJevL4rVB9aZPty0fhethCEndUEDT6YaXLKs0rmCv2JddQSKq0IaSfWXeFaJ8sXzg +BJs7cnaGDsteBjDoI9sveLP7NxnjVzKzTzNSVv+4wVid0VxL7NGQ5xkF/ng5TEzs9bq ueRBT8EUtGz/RAzKl+kNexz/y7OMGHahCoExt4+24F3Gl8Jq6JaOMVdz4rOCaGH9ShPW XzR0zXWASGlrjl+QOQiH/YvjfXqZZNHolP7WdBWwMIOvcnD/+lJ98FQHoqCBYDJ94z09 +b4LTuMo9Xy4ymNi5YR+R615dE+MV1F5cQwDypH5lzU06LHgRi5f7Tj6a11wUYqtuaME QyQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=P+A7Ep4P; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 2-20020a630902000000b003fc04782bbdsi3222779pgj.380.2022.06.01.12.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:59:23 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=P+A7Ep4P; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 90A1A21AC6E; Wed, 1 Jun 2022 12:18:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbiFAO6h (ORCPT + 99 others); Wed, 1 Jun 2022 10:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiFAO6c (ORCPT ); Wed, 1 Jun 2022 10:58:32 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79E63579BF for ; Wed, 1 Jun 2022 07:58:28 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q7so2729632wrg.5 for ; Wed, 01 Jun 2022 07:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=bcxJZOoEGdj9HHyfjULCcOOxYPoZGRjHpoFm81lNVOs=; b=P+A7Ep4P+FL+NTqEOtoX8UyZXTOoMsHDrPThvBn0p2XBWcLvNZFCRF7csyce5aJIgC /9J8TqZFKIKxg2L9BWSFt0+g/QdglYWeGwGr9vBpkG6lvUtwe24zixvQnaVAwqK2LTTw 1epOyxU982uVJ8EcAUJAU6U9HLFl24Deyae4kvazM0NpvT9iCnL1FaKKzMmKp4f/M2Cf KtruZqQI5Mxe/3mT8Qb8rfG3YG75gK3bweRHBCVUOlHWwTfHTMSj3dbyzs0XWy9/z5XF jQKHq1dd7J3P8yVThLPD9s+w3k5yM1y6Z2oMhGM33BXvo/V2LfUPw0tyLQzHiaLK66HC 0syg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=bcxJZOoEGdj9HHyfjULCcOOxYPoZGRjHpoFm81lNVOs=; b=h8eb1ugjMn8fSHV5U7yAxklO0l5tQU2bCWlLn8ML9T0u4YM16foc9VJjLoPxvBzXkH kH7XPMMNtTB3kXJDcjOM7Lh/oBBlmQco7I8Hxw580yIp1QPfNu+SjnQ9Bj91rBFOrXlh qyd0F39ekZpJkkBX6o/blaiuNgoHAQga7N6CCTv12iDcRHv5+Oeo87uOSDcu/1na9Phz tA++u89JpSpdOePjrMQKeDWPRPfED+0ndwqdvgw87lkOpsTKmLWS4zL26DxrtCEI8h/N YuSFGSI99DcPgYEp5qY/XSM3BrAzNN6E9vAUOr8RYUOXGRMMN5gdDJGNHtdN4b7cNvmz NJ6Q== X-Gm-Message-State: AOAM533+kU/bZxvBxNLFURaEKS4c3ECZE2ek0t1ITF4NaIFcsCgzjX0K UqHwS+7MULyUPL6BKPXFzv145uG2sRU2eoMZur7HGQ== X-Received: by 2002:a05:6000:71b:b0:20e:ed96:e976 with SMTP id bs27-20020a056000071b00b0020eed96e976mr178409wrb.500.1654095506747; Wed, 01 Jun 2022 07:58:26 -0700 (PDT) MIME-Version: 1.0 References: <20220531212521.1231133-1-kaleshsingh@google.com> <20220531212521.1231133-2-kaleshsingh@google.com> <78efbada-6dd5-ead7-fc10-38b5e1e92fc5@amd.com> In-Reply-To: <78efbada-6dd5-ead7-fc10-38b5e1e92fc5@amd.com> From: Kalesh Singh Date: Wed, 1 Jun 2022 07:58:15 -0700 Message-ID: Subject: Re: [PATCH 1/2] procfs: Add 'size' to /proc//fdinfo/ To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Ioannis Ilkos , "T.J. Mercier" , Suren Baghdasaryan , "Cc: Android Kernel" , Jonathan Corbet , Sumit Semwal , Andrew Morton , David Hildenbrand , Johannes Weiner , Christoph Anton Mitterer , Paul Gortmaker , Mike Rapoport , Randy Dunlap , LKML , linux-fsdevel , "open list:DOCUMENTATION" , Linux Media Mailing List , DRI mailing list , "moderated list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Wed, Jun 1, 2022 at 6:55 AM Christian K=C3=B6nig wrote: > > Am 31.05.22 um 23:25 schrieb Kalesh Singh: > > 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 > > At least for the DMA-buf part feel free to add an Reviewed-by: Christian > K=C3=B6nig for this. Thanks for the review, Christian. --Kalesh > > Regards, > Christian. > > > --- > > > > Changes from rfc: > > - Split adding 'size' and 'path' into a separate patches, per Christ= ian > > - 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/Documentation/filesystems/proc.rst b/Documentation/filesys= tems/proc.rst > > index 1bc91fb8c321..779c05528e87 100644 > > --- a/Documentation/filesystems/proc.rst > > +++ b/Documentation/filesystems/proc.rst > > @@ -1886,13 +1886,14 @@ if precise results are needed. > > 3.8 /proc//fdinfo/ - Information about opened file > > --------------------------------------------------------------- > > This file provides information associated with an opened file. The re= gular > > -files have at least four fields -- 'pos', 'flags', 'mnt_id' and 'ino'. > > +files have at least five fields -- 'pos', 'flags', 'mnt_id', 'ino', an= d 'size'. > > + > > The 'pos' represents the current offset of the opened file in decimal > > form [see lseek(2) for details], 'flags' denotes the octal O_xxx mask= the > > file has been created with [see open(2) for details] and 'mnt_id' rep= resents > > mount ID of the file system containing the opened file [see 3.5 > > /proc//mountinfo for details]. 'ino' represents the inode number= of > > -the file. > > +the file, and 'size' represents the size of the file in bytes. > > > > A typical output is:: > > > > @@ -1900,6 +1901,7 @@ A typical output is:: > > flags: 0100002 > > mnt_id: 19 > > ino: 63107 > > + size: 0 > > > > All locks associated with a file descriptor are shown in its fdinfo t= oo:: > > > > @@ -1917,6 +1919,7 @@ Eventfd files > > flags: 04002 > > mnt_id: 9 > > ino: 63107 > > + size: 0 > > eventfd-count: 5a > > > > where 'eventfd-count' is hex value of a counter. > > @@ -1930,6 +1933,7 @@ Signalfd files > > flags: 04002 > > mnt_id: 9 > > ino: 63107 > > + size: 0 > > sigmask: 0000000000000200 > > > > where 'sigmask' is hex value of the signal mask associated > > @@ -1944,6 +1948,7 @@ Epoll files > > flags: 02 > > mnt_id: 9 > > ino: 63107 > > + size: 0 > > tfd: 5 events: 1d data: ffffffffffffffff pos:0 ino:6= 1af sdev:7 > > > > where 'tfd' is a target file descriptor number in decimal form, > > @@ -1962,6 +1967,7 @@ For inotify files the format is the following:: > > flags: 02000000 > > mnt_id: 9 > > ino: 63107 > > + size: 0 > > inotify wd:3 ino:9e7e sdev:800013 mask:800afce ignored_mask:0 fha= ndle-bytes:8 fhandle-type:1 f_handle:7e9e0000640d1b6d > > > > where 'wd' is a watch descriptor in decimal form, i.e. a target file > > @@ -1985,6 +1991,7 @@ For fanotify files the format is:: > > flags: 02 > > mnt_id: 9 > > ino: 63107 > > + size: 0 > > fanotify flags:10 event-flags:0 > > fanotify mnt_id:12 mflags:40 mask:38 ignored_mask:40000003 > > fanotify ino:4f969 sdev:800013 mflags:0 mask:3b ignored_mask:4000= 0000 fhandle-bytes:8 fhandle-type:1 f_handle:69f90400c275b5b4 > > @@ -2010,6 +2017,7 @@ Timerfd files > > flags: 02 > > mnt_id: 9 > > ino: 63107 > > + size: 0 > > clockid: 0 > > ticks: 0 > > settime flags: 01 > > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c > > index 32f55640890c..5f2ae38c960f 100644 > > --- a/drivers/dma-buf/dma-buf.c > > +++ b/drivers/dma-buf/dma-buf.c > > @@ -378,7 +378,6 @@ static void dma_buf_show_fdinfo(struct seq_file *m,= struct file *file) > > { > > struct dma_buf *dmabuf =3D file->private_data; > > > > - seq_printf(m, "size:\t%zu\n", dmabuf->size); > > /* Don't count the temporary reference taken inside procfs seq_sh= ow */ > > seq_printf(m, "count:\t%ld\n", file_count(dmabuf->file) - 1); > > seq_printf(m, "exp_name:\t%s\n", dmabuf->exp_name); > > 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_siz= e); > > > > /* show_fd_locks() never deferences files so a stale value is saf= e */ > > show_fd_locks(m, file, files); >