Re: [PATCH] fs: predict not reaching the limit in alloc_empty_file()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

								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@xxxxxxxx>
SUSE Labs, CR




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux