netfs.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 08/10] netfs: Use folio_next_pos()
       [not found] <20251024170822.1427218-1-willy@infradead.org>
@ 2025-10-24 17:08 ` Matthew Wilcox (Oracle)
  2025-10-24 17:36   ` Paulo Alcantara
  2025-10-27 14:16 ` David Howells
  1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-10-24 17:08 UTC (permalink / raw)
  To: linux-fsdevel, Christian Brauner
  Cc: Matthew Wilcox (Oracle), David Howells, Paulo Alcantara, netfs

This is one instruction more efficient than open-coding folio_pos() +
folio_size().  It's the equivalent of (x + y) << z rather than
x << z + y << z.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: netfs@lists.linux.dev
---
 fs/netfs/buffered_write.c | 2 +-
 fs/netfs/misc.c           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c
index 09394ac2c180..f9d62abef2ac 100644
--- a/fs/netfs/buffered_write.c
+++ b/fs/netfs/buffered_write.c
@@ -535,7 +535,7 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr
 		folio_unlock(folio);
 		err = filemap_fdatawrite_range(mapping,
 					       folio_pos(folio),
-					       folio_pos(folio) + folio_size(folio));
+					       folio_next_pos(folio));
 		switch (err) {
 		case 0:
 			ret = VM_FAULT_RETRY;
diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c
index 486166460e17..82342c6d22cb 100644
--- a/fs/netfs/misc.c
+++ b/fs/netfs/misc.c
@@ -298,7 +298,7 @@ bool netfs_release_folio(struct folio *folio, gfp_t gfp)
 	if (folio_test_dirty(folio))
 		return false;
 
-	end = umin(folio_pos(folio) + folio_size(folio), i_size_read(&ctx->inode));
+	end = umin(folio_next_pos(folio), i_size_read(&ctx->inode));
 	if (end > ctx->zero_point)
 		ctx->zero_point = end;
 
-- 
2.47.2


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

* Re: [PATCH 08/10] netfs: Use folio_next_pos()
  2025-10-24 17:08 ` [PATCH 08/10] netfs: Use folio_next_pos() Matthew Wilcox (Oracle)
@ 2025-10-24 17:36   ` Paulo Alcantara
  0 siblings, 0 replies; 4+ messages in thread
From: Paulo Alcantara @ 2025-10-24 17:36 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), linux-fsdevel, Christian Brauner
  Cc: Matthew Wilcox (Oracle), David Howells, netfs

"Matthew Wilcox (Oracle)" <willy@infradead.org> writes:

> This is one instruction more efficient than open-coding folio_pos() +
> folio_size().  It's the equivalent of (x + y) << z rather than
> x << z + y << z.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: David Howells <dhowells@redhat.com>
> Cc: Paulo Alcantara <pc@manguebit.org>
> Cc: netfs@lists.linux.dev

Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>

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

* Re: [PATCH 08/10] netfs: Use folio_next_pos()
       [not found] <20251024170822.1427218-1-willy@infradead.org>
  2025-10-24 17:08 ` [PATCH 08/10] netfs: Use folio_next_pos() Matthew Wilcox (Oracle)
@ 2025-10-27 14:16 ` David Howells
  2025-10-27 14:50   ` Matthew Wilcox
  1 sibling, 1 reply; 4+ messages in thread
From: David Howells @ 2025-10-27 14:16 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: dhowells, linux-fsdevel, Christian Brauner, Paulo Alcantara,
	netfs

Matthew Wilcox (Oracle) <willy@infradead.org> wrote:

> This is one instruction more efficient than open-coding folio_pos() +
> folio_size().  It's the equivalent of (x + y) << z rather than
> x << z + y << z.

Should that be noted to the gcc bugzilla as a missed optimisation?

> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: David Howells <dhowells@redhat.com>
> Cc: Paulo Alcantara <pc@manguebit.org>
> Cc: netfs@lists.linux.dev

Acked-by: David Howells <dhowells@redhat.com>


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

* Re: [PATCH 08/10] netfs: Use folio_next_pos()
  2025-10-27 14:16 ` David Howells
@ 2025-10-27 14:50   ` Matthew Wilcox
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2025-10-27 14:50 UTC (permalink / raw)
  To: David Howells; +Cc: linux-fsdevel, Christian Brauner, Paulo Alcantara, netfs

On Mon, Oct 27, 2025 at 02:16:45PM +0000, David Howells wrote:
> Matthew Wilcox (Oracle) <willy@infradead.org> wrote:
> 
> > This is one instruction more efficient than open-coding folio_pos() +
> > folio_size().  It's the equivalent of (x + y) << z rather than
> > x << z + y << z.
> 
> Should that be noted to the gcc bugzilla as a missed optimisation?

I don't know?  Maybe there's a Law Of C Arithmetic that prevents it
from doing this optimisation that we can ignore because we know that
the calculation will never overflow.

I tried with both gcc and LLVM and both produce better code for g()
than for f():
https://godbolt.org/z/YTc883f6G

Interestingly, LLVM does better for f() than gcc does, but they produce
identical code for g() (minor difference like using sal instead of shl
but that feels unimportant).

If you want to file optimisation bug(s) against gcc, feel free to use
this example code.

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

end of thread, other threads:[~2025-10-27 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20251024170822.1427218-1-willy@infradead.org>
2025-10-24 17:08 ` [PATCH 08/10] netfs: Use folio_next_pos() Matthew Wilcox (Oracle)
2025-10-24 17:36   ` Paulo Alcantara
2025-10-27 14:16 ` David Howells
2025-10-27 14:50   ` 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).