mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fs: predict not reaching the limit in alloc_empty_file()
@ 2025-03-19 12:49 Mateusz Guzik
  2025-03-19 13:10 ` Christian Brauner
  2025-03-19 16:23 ` Jan Kara
  0 siblings, 2 replies; 3+ messages in thread
From: Mateusz Guzik @ 2025-03-19 12:49 UTC (permalink / raw)
  To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel, Mateusz Guzik

Eliminates a jump over a call to capable() in the common case.

By default the limit is not even set, in which case the check can't even
fail to begin with. It remains unset at least on Debian and Ubuntu.
For this cases this can probably become a static branch instead.

In the meantime tidy it up.

I note the check separate from the bump makes the entire thing racy.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
 fs/file_table.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/file_table.c b/fs/file_table.c
index 5b4cc9da1344..c04ed94cdc4b 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -221,7 +221,8 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
 	/*
 	 * Privileged users can go above max_files
 	 */
-	if (get_nr_files() >= files_stat.max_files && !capable(CAP_SYS_ADMIN)) {
+	if (unlikely(get_nr_files() >= files_stat.max_files) &&
+	    !capable(CAP_SYS_ADMIN)) {
 		/*
 		 * percpu_counters are inaccurate.  Do an expensive check before
 		 * we go and fail.
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: predict not reaching the limit in alloc_empty_file()
  2025-03-19 12:49 [PATCH] fs: predict not reaching the limit in alloc_empty_file() Mateusz Guzik
@ 2025-03-19 13:10 ` Christian Brauner
  2025-03-19 16:23 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2025-03-19 13:10 UTC (permalink / raw)
  To: Mateusz Guzik; +Cc: Christian Brauner, viro, jack, linux-kernel, linux-fsdevel

On Wed, 19 Mar 2025 13:49:23 +0100, Mateusz Guzik wrote:
> Eliminates a jump over a call to capable() in the common case.
> 
> By default the limit is not even set, in which case the check can't even
> fail to begin with. It remains unset at least on Debian and Ubuntu.
> For this cases this can probably become a static branch instead.
> 
> In the meantime tidy it up.
> 
> [...]

Applied to the vfs-6.15.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.15.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.15.misc

[1/1] fs: predict not reaching the limit in alloc_empty_file()
      https://git.kernel.org/vfs/vfs/c/9ae7e5a1cd17

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: predict not reaching the limit in alloc_empty_file()
  2025-03-19 12:49 [PATCH] fs: predict not reaching the limit in alloc_empty_file() Mateusz Guzik
  2025-03-19 13:10 ` Christian Brauner
@ 2025-03-19 16:23 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2025-03-19 16:23 UTC (permalink / raw)
  To: Mateusz Guzik; +Cc: brauner, viro, jack, linux-kernel, linux-fsdevel

On Wed 19-03-25 13:49:23, Mateusz Guzik wrote:
> Eliminates a jump over a call to capable() in the common case.
> 
> By default the limit is not even set, in which case the check can't even
> fail to begin with. It remains unset at least on Debian and Ubuntu.
> For this cases this can probably become a static branch instead.
> 
> In the meantime tidy it up.
> 
> I note the check separate from the bump makes the entire thing racy.
> 
> Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/file_table.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/file_table.c b/fs/file_table.c
> index 5b4cc9da1344..c04ed94cdc4b 100644
> --- a/fs/file_table.c
> +++ b/fs/file_table.c
> @@ -221,7 +221,8 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
>  	/*
>  	 * Privileged users can go above max_files
>  	 */
> -	if (get_nr_files() >= files_stat.max_files && !capable(CAP_SYS_ADMIN)) {
> +	if (unlikely(get_nr_files() >= files_stat.max_files) &&
> +	    !capable(CAP_SYS_ADMIN)) {
>  		/*
>  		 * percpu_counters are inaccurate.  Do an expensive check before
>  		 * we go and fail.
> -- 
> 2.43.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-19 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-19 12:49 [PATCH] fs: predict not reaching the limit in alloc_empty_file() Mateusz Guzik
2025-03-19 13:10 ` Christian Brauner
2025-03-19 16:23 ` Jan Kara

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®