diff mbox series

btrfs: make btrfs_is_subpage() to return false directly for 4K page size

Message ID bc8baf98c9c9357423178d4fab6b945bcb959f1d.1722839158.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: make btrfs_is_subpage() to return false directly for 4K page size | expand

Commit Message

Qu Wenruo Aug. 5, 2024, 6:26 a.m. UTC
Btrfs only supports sectorsize 4K, 8K, 16K, 32K, 64K for now, thus for
systems with 4K page size, there is no way the fs is subpage (sectorsize
< PAGE_SIZE).

So here we define btrfs_is_subpage() different according to the
PAGE_SIZE:

- PAGE_SIZE > 4K
  We may hit real subpage cases, define btrfs_is_subpage() as a regular
  function and do the usual checks.

- PAGE_SIZE == 4K (no smaller PAGE_SIZE support AFAIK)
  There is no way the fs is subpage, so just define btrfs_is_subpage()
  as an inline function which always return false.

This saves some bytes for x86_64 debug builds:

	   text	   data	    bss	    dec	    hex	filename
Before:	1484452	 168693	  25776	1678921	 199e49	fs/btrfs/btrfs.ko
After:	1476605	 168445	  25776	1670826	 197eaa	fs/btrfs/btrfs.ko

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/subpage.c | 2 ++
 fs/btrfs/subpage.h | 9 +++++++++
 2 files changed, 11 insertions(+)

Comments

David Sterba Aug. 5, 2024, 4:22 p.m. UTC | #1
On Mon, Aug 05, 2024 at 03:56:30PM +0930, Qu Wenruo wrote:
> Btrfs only supports sectorsize 4K, 8K, 16K, 32K, 64K for now, thus for
> systems with 4K page size, there is no way the fs is subpage (sectorsize
> < PAGE_SIZE).
> 
> So here we define btrfs_is_subpage() different according to the
> PAGE_SIZE:
> 
> - PAGE_SIZE > 4K
>   We may hit real subpage cases, define btrfs_is_subpage() as a regular
>   function and do the usual checks.
> 
> - PAGE_SIZE == 4K (no smaller PAGE_SIZE support AFAIK)
>   There is no way the fs is subpage, so just define btrfs_is_subpage()
>   as an inline function which always return false.
> 
> This saves some bytes for x86_64 debug builds:
> 
> 	   text	   data	    bss	    dec	    hex	filename
> Before:	1484452	 168693	  25776	1678921	 199e49	fs/btrfs/btrfs.ko
> After:	1476605	 168445	  25776	1670826	 197eaa	fs/btrfs/btrfs.ko

The delta is 7847, not bad and it's on x86_64 so it'll affect most
machines.

> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: David Sterba <dsterba@suse.com>
David Sterba Aug. 6, 2024, 10:11 a.m. UTC | #2
On Mon, Aug 05, 2024 at 06:22:20PM +0200, David Sterba wrote:
> On Mon, Aug 05, 2024 at 03:56:30PM +0930, Qu Wenruo wrote:
> > Btrfs only supports sectorsize 4K, 8K, 16K, 32K, 64K for now, thus for
> > systems with 4K page size, there is no way the fs is subpage (sectorsize
> > < PAGE_SIZE).
> > 
> > So here we define btrfs_is_subpage() different according to the
> > PAGE_SIZE:
> > 
> > - PAGE_SIZE > 4K
> >   We may hit real subpage cases, define btrfs_is_subpage() as a regular
> >   function and do the usual checks.
> > 
> > - PAGE_SIZE == 4K (no smaller PAGE_SIZE support AFAIK)
> >   There is no way the fs is subpage, so just define btrfs_is_subpage()
> >   as an inline function which always return false.
> > 
> > This saves some bytes for x86_64 debug builds:
> > 
> > 	   text	   data	    bss	    dec	    hex	filename
> > Before:	1484452	 168693	  25776	1678921	 199e49	fs/btrfs/btrfs.ko
> > After:	1476605	 168445	  25776	1670826	 197eaa	fs/btrfs/btrfs.ko
> 
> The delta is 7847, not bad and it's on x86_64 so it'll affect most
> machines.

On my release build config it's

   text    data     bss     dec     hex filename
1339533   30572   16088 1386193  1526d1 pre/btrfs.ko
1332328   30372   16088 1378788  1509e4 post/btrfs.ko

DELTA: -7205
diff mbox series

Patch

diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c
index 8ddd5fcbeb93..631d96f1e905 100644
--- a/fs/btrfs/subpage.c
+++ b/fs/btrfs/subpage.c
@@ -64,6 +64,7 @@ 
  *   This means a slightly higher tree locking latency.
  */
 
+#if PAGE_SIZE > SZ_4K
 bool btrfs_is_subpage(const struct btrfs_fs_info *fs_info, struct address_space *mapping)
 {
 	if (fs_info->sectorsize >= PAGE_SIZE)
@@ -85,6 +86,7 @@  bool btrfs_is_subpage(const struct btrfs_fs_info *fs_info, struct address_space
 		return true;
 	return false;
 }
+#endif
 
 void btrfs_init_subpage_info(struct btrfs_subpage_info *subpage_info, u32 sectorsize)
 {
diff --git a/fs/btrfs/subpage.h b/fs/btrfs/subpage.h
index 249396e118d0..5532cc4fac50 100644
--- a/fs/btrfs/subpage.h
+++ b/fs/btrfs/subpage.h
@@ -5,6 +5,7 @@ 
 
 #include <linux/spinlock.h>
 #include <linux/atomic.h>
+#include <linux/sizes.h>
 
 struct address_space;
 struct folio;
@@ -88,7 +89,15 @@  enum btrfs_subpage_type {
 	BTRFS_SUBPAGE_DATA,
 };
 
+#if PAGE_SIZE > SZ_4K
 bool btrfs_is_subpage(const struct btrfs_fs_info *fs_info, struct address_space *mapping);
+#else
+static inline bool btrfs_is_subpage(const struct btrfs_fs_info *fs_info,
+				    struct address_space *mapping)
+{
+	return false;
+}
+#endif
 
 void btrfs_init_subpage_info(struct btrfs_subpage_info *subpage_info, u32 sectorsize);
 int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,