linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: reduce stack usage for btrfsic_process_written_block
@ 2019-07-08 12:40 Arnd Bergmann
  2019-07-08 12:47 ` Johannes Thumshirn
  2019-07-24 14:57 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-07-08 12:40 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba
  Cc: Arnd Bergmann, Johannes Thumshirn, Nikolay Borisov,
	Andrea Gelmini, Qu Wenruo, Liu Bo, linux-btrfs, linux-kernel

btrfsic_process_written_block() cals btrfsic_process_metablock(),
which has a fairly large stack usage due to the btrfsic_stack_frame
variable. It also calls btrfsic_test_for_metadata(), which now
needs several hundreds of bytes for its SHASH_DESC_ON_STACK().

In some configurations, we end up with both functions on the
same stack, and gcc warns about the excessive stack usage that
might cause the available stack space to run out:

fs/btrfs/check-integrity.c:1743:13: error: stack frame size of 1152 bytes in function 'btrfsic_process_written_block' [-Werror,-Wframe-larger-than=]

Marking both child functions as noinline_for_stack helps because
this guarantees that the large variables are not on the same
stack frame.

Fixes: d5178578bcd4 ("btrfs: directly call into crypto framework for checksumming")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 fs/btrfs/check-integrity.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 81a9731959a9..0b52ab4cb964 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -940,7 +940,7 @@ static void btrfsic_stack_frame_free(struct btrfsic_stack_frame *sf)
 	kfree(sf);
 }
 
-static int btrfsic_process_metablock(
+static noinline_for_stack int btrfsic_process_metablock(
 		struct btrfsic_state *state,
 		struct btrfsic_block *const first_block,
 		struct btrfsic_block_data_ctx *const first_block_ctx,
@@ -1706,8 +1706,9 @@ static void btrfsic_dump_database(struct btrfsic_state *state)
  * Test whether the disk block contains a tree block (leaf or node)
  * (note that this test fails for the super block)
  */
-static int btrfsic_test_for_metadata(struct btrfsic_state *state,
-				     char **datav, unsigned int num_pages)
+static noinline_for_stack int btrfsic_test_for_metadata(
+		struct btrfsic_state *state,
+		char **datav, unsigned int num_pages)
 {
 	struct btrfs_fs_info *fs_info = state->fs_info;
 	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
-- 
2.20.0


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

* Re: [PATCH] btrfs: reduce stack usage for btrfsic_process_written_block
  2019-07-08 12:40 [PATCH] btrfs: reduce stack usage for btrfsic_process_written_block Arnd Bergmann
@ 2019-07-08 12:47 ` Johannes Thumshirn
  2019-07-24 14:57 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2019-07-08 12:47 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Chris Mason, Josef Bacik, David Sterba, Nikolay Borisov,
	Andrea Gelmini, Qu Wenruo, Liu Bo, linux-btrfs, linux-kernel

Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>

Thanks Arnd
-- 
Johannes Thumshirn                            SUSE Labs Filesystems
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

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

* Re: [PATCH] btrfs: reduce stack usage for btrfsic_process_written_block
  2019-07-08 12:40 [PATCH] btrfs: reduce stack usage for btrfsic_process_written_block Arnd Bergmann
  2019-07-08 12:47 ` Johannes Thumshirn
@ 2019-07-24 14:57 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2019-07-24 14:57 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Chris Mason, Josef Bacik, David Sterba, Johannes Thumshirn,
	Nikolay Borisov, Andrea Gelmini, Qu Wenruo, Liu Bo, linux-btrfs,
	linux-kernel

On Mon, Jul 08, 2019 at 02:40:09PM +0200, Arnd Bergmann wrote:
> btrfsic_process_written_block() cals btrfsic_process_metablock(),
> which has a fairly large stack usage due to the btrfsic_stack_frame
> variable. It also calls btrfsic_test_for_metadata(), which now
> needs several hundreds of bytes for its SHASH_DESC_ON_STACK().
> 
> In some configurations, we end up with both functions on the
> same stack, and gcc warns about the excessive stack usage that
> might cause the available stack space to run out:
> 
> fs/btrfs/check-integrity.c:1743:13: error: stack frame size of 1152 bytes in function 'btrfsic_process_written_block' [-Werror,-Wframe-larger-than=]
> 
> Marking both child functions as noinline_for_stack helps because
> this guarantees that the large variables are not on the same
> stack frame.
> 
> Fixes: d5178578bcd4 ("btrfs: directly call into crypto framework for checksumming")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Added to misc-next, thanks.

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

end of thread, other threads:[~2019-07-24 14:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 12:40 [PATCH] btrfs: reduce stack usage for btrfsic_process_written_block Arnd Bergmann
2019-07-08 12:47 ` Johannes Thumshirn
2019-07-24 14:57 ` David Sterba

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