All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tycho Andersen <tycho@tycho.pizza>
To: cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Christian Brauner <brauner@kernel.org>, Tejun Heo <tj@kernel.org>,
	Zefan Li <lizefan.x@bytedance.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Haitao Huang <haitao.huang@linux.intel.com>,
	Kamalesh Babulal <kamalesh.babulal@oracle.com>,
	Tycho Andersen <tycho@tycho.pizza>,
	Tycho Andersen <tandersen@netflix.com>
Subject: [RFC 2/6] fs: introduce count_open_files()
Date: Tue,  7 Nov 2023 17:26:43 -0700	[thread overview]
Message-ID: <20231108002647.73784-3-tycho@tycho.pizza> (raw)
In-Reply-To: <20231108002647.73784-1-tycho@tycho.pizza>

From: Tycho Andersen <tandersen@netflix.com>

In future patches, we'll need a count of the number of open file
descriptors for misc NOFILE cgroup migration, so introduce a helper to do
this.

Signed-off-by: Tycho Andersen <tandersen@netflix.com>
---
 fs/file.c               | 10 ++++++++++
 include/linux/fdtable.h |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/fs/file.c b/fs/file.c
index b1633c00bd3c..539bead2364e 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -285,6 +285,16 @@ static unsigned int count_possible_open_files(struct fdtable *fdt)
 	return i;
 }
 
+u64 count_open_files(struct fdtable *fdt)
+{
+	int i;
+	u64 retval = 0;
+
+	for (i = 0; i < DIV_ROUND_UP(fdt->max_fds, BITS_PER_LONG); i++)
+		retval += hweight64((__u64)fdt->open_fds[i]);
+	return retval;
+}
+
 /*
  * Note that a sane fdtable size always has to be a multiple of
  * BITS_PER_LONG, since we have bitmaps that are sized by this.
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
index bc4c3287a65e..d74234c5d4e9 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -77,6 +77,8 @@ struct dentry;
 #define files_fdtable(files) \
 	rcu_dereference_check_fdtable((files), (files)->fdt)
 
+u64 count_open_files(struct fdtable *fdt);
+
 /*
  * The caller must ensure that fd table isn't shared or hold rcu or file lock
  */
-- 
2.34.1


  parent reply	other threads:[~2023-11-08  0:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08  0:26 [RFC 0/6] tracking fd counts per cgroup Tycho Andersen
2023-11-08  0:26 ` [RFC 1/6] fs: count_open_files() -> count_possible_open_files() Tycho Andersen
2023-11-08  0:26 ` Tycho Andersen [this message]
2023-11-08  0:26 ` [RFC 3/6] misc: introduce misc_cg_charge() Tycho Andersen
2023-11-09 18:04   ` kernel test robot
2023-11-08  0:26 ` [RFC 4/6] misc cgroup: introduce an fd counter Tycho Andersen
2023-11-08 16:57   ` Al Viro
2023-11-08 21:01     ` Tycho Andersen
2023-11-09  9:53   ` Christian Brauner
2023-11-09 14:58     ` Tycho Andersen
2023-11-08  0:26 ` [RFC 5/6] selftests/cgroup: add a flags arg to clone_into_cgroup() Tycho Andersen
2023-11-08  0:26 ` [RFC 6/6] selftests/cgroup: add a test for misc cgroup Tycho Andersen
2023-11-09 18:44 ` [RFC 0/6] tracking fd counts per cgroup Tejun Heo

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=20231108002647.73784-3-tycho@tycho.pizza \
    --to=tycho@tycho.pizza \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=haitao.huang@linux.intel.com \
    --cc=hannes@cmpxchg.org \
    --cc=kamalesh.babulal@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=tandersen@netflix.com \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.