Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5317389ioo; Wed, 1 Jun 2022 03:02:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/EfHYP7d65h5G2uZdvEXdMtA3Z58p/dAb1xdNmTGR8mDFBtgi7GS8eSgIHSK1YtGtKN1U X-Received: by 2002:a05:6402:26c7:b0:42b:456d:946b with SMTP id x7-20020a05640226c700b0042b456d946bmr56211051edd.400.1654077759113; Wed, 01 Jun 2022 03:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654077759; cv=none; d=google.com; s=arc-20160816; b=mZgUMe1NNKcNXcuV2VIWXJoDrea4L+QcGzrDP9RhnkrROW89sLk6m8BZYAlkbEoMqD aqrLr5vnwnqJUDYCavTBx8qqYzQUwOxGSDB0Nw4ZUA1T6FMbKp3AyXMiqfeeFg4ZjsQO urqX7TnODEHg+Unaby/ffBup1WXtHyu2o3P3hbrlpeUwpJrXmDp9pVYbDlrnhvqAzUpr 7T9XRSaWc+2/eOLqBFoGZLAMX1D3S/TAP8xDa+Mk4EqwVqtu07V58grD8thmj6C92lEC 8dED2UKbXlopSwJuPm9+oytyfJVTdZCHsD5OJSWOYRNjyrA9egnUisXUnUw6aE3EHZMY C+og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:cc:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=px4+ZpXbHsure7vaViwll/H2EGv0zUZueEOXuxtocqM=; b=mG9epwNVfee/NFHl9uAK+iDLj/wLLS87XsFi401qHx0rhBkrWBWkK94S/jehHYVd6O XLnejzm9xWpAAODiy2RBwmEe/zhxzrbuingHWKTeF78SaZXWuIfwqqbasXnHu3gWbutN d//LiAJwtPx6bsbzpnKaNy4XIoLZ6aT33Egu3EmJyVyLn6iEZ9y+nx+F0V5inR3wTGQk flYAdYSHN7wF3+zEMdCsvo49n441boDfpHkeg/znUjO15berLfPnA7A+WFPr1Kbz3pvj YJeu/SkVUP9rwJ8L/ouEw3DlOUt4TvFGLoCY/MLV/Vfcp5lgJtUik3RjexOnDZONZvRe XKzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZaARQ8d9; 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=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh9-20020a1709076e8900b006fe89c9ef8csi820627ejc.764.2022.06.01.03.02.13; Wed, 01 Jun 2022 03:02:39 -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=@google.com header.s=20210112 header.b=ZaARQ8d9; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348008AbiEaVZs (ORCPT + 99 others); Tue, 31 May 2022 17:25:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348002AbiEaVZj (ORCPT ); Tue, 31 May 2022 17:25:39 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6EBC9E9C1 for ; Tue, 31 May 2022 14:25:38 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id e5-20020a255005000000b0065cb3669fe9so6887948ybb.0 for ; Tue, 31 May 2022 14:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:cc; bh=px4+ZpXbHsure7vaViwll/H2EGv0zUZueEOXuxtocqM=; b=ZaARQ8d9PxwUFkeye+orr7uFPd1EQEtmzE+s6UR1ux+FcJbmTHiZMJ7e1JzoYbWBUl MmsmGGcDUWwDl++YBLF/jGBcZ9lqmCmJqOXTlaS/R3d6UBNhxWaNMjeHc5eGTbvGLUe8 SkmOziIw6AkAwq76+XInYclaLp6vw+FNuXhy2Jq5VMAFaIlILl3AKWGm3vccd/4/2RDZ HPtlQ8x4ydXT7SRAuKi6Uou21GfFqKbCfvEpfPM4kJojTYN93ydf8Mcw6YmEpoOEzdQ3 p97exnTro1SyD5LgslZm6/+TUMSKAEZrVnMkRAoxLIKYgxyjsusMw/gYicG9vpaLMIkN XEPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:cc; bh=px4+ZpXbHsure7vaViwll/H2EGv0zUZueEOXuxtocqM=; b=dSPjWtvPgrR/cs9Yc3JtBs88ftfWdZndU4Os6YaX+xl52bW8C2qiS2YuDzhmAX3xMP oTp4sZBzPdDsApa8faT+iWttlzZ6f4gvx5WCCzJEihfFHbboYLfnDy0ogLL10cyDRSjL UiAD4l8vk+iax7rJpwhGkg4KuBnF56B2aXA3tWfXHDKDaiBuC1pWeVPL5GSYuV7KDLEH 7wLlUdDMLWWsdlHZPivphejduwtkfDzA2TzSipESGl5XhOPwa/akVxO17rLdPaSZGrQz IIvjatQndZYQtFFgnO+DP+Cz/A2DFOqdLbqLg3zg76SV/uBrKuBlbBivCWhiGsqDSM+Z o/7Q== X-Gm-Message-State: AOAM533pzJM4ioqAvpGccjE+hMhmters5URiqdSVkKvgkWVluxlVqBdZ kfxyxt0CFNM8fYJXH6sz22/Gpjqz0P8Y9CInZQ== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:a3c0:2a66:b25c:16df]) (user=kaleshsingh job=sendgmr) by 2002:a05:6902:1d1:b0:65c:ea47:8ea1 with SMTP id u17-20020a05690201d100b0065cea478ea1mr11260576ybh.400.1654032337918; Tue, 31 May 2022 14:25:37 -0700 (PDT) Date: Tue, 31 May 2022 14:25:14 -0700 In-Reply-To: <20220531212521.1231133-1-kaleshsingh@google.com> Message-Id: <20220531212521.1231133-2-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220531212521.1231133-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 1/2] procfs: Add 'size' to /proc//fdinfo/ From: Kalesh Singh Cc: ilkos@google.com, tjmercier@google.com, surenb@google.com, kernel-team@android.com, Kalesh Singh , Jonathan Corbet , Sumit Semwal , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Andrew Morton , David Hildenbrand , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MISSING_HEADERS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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/Documentation/filesystems/proc.rst b/Documentation/filesystems/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 regular -files have at least four fields -- 'pos', 'flags', 'mnt_id' and 'ino'. +files have at least five fields -- 'pos', 'flags', 'mnt_id', 'ino', and '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' represents 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 too:: @@ -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:61af 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 fhandle-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:40000000 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 = file->private_data; - seq_printf(m, "size:\t%zu\n", dmabuf->size); /* Don't count the temporary reference taken inside procfs seq_show */ 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_size); /* show_fd_locks() never deferences files so a stale value is safe */ show_fd_locks(m, file, files); -- 2.36.1.255.ge46751e96f-goog