* [PATCH] inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set
@ 2024-09-01 3:01 imandevel
2024-09-01 7:00 ` Kuan-Wei Chiu
2024-09-02 14:04 ` Jan Kara
0 siblings, 2 replies; 4+ messages in thread
From: imandevel @ 2024-09-01 3:01 UTC (permalink / raw)
To: jack; +Cc: amir73il, linux-fsdevel, linux-kernel, Iman Seyed
From: Iman Seyed <ImanDevel@gmail.com>
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.
Signed-off-by: Iman Seyed <ImanDevel@gmail.com>
---
fs/notify/inotify/inotify_user.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 4ffc30606e0b..d5d4b306a33d 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -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;
--
2.46.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set
2024-09-01 3:01 [PATCH] inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set imandevel
@ 2024-09-01 7:00 ` Kuan-Wei Chiu
2024-09-01 7:35 ` Iman Seyed
2024-09-02 14:04 ` Jan Kara
1 sibling, 1 reply; 4+ messages in thread
From: Kuan-Wei Chiu @ 2024-09-01 7:00 UTC (permalink / raw)
To: imandevel; +Cc: jack, amir73il, linux-fsdevel, linux-kernel
On Sat, Aug 31, 2024 at 11:01:50PM -0400, imandevel@gmail.com wrote:
> From: Iman Seyed <ImanDevel@gmail.com>
>
> 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.
>
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
> Signed-off-by: Iman Seyed <ImanDevel@gmail.com>
> ---
> fs/notify/inotify/inotify_user.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
> index 4ffc30606e0b..d5d4b306a33d 100644
> --- a/fs/notify/inotify/inotify_user.c
> +++ b/fs/notify/inotify/inotify_user.c
> @@ -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;
> --
> 2.46.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set
2024-09-01 7:00 ` Kuan-Wei Chiu
@ 2024-09-01 7:35 ` Iman Seyed
0 siblings, 0 replies; 4+ messages in thread
From: Iman Seyed @ 2024-09-01 7:35 UTC (permalink / raw)
To: Kuan-Wei Chiu; +Cc: jack, amir73il, linux-fsdevel, linux-kernel
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
On 9/1/24 03:00, Kuan-Wei Chiu wrote:
> On Sat, Aug 31, 2024 at 11:01:50PM -0400, imandevel@gmail.com wrote:
>> From: Iman Seyed <ImanDevel@gmail.com>
>>
>> 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.
>>
> 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
>
>> Signed-off-by: Iman Seyed <ImanDevel@gmail.com>
>> ---
>> fs/notify/inotify/inotify_user.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
>> index 4ffc30606e0b..d5d4b306a33d 100644
>> --- a/fs/notify/inotify/inotify_user.c
>> +++ b/fs/notify/inotify/inotify_user.c
>> @@ -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;
>> --
>> 2.46.0
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set
2024-09-01 3:01 [PATCH] inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set imandevel
2024-09-01 7:00 ` Kuan-Wei Chiu
@ 2024-09-02 14:04 ` Jan Kara
1 sibling, 0 replies; 4+ messages in thread
From: Jan Kara @ 2024-09-02 14:04 UTC (permalink / raw)
To: imandevel; +Cc: jack, amir73il, linux-fsdevel, linux-kernel
On Sat 31-08-24 23:01:50, imandevel@gmail.com wrote:
> From: Iman Seyed <ImanDevel@gmail.com>
>
> 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.
>
> Signed-off-by: Iman Seyed <ImanDevel@gmail.com>
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
> ---
> fs/notify/inotify/inotify_user.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
> index 4ffc30606e0b..d5d4b306a33d 100644
> --- a/fs/notify/inotify/inotify_user.c
> +++ b/fs/notify/inotify/inotify_user.c
> @@ -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;
> --
> 2.46.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-02 14:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-01 3:01 [PATCH] inotify: set ret in inotify_read() to -EAGAIN only when O_NONBLOCK is set imandevel
2024-09-01 7:00 ` Kuan-Wei Chiu
2024-09-01 7:35 ` Iman Seyed
2024-09-02 14:04 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).