On Mon, 17 Oct 2022 21:58:44 -0700 Ivan Babrou <ivan@xxxxxxxxxxxxxx> 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> _