From: Andrew Morton <akpm@linux-foundation.org>
To: Ivan Babrou <ivan@cloudflare.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@cloudflare.com, Alexey Dobriyan <adobriyan@gmail.com>,
Al Viro <viro@zeniv.linux.org.uk>,
"Theodore Ts'o" <tytso@mit.edu>,
David Laight <David.Laight@aculab.com>,
Jonathan Corbet <corbet@lwn.net>,
David Hildenbrand <david@redhat.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>,
Mike Rapoport <rppt@kernel.org>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Kalesh Singh <kaleshsingh@google.com>
Subject: Re: [PATCH v3] proc: report open files as size in stat() for /proc/pid/fd
Date: Tue, 18 Oct 2022 16:13:57 -0700 [thread overview]
Message-ID: <20221018161357.4891fcdb94ecc63035b6792a@linux-foundation.org> (raw)
In-Reply-To: <20221018045844.37697-1-ivan@cloudflare.com>
On Mon, 17 Oct 2022 21:58:44 -0700 Ivan Babrou <ivan@cloudflare.com> wrote:
> v3: Made use of bitmap_weight() to count the bits.
Thanks, I queued the below delta:
--- a/fs/proc/fd.c~proc-report-open-files-as-size-in-stat-for-proc-pid-fd-v3
+++ a/fs/proc/fd.c
@@ -283,7 +283,7 @@ static int proc_readfd_count(struct inod
{
struct task_struct *p = get_proc_task(inode);
struct fdtable *fdt;
- unsigned int i, size, open_fds = 0;
+ unsigned int open_fds = 0;
if (!p)
return -ENOENT;
@@ -293,10 +293,7 @@ static int proc_readfd_count(struct inod
rcu_read_lock();
fdt = files_fdtable(p->files);
- size = fdt->max_fds;
-
- for (i = size / BITS_PER_LONG; i > 0;)
- open_fds += hweight64(fdt->open_fds[--i]);
+ open_fds = bitmap_weight(fdt->open_fds, fdt->max_fds);
rcu_read_unlock();
}
_
Also, let's explicitly include the header file to avoid possible
accidents with unexpected Kconfigs.
--- a/fs/proc/fd.c~proc-report-open-files-as-size-in-stat-for-proc-pid-fd-v3-fix
+++ a/fs/proc/fd.c
@@ -7,6 +7,7 @@
#include <linux/namei.h>
#include <linux/pid.h>
#include <linux/ptrace.h>
+#include <linux/bitmap.h>
#include <linux/security.h>
#include <linux/file.h>
#include <linux/seq_file.h>
_
prev parent reply other threads:[~2022-10-18 23:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 4:58 Ivan Babrou
2022-10-18 18:16 ` Brian Foster
2022-10-18 18:51 ` Ivan Babrou
2022-10-19 11:28 ` Brian Foster
2022-10-21 0:52 ` Andrew Morton
2022-10-18 23:13 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221018161357.4891fcdb94ecc63035b6792a@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=David.Laight@aculab.com \
--cc=adobriyan@gmail.com \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=ivan@cloudflare.com \
--cc=kaleshsingh@google.com \
--cc=kernel-team@cloudflare.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@christoph.anton.mitterer.name \
--cc=paul.gortmaker@windriver.com \
--cc=rppt@kernel.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®