fs: predict not reaching the limit in alloc_empty_file()
PATCH 1/1 fs: predict not reaching the limit in alloc_empty_file()
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.
--- fs/file_table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/file_table.c +2 -1
@@ -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.
Signature · 1 line
2.43.0
Quoted 9 lines · 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.
[...]
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
Quoted 11 lines · 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 <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 21 lines
--- fs/file_table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/file_table.c +2
-1@@ -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. Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR