All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: dsterba@suse.cz, Christoph Hellwig <hch@infradead.org>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org,
	"Gustavo A . R . Silva" <gustavoars@kernel.org>
Subject: Re: [PATCH] btrfs: add special case to setget helpers for 64k pages
Date: Mon, 5 Jul 2021 09:33:34 +0100	[thread overview]
Message-ID: <YOLD3CJjDgiq+kfR@infradead.org> (raw)
In-Reply-To: <20210702110630.GE2610@twin.jikos.cz>

On Fri, Jul 02, 2021 at 01:06:30PM +0200, David Sterba wrote:
> On Fri, Jul 02, 2021 at 08:10:50AM +0100, Christoph Hellwig wrote:
> > > +	if (INLINE_EXTENT_BUFFER_PAGES == 1) {				\
> > >  		return get_unaligned_le##bits(token->kaddr + oip);	\
> > > +	} else {							\
> > 
> > No need for an else after the return and thus no need for all the
> > reformatting.
> 
> That leads to worse code, compiler does not eliminate the block that
> would otherwise be in the else block. Measured on x86_64 with
> instrumented code to force INLINE_EXTENT_BUFFER_PAGES = 1 this adds
> +1100 bytes of code and has impact on stack consumption.
> 
> That the code that is in two branches that do not share any code is
> maybe not pretty but the compiler did what I expected.  The set/get
> helpers get called a lot and are performance sensitive.
> 
> This patch pre (original version), post (with dropped else):
> 
> 1156210   19305   14912 1190427  122a1b pre/btrfs.ko
> 1157386   19305   14912 1191603  122eb3 post/btrfs.ko

For the obvious trivial patch (see below) I see the following
difference, which actually makes the simple change smaller:

   text	   data	    bss	    dec	    hex	filename
1322580	 112183	  27600	1462363	 16505b	fs/btrfs/btrfs.o.hch
1322832	 112183	  27600	1462615	 165157	fs/btrfs/btrfs.o.dave

This is sing the following compiler:
gcc version 10.2.1 20210110 (Debian 10.2.1-6) 

---
diff --git a/fs/btrfs/struct-funcs.c b/fs/btrfs/struct-funcs.c
index 8260f8bb3ff0..a20954f06ec8 100644
--- a/fs/btrfs/struct-funcs.c
+++ b/fs/btrfs/struct-funcs.c
@@ -73,7 +73,7 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token,		\
 	}								\
 	token->kaddr = page_address(token->eb->pages[idx]);		\
 	token->offset = idx << PAGE_SHIFT;				\
-	if (oip + size <= PAGE_SIZE)					\
+	if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE)	\
 		return get_unaligned_le##bits(token->kaddr + oip);	\
 									\
 	memcpy(lebytes, token->kaddr + oip, part);			\
@@ -94,7 +94,7 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb,		\
 	u8 lebytes[sizeof(u##bits)];					\
 									\
 	ASSERT(check_setget_bounds(eb, ptr, off, size));		\
-	if (oip + size <= PAGE_SIZE)					\
+	if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE)	\
 		return get_unaligned_le##bits(kaddr + oip);		\
 									\
 	memcpy(lebytes, kaddr + oip, part);				\
@@ -124,7 +124,7 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token,		\
 	}								\
 	token->kaddr = page_address(token->eb->pages[idx]);		\
 	token->offset = idx << PAGE_SHIFT;				\
-	if (oip + size <= PAGE_SIZE) {					\
+	if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE) { \
 		put_unaligned_le##bits(val, token->kaddr + oip);	\
 		return;							\
 	}								\
@@ -146,7 +146,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr,	\
 	u8 lebytes[sizeof(u##bits)];					\
 									\
 	ASSERT(check_setget_bounds(eb, ptr, off, size));		\
-	if (oip + size <= PAGE_SIZE) {					\
+	if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE) { \
 		put_unaligned_le##bits(val, kaddr + oip);		\
 		return;							\
 	}								\

  reply	other threads:[~2021-07-05  8:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01 16:00 [PATCH] btrfs: add special case to setget helpers for 64k pages David Sterba
2021-07-01 21:57 ` Gustavo A. R. Silva
2021-07-01 23:59   ` Qu Wenruo
2021-07-02  0:09     ` Gustavo A. R. Silva
2021-07-02  0:21       ` Qu Wenruo
2021-07-02  0:39         ` Gustavo A. R. Silva
2021-07-02  0:39           ` Qu Wenruo
2021-07-02  1:09             ` Gustavo A. R. Silva
2021-07-02 10:22           ` David Sterba
2021-07-02  7:10 ` Christoph Hellwig
2021-07-02 11:06   ` David Sterba
2021-07-05  8:33     ` Christoph Hellwig [this message]
2021-07-08 14:34       ` David Sterba
2021-07-14 23:37         ` Gustavo A. R. Silva
2021-07-28 15:32           ` David Sterba
2021-07-28 16:00             ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YOLD3CJjDgiq+kfR@infradead.org \
    --to=hch@infradead.org \
    --cc=dsterba@suse.com \
    --cc=dsterba@suse.cz \
    --cc=gustavoars@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.