linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: tree-check: reduce stack consumption in check_dir_item
@ 2018-01-10 14:28 David Sterba
  2018-01-10 15:46 ` Josef Bacik
  2018-01-11  1:14 ` Qu Wenruo
  0 siblings, 2 replies; 3+ messages in thread
From: David Sterba @ 2018-01-10 14:28 UTC (permalink / raw)
  To: linux-btrfs; +Cc: wqu, David Sterba

I've noticed that the updated item checker stack consumption increased
dramatically in 542f5385e20cf97447 ("btrfs: tree-checker: Add checker
for dir item")

tree-checker.c:check_leaf                    +552 (176 -> 728)

The array is 255 bytes long, dynamic allocation would slow down the
sanity checks so it's more reasonable to keep it on-stack. Moving the
variable to the scope of use reduces the stack usage again

tree-checker.c:check_leaf                    -264 (728 -> 464)

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/tree-checker.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 7c55e3ba5a6c..c3c8d48f6618 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -259,7 +259,6 @@ static int check_dir_item(struct btrfs_root *root,
 
 	di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
 	while (cur < item_size) {
-		char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)];
 		u32 name_len;
 		u32 data_len;
 		u32 max_name_len;
@@ -342,6 +341,8 @@ static int check_dir_item(struct btrfs_root *root,
 		 */
 		if (key->type == BTRFS_DIR_ITEM_KEY ||
 		    key->type == BTRFS_XATTR_ITEM_KEY) {
+			char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)];
+
 			read_extent_buffer(leaf, namebuf,
 					(unsigned long)(di + 1), name_len);
 			name_hash = btrfs_name_hash(namebuf, name_len);
-- 
2.15.1


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

* Re: [PATCH] btrfs: tree-check: reduce stack consumption in check_dir_item
  2018-01-10 14:28 [PATCH] btrfs: tree-check: reduce stack consumption in check_dir_item David Sterba
@ 2018-01-10 15:46 ` Josef Bacik
  2018-01-11  1:14 ` Qu Wenruo
  1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2018-01-10 15:46 UTC (permalink / raw)
  To: David Sterba; +Cc: linux-btrfs, wqu

On Wed, Jan 10, 2018 at 03:28:51PM +0100, David Sterba wrote:
> I've noticed that the updated item checker stack consumption increased
> dramatically in 542f5385e20cf97447 ("btrfs: tree-checker: Add checker
> for dir item")
> 
> tree-checker.c:check_leaf                    +552 (176 -> 728)
> 
> The array is 255 bytes long, dynamic allocation would slow down the
> sanity checks so it's more reasonable to keep it on-stack. Moving the
> variable to the scope of use reduces the stack usage again
> 
> tree-checker.c:check_leaf                    -264 (728 -> 464)
> 
> Signed-off-by: David Sterba <dsterba@suse.com>

Reviewed-by: Josef Bacik <jbacik@fb.com>

Thanks,

Josef

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

* Re: [PATCH] btrfs: tree-check: reduce stack consumption in check_dir_item
  2018-01-10 14:28 [PATCH] btrfs: tree-check: reduce stack consumption in check_dir_item David Sterba
  2018-01-10 15:46 ` Josef Bacik
@ 2018-01-11  1:14 ` Qu Wenruo
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-01-11  1:14 UTC (permalink / raw)
  To: David Sterba, linux-btrfs; +Cc: wqu


[-- Attachment #1.1: Type: text/plain, Size: 1631 bytes --]



On 2018年01月10日 22:28, David Sterba wrote:
> I've noticed that the updated item checker stack consumption increased
> dramatically in 542f5385e20cf97447 ("btrfs: tree-checker: Add checker
> for dir item")
> 
> tree-checker.c:check_leaf                    +552 (176 -> 728)
> 
> The array is 255 bytes long, dynamic allocation would slow down the
> sanity checks so it's more reasonable to keep it on-stack. Moving the
> variable to the scope of use reduces the stack usage again
> 
> tree-checker.c:check_leaf                    -264 (728 -> 464)
> 
> Signed-off-by: David Sterba <dsterba@suse.com>

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

Thanks,
Qu

> ---
>  fs/btrfs/tree-checker.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
> index 7c55e3ba5a6c..c3c8d48f6618 100644
> --- a/fs/btrfs/tree-checker.c
> +++ b/fs/btrfs/tree-checker.c
> @@ -259,7 +259,6 @@ static int check_dir_item(struct btrfs_root *root,
>  
>  	di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
>  	while (cur < item_size) {
> -		char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)];
>  		u32 name_len;
>  		u32 data_len;
>  		u32 max_name_len;
> @@ -342,6 +341,8 @@ static int check_dir_item(struct btrfs_root *root,
>  		 */
>  		if (key->type == BTRFS_DIR_ITEM_KEY ||
>  		    key->type == BTRFS_XATTR_ITEM_KEY) {
> +			char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)];
> +
>  			read_extent_buffer(leaf, namebuf,
>  					(unsigned long)(di + 1), name_len);
>  			name_hash = btrfs_name_hash(namebuf, name_len);
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 520 bytes --]

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-10 14:28 [PATCH] btrfs: tree-check: reduce stack consumption in check_dir_item David Sterba
2018-01-10 15:46 ` Josef Bacik
2018-01-11  1:14 ` Qu Wenruo

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