aboutsummaryrefslogtreecommitdiffstats
path: root/fs/file_table.c
diff options
context:
space:
mode:
authorMateusz Guzik <[email protected]>2025-03-19 12:49:23 +0000
committerChristian Brauner <[email protected]>2025-03-19 13:09:58 +0000
commit9ae7e5a1cd17b271e1b3339a23883d3d64724dcc (patch)
tree54065ce766278bb21114f5786e2c2a8b1b72cf55 /fs/file_table.c
parentfs: load the ->i_sb pointer once in inode_sb_list_{add,del} (diff)
downloadkernel-9ae7e5a1cd17b271e1b3339a23883d3d64724dcc.tar.gz
kernel-9ae7e5a1cd17b271e1b3339a23883d3d64724dcc.zip
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. Signed-off-by: Mateusz Guzik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
Diffstat (limited to 'fs/file_table.c')
-rw-r--r--fs/file_table.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/fs/file_table.c b/fs/file_table.c
index f0291a66f9db..4d9f723350fb 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -216,7 +216,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.