inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set
Subsystems (3)
PATCH 1/1 inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set
From: Iman Seyed <[email protected]>
Avoid setting ret to -EAGAIN unnecessarily. Only set it when O_NONBLOCK is specified; otherwise, leave ret unchanged and proceed to set it to -ERESTARTSYS.
--- fs/notify/inotify/inotify_user.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/notify/inotify/inotify_user.c +4 -2
@@ -279,9 +279,11 @@ static ssize_t inotify_read(struct file *file, char __user *buf,continue ; } - ret = -EAGAIN ; -if (file->f_flags &O_NONBLOCK ) +if (file->f_flags &O_NONBLOCK ) { + ret = -EAGAIN ;break ; + } + ret = -ERESTARTSYS ;if (signal_pending (current))break ;
Signature · 1 line
2.46.0
Quoted 6 lines · On Sat, Aug 31, 2024 at 11:01:50PM -0400, [email protected] wrote:
From: Iman Seyed <[email protected]>
Avoid setting ret to
-EAGAINunnecessarily. Only set it whenO_NONBLOCKis specified; otherwise, leave ret unchanged and proceed to set it to-ERESTARTSYS.
Hi Iman,
Have you checked the code generated by gcc before and after applying this patch? My intuition suggests that the compiler optimization might result in the same code being produced.
Regards,
Kuan-Wei
Quoted 26 lines
Signed-off-by Iman Seyed <[email protected]>--- fs/notify/inotify/inotify_user.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/notify/inotify/inotify_user.c +4
-2@@ -279,9 +279,11 @@ static ssize_t inotify_read(struct file *file, char __user *buf,continue ; } - ret = -EAGAIN ; -if (file->f_flags &O_NONBLOCK ) +if (file->f_flags &O_NONBLOCK ) { + ret = -EAGAIN ;break ; + } + ret = -ERESTARTSYS ;if (signal_pending (current))break ;Signature · 1 line
2.46.0
Hi Kuan-Wei,
I just looked over the assembly generated by GCC and Clang with the O2 level of optimization, and you're right. Both Generate the identical assembly. It seem like my patch would only affect the appearance of the code.
Kind Regards,
Iman
Quoted 42 lines · Kuan-Wei Chiu
Quoted 6 lines · On Sat, Aug 31, 2024 at 11:01:50PM -0400, [email protected] wrote:
From: Iman Seyed <[email protected]>
Avoid setting ret to
-EAGAINunnecessarily. Only set it whenO_NONBLOCKis specified; otherwise, leave ret unchanged and proceed to set it to-ERESTARTSYS.Hi Iman,
Have you checked the code generated by gcc before and after applying this patch? My intuition suggests that the compiler optimization might result in the same code being produced.
Regards,
Kuan-WeiQuoted 26 lines
Signed-off-by Iman Seyed <[email protected]>--- fs/notify/inotify/inotify_user.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/notify/inotify/inotify_user.c +4
-2@@ -279,9 +279,11 @@ static ssize_t inotify_read(struct file *file, char __user *buf,continue ; } - ret = -EAGAIN ; -if (file->f_flags &O_NONBLOCK ) +if (file->f_flags &O_NONBLOCK ) { + ret = -EAGAIN ;break ; + } + ret = -ERESTARTSYS ;if (signal_pending (current))break ;Signature · 1 line
2.46.0
Jan Kara
maintainerQuoted 7 lines · On Sat 31-08-24 23:01:50, [email protected] wrote:
From: Iman Seyed <[email protected]>
Avoid setting ret to
-EAGAINunnecessarily. Only set it whenO_NONBLOCKis specified; otherwise, leave ret unchanged and proceed to set it to-ERESTARTSYS.Signed-off-by Iman Seyed <[email protected]>
Sorry, but this change is a pointless churn. There's no difference to generated code and wrt source code appearance it is a matter of taste where there's no strong preference one way or other in the kernel...
Honza
Quoted 25 lines
--- fs/notify/inotify/inotify_user.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/notify/inotify/inotify_user.c +4
-2@@ -279,9 +279,11 @@ static ssize_t inotify_read(struct file *file, char __user *buf,continue ; } - ret = -EAGAIN ; -if (file->f_flags &O_NONBLOCK ) +if (file->f_flags &O_NONBLOCK ) { + ret = -EAGAIN ;break ; + } + ret = -ERESTARTSYS ;if (signal_pending (current))break ;Signature · 1 line
2.46.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR