linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/filemap.c: minor optimization in write_iter file operation
@ 2018-11-18 12:02 Yafang Shao
  2018-11-18 12:13 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Yafang Shao @ 2018-11-18 12:02 UTC (permalink / raw)
  To: willy, akpm, darrick.wong; +Cc: linux-mm, linux-kernel, Yafang Shao

This little adjustment on bitwise operation could make the code a little
faster.
As write_iter is used in lots of critical path, so this code change is
useful for performance.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 mm/filemap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 81adec8..a65056ea 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2881,7 +2881,8 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from)
 	if (iocb->ki_flags & IOCB_APPEND)
 		iocb->ki_pos = i_size_read(inode);
 
-	if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
+	if ((iocb->ki_flags & (IOCB_NOWAIT | IOCB_DIRECT)) ==
+	    IOCB_NOWAIT)
 		return -EINVAL;
 
 	count = iov_iter_count(from);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/filemap.c: minor optimization in write_iter file operation
  2018-11-18 12:02 [PATCH] mm/filemap.c: minor optimization in write_iter file operation Yafang Shao
@ 2018-11-18 12:13 ` Matthew Wilcox
  2018-11-18 15:02   ` Yafang Shao
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2018-11-18 12:13 UTC (permalink / raw)
  To: Yafang Shao; +Cc: akpm, darrick.wong, linux-mm, linux-kernel

On Sun, Nov 18, 2018 at 08:02:18PM +0800, Yafang Shao wrote:
> This little adjustment on bitwise operation could make the code a little
> faster.
> As write_iter is used in lots of critical path, so this code change is
> useful for performance.

Did you check the before/after code generation with this patch applied?

$ diff -u before.S after.S
--- before.S	2018-11-18 07:11:48.031096768 -0500
+++ after.S	2018-11-18 07:11:36.883069103 -0500
@@ -1,5 +1,5 @@
 
-before.o:     file format elf32-i386
+after.o:     file format elf32-i386
 
 
 Disassembly of section .text:

with gcc 8.2.0, I see no difference, indicating that the compiler already
makes this optimisation.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/filemap.c: minor optimization in write_iter file operation
  2018-11-18 12:13 ` Matthew Wilcox
@ 2018-11-18 15:02   ` Yafang Shao
  2018-11-19  1:03     ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Yafang Shao @ 2018-11-18 15:02 UTC (permalink / raw)
  To: willy; +Cc: Andrew Morton, darrick.wong, Linux MM, LKML

On Sun, Nov 18, 2018 at 8:13 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Sun, Nov 18, 2018 at 08:02:18PM +0800, Yafang Shao wrote:
> > This little adjustment on bitwise operation could make the code a little
> > faster.
> > As write_iter is used in lots of critical path, so this code change is
> > useful for performance.
>
> Did you check the before/after code generation with this patch applied?
>

Yes, I did.
My oompiler is gcc-4.8.5, a litte old, and with CONFIG_CC_OPTIMIZE_FOR_SIZE on.
The output file is differrent.

> $ diff -u before.S after.S
> --- before.S    2018-11-18 07:11:48.031096768 -0500
> +++ after.S     2018-11-18 07:11:36.883069103 -0500
> @@ -1,5 +1,5 @@
>
> -before.o:     file format elf32-i386
> +after.o:     file format elf32-i386
>
>
>  Disassembly of section .text:
>
> with gcc 8.2.0, I see no difference, indicating that the compiler already
> makes this optimisation.

Could pls. try set CONFIG_CC_OPTIMIZE_FOR_SIZE on and then compare them again ?

Thanks
Yafang

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/filemap.c: minor optimization in write_iter file operation
  2018-11-18 15:02   ` Yafang Shao
@ 2018-11-19  1:03     ` Matthew Wilcox
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2018-11-19  1:03 UTC (permalink / raw)
  To: Yafang Shao; +Cc: Andrew Morton, darrick.wong, Linux MM, LKML

On Sun, Nov 18, 2018 at 11:02:19PM +0800, Yafang Shao wrote:
> On Sun, Nov 18, 2018 at 8:13 PM Matthew Wilcox <willy@infradead.org> wrote:
> > Did you check the before/after code generation with this patch applied?
> 
> Yes, I did.
> My oompiler is gcc-4.8.5, a litte old, and with CONFIG_CC_OPTIMIZE_FOR_SIZE on.
> > with gcc 8.2.0, I see no difference, indicating that the compiler already
> > makes this optimisation.
> 
> Could pls. try set CONFIG_CC_OPTIMIZE_FOR_SIZE on and then compare them again ?

Actually it was already on:

# CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set
CONFIG_CC_OPTIMIZE_FOR_SIZE=y

I happened to build it in my build-tiny output tree.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-11-19  1:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-18 12:02 [PATCH] mm/filemap.c: minor optimization in write_iter file operation Yafang Shao
2018-11-18 12:13 ` Matthew Wilcox
2018-11-18 15:02   ` Yafang Shao
2018-11-19  1:03     ` Matthew Wilcox

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).