Skip to content

Commit 50053de

Browse files
ColinIanKingkakra
authored andcommitted
readdir: add unlikely hint on len check
Currently the out of bounds check for the length is very unlikely to be false for valid name strings. Analysis with gcov coverage show this to be so. Add an unlikely hint on the error return path check. This improves performance when testing with single instance stress-ng dentry and dirent stressors. Tested with a 6.15 kernel, built with gcc 14.2.0 on a Debian Ultra 9 285K system with turbo disabled to reduce test jitter on tmpfs. Each test case was run 25 times and the % standard deviation was less than 0.4%. Geometric mean of 25 results show the following stress-ng bogo-ops performance improvments: getdent: 1.1% dentry: 0.9% Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent 72b441f commit 50053de

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/readdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ EXPORT_SYMBOL(iterate_dir);
147147
*/
148148
static int verify_dirent_name(const char *name, int len)
149149
{
150-
if (len <= 0 || len >= PATH_MAX)
150+
if (unlikely(len <= 0 || len >= PATH_MAX))
151151
return -EIO;
152152
if (memchr(name, '/', len))
153153
return -EIO;

0 commit comments

Comments
 (0)