* [PATCH] fs: Make file-nr output the total allocated file handles
@ 2025-04-10 11:21 lirongqing
2025-04-11 14:16 ` Christian Brauner
2025-04-14 10:07 ` (subset) " Christian Brauner
0 siblings, 2 replies; 6+ messages in thread
From: lirongqing @ 2025-04-10 11:21 UTC (permalink / raw)
To: viro, brauner, jack, linux-fsdevel, linux-kernel; +Cc: Li RongQing
From: Li RongQing <lirongqing@baidu.com>
Make file-nr output the total allocated file handles, not per-cpu
cache number, it's more precise, and not in hot path
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
fs/file_table.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/file_table.c b/fs/file_table.c
index c04ed94..138114d 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(get_max_files);
static int proc_nr_files(const struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos)
{
- files_stat.nr_files = get_nr_files();
+ files_stat.nr_files = percpu_counter_sum_positive(&nr_files);
return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
}
--
2.9.4
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] fs: Make file-nr output the total allocated file handles
2025-04-10 11:21 [PATCH] fs: Make file-nr output the total allocated file handles lirongqing
@ 2025-04-11 14:16 ` Christian Brauner
2025-04-11 21:15 ` Mateusz Guzik
2025-04-12 12:59 ` 答复: [外部邮件] " Li,Rongqing
2025-04-14 10:07 ` (subset) " Christian Brauner
1 sibling, 2 replies; 6+ messages in thread
From: Christian Brauner @ 2025-04-11 14:16 UTC (permalink / raw)
To: lirongqing; +Cc: viro, jack, linux-fsdevel, linux-kernel
On Thu, Apr 10, 2025 at 07:21:17PM +0800, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> Make file-nr output the total allocated file handles, not per-cpu
> cache number, it's more precise, and not in hot path
>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
That means grabbing a lock suddenly. Is there an actual use-case
behind this?
> fs/file_table.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/file_table.c b/fs/file_table.c
> index c04ed94..138114d 100644
> --- a/fs/file_table.c
> +++ b/fs/file_table.c
> @@ -102,7 +102,7 @@ EXPORT_SYMBOL_GPL(get_max_files);
> static int proc_nr_files(const struct ctl_table *table, int write, void *buffer,
> size_t *lenp, loff_t *ppos)
> {
> - files_stat.nr_files = get_nr_files();
> + files_stat.nr_files = percpu_counter_sum_positive(&nr_files);
> return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
> }
>
> --
> 2.9.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] fs: Make file-nr output the total allocated file handles
2025-04-11 14:16 ` Christian Brauner
@ 2025-04-11 21:15 ` Mateusz Guzik
2025-04-12 12:59 ` 答复: [外部邮件] " Li,Rongqing
1 sibling, 0 replies; 6+ messages in thread
From: Mateusz Guzik @ 2025-04-11 21:15 UTC (permalink / raw)
To: Christian Brauner; +Cc: lirongqing, viro, jack, linux-fsdevel, linux-kernel
On Fri, Apr 11, 2025 at 04:16:08PM +0200, Christian Brauner wrote:
> On Thu, Apr 10, 2025 at 07:21:17PM +0800, lirongqing wrote:
> > From: Li RongQing <lirongqing@baidu.com>
> >
> > Make file-nr output the total allocated file handles, not per-cpu
> > cache number, it's more precise, and not in hot path
> >
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > ---
>
> That means grabbing a lock suddenly. Is there an actual use-case
> behind this?
>
The centralized value can be really grossly inaccurate as CPU count increases.
There is some talks about fixing that, see:
https://lore.kernel.org/linux-mm/20250410175149.1206995-1-mathieu.desnoyers@efficios.com/
In the meantime, given that this is only accessed when reading the /proc
file, this should be fine?
Note it still wont delay bumps/decs as long as they fit the batch (which
is the common case).
^ permalink raw reply [flat|nested] 6+ messages in thread
* 答复: [外部邮件] Re: [PATCH] fs: Make file-nr output the total allocated file handles
2025-04-11 14:16 ` Christian Brauner
2025-04-11 21:15 ` Mateusz Guzik
@ 2025-04-12 12:59 ` Li,Rongqing
1 sibling, 0 replies; 6+ messages in thread
From: Li,Rongqing @ 2025-04-12 12:59 UTC (permalink / raw)
To: Christian Brauner; +Cc: viro, jack, linux-fsdevel, linux-kernel
> On Thu, Apr 10, 2025 at 07:21:17PM +0800, lirongqing wrote:
> > From: Li RongQing <lirongqing@baidu.com>
> >
> > Make file-nr output the total allocated file handles, not per-cpu
> > cache number, it's more precise, and not in hot path
> >
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > ---
>
> That means grabbing a lock suddenly. Is there an actual use-case behind this?
want to monitor it to find the leaking of the allocated file handler by some applications, but find it is inaccurate
So I think this is not a hot path, percpu_counter_sum_positive may be able to be used
Thank
-Li
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: (subset) [PATCH] fs: Make file-nr output the total allocated file handles
2025-04-10 11:21 [PATCH] fs: Make file-nr output the total allocated file handles lirongqing
2025-04-11 14:16 ` Christian Brauner
@ 2025-04-14 10:07 ` Christian Brauner
2025-04-14 11:05 ` 答复: [外部邮件] " Li,Rongqing
1 sibling, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2025-04-14 10:07 UTC (permalink / raw)
To: lirongqing; +Cc: Christian Brauner, viro, jack, linux-fsdevel, linux-kernel
On Thu, 10 Apr 2025 19:21:17 +0800, lirongqing wrote:
> Make file-nr output the total allocated file handles, not per-cpu
> cache number, it's more precise, and not in hot path
>
>
Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.16.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.16.misc
[1/1] fs: Make file-nr output the total allocated file handles
https://git.kernel.org/vfs/vfs/c/66319519f89d
^ permalink raw reply [flat|nested] 6+ messages in thread* 答复: [外部邮件] Re: (subset) [PATCH] fs: Make file-nr output the total allocated file handles
2025-04-14 10:07 ` (subset) " Christian Brauner
@ 2025-04-14 11:05 ` Li,Rongqing
0 siblings, 0 replies; 6+ messages in thread
From: Li,Rongqing @ 2025-04-14 11:05 UTC (permalink / raw)
To: Christian Brauner; +Cc: viro, jack, linux-fsdevel, linux-kernel
> On Thu, 10 Apr 2025 19:21:17 +0800, lirongqing wrote:
> > Make file-nr output the total allocated file handles, not per-cpu
> > cache number, it's more precise, and not in hot path
> >
> >
>
Hi Christian Brauner:
Could we change the changelog as below, it maybe more reasonable
fs: Use percpu_counter_sum_positive in proc_nr_files
The centralized value of percpu counter can be really grossly inaccurate
as CPU count increases. and proc_nr_files is only accessed when reading
proc file, not a hot path, so use percpu_counter_sum_positive in it, to make
/proc/sys/fs/file-nr more accurate
thanks
-Li
> Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree.
> Patches in the vfs-6.16.misc branch should appear in linux-next soon.
>
> Please report any outstanding bugs that were missed during review in a new
> review to the original patch series allowing us to drop it.
>
> It's encouraged to provide Acked-bys and Reviewed-bys even though the patch
> has now been applied. If possible patch trailers will be updated.
>
> Note that commit hashes shown below are subject to change due to rebase,
> trailer updates or similar. If in doubt, please check the listed branch.
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
> branch: vfs-6.16.misc
>
> [1/1] fs: Make file-nr output the total allocated file handles
> https://git.kernel.org/vfs/vfs/c/66319519f89d
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-04-14 11:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-10 11:21 [PATCH] fs: Make file-nr output the total allocated file handles lirongqing
2025-04-11 14:16 ` Christian Brauner
2025-04-11 21:15 ` Mateusz Guzik
2025-04-12 12:59 ` 答复: [外部邮件] " Li,Rongqing
2025-04-14 10:07 ` (subset) " Christian Brauner
2025-04-14 11:05 ` 答复: [外部邮件] " Li,Rongqing
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®