linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Goldwyn Rodrigues <rgoldwyn@suse.de>
To: linux-btrfs@vger.kernel.org
Cc: Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: [PATCH 7/7] btrfs: Alloc backref_ctx on stack
Date: Tue, 27 Jul 2021 16:17:31 -0500	[thread overview]
Message-ID: <d1a4e43de270f291d97b1c00b7ca3b32ce699009.1627418762.git.rgoldwyn@suse.com> (raw)
In-Reply-To: <cover.1627418762.git.rgoldwyn@suse.com>

From: Goldwyn Rodrigues <rgoldwyn@suse.com>

Instead of using kmalloc() to allocate backref_ctx, allocate backref_ctx
on stack.

sizeof(backref_ctx) = 48

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/send.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 6ac37ae6c811..e0553fa27f85 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -1307,7 +1307,7 @@ static int find_extent_clone(struct send_ctx *sctx,
 	u64 flags = 0;
 	struct btrfs_file_extent_item *fi;
 	struct extent_buffer *eb = path->nodes[0];
-	struct backref_ctx *backref_ctx = NULL;
+	struct backref_ctx backref_ctx = {0};
 	struct clone_root *cur_clone_root;
 	struct btrfs_key found_key;
 	struct btrfs_path *tmp_path;
@@ -1322,12 +1322,6 @@ static int find_extent_clone(struct send_ctx *sctx,
 	/* We only use this path under the commit sem */
 	tmp_path->need_commit_sem = 0;
 
-	backref_ctx = kmalloc(sizeof(*backref_ctx), GFP_KERNEL);
-	if (!backref_ctx) {
-		ret = -ENOMEM;
-		goto out;
-	}
-
 	if (data_offset >= ino_size) {
 		/*
 		 * There may be extents that lie behind the file's size.
@@ -1392,12 +1386,12 @@ static int find_extent_clone(struct send_ctx *sctx,
 		cur_clone_root->found_refs = 0;
 	}
 
-	backref_ctx->sctx = sctx;
-	backref_ctx->found = 0;
-	backref_ctx->cur_objectid = ino;
-	backref_ctx->cur_offset = data_offset;
-	backref_ctx->found_itself = 0;
-	backref_ctx->extent_len = num_bytes;
+	backref_ctx.sctx = sctx;
+	backref_ctx.found = 0;
+	backref_ctx.cur_objectid = ino;
+	backref_ctx.cur_offset = data_offset;
+	backref_ctx.found_itself = 0;
+	backref_ctx.extent_len = num_bytes;
 
 	/*
 	 * The last extent of a file may be too large due to page alignment.
@@ -1405,7 +1399,7 @@ static int find_extent_clone(struct send_ctx *sctx,
 	 * __iterate_backrefs work.
 	 */
 	if (data_offset + num_bytes >= ino_size)
-		backref_ctx->extent_len = ino_size - data_offset;
+		backref_ctx.extent_len = ino_size - data_offset;
 
 	/*
 	 * Now collect all backrefs.
@@ -1416,12 +1410,12 @@ static int find_extent_clone(struct send_ctx *sctx,
 		extent_item_pos = 0;
 	ret = iterate_extent_inodes(fs_info, found_key.objectid,
 				    extent_item_pos, 1, __iterate_backrefs,
-				    backref_ctx, false);
+				    &backref_ctx, false);
 
 	if (ret < 0)
 		goto out;
 
-	if (!backref_ctx->found_itself) {
+	if (!backref_ctx.found_itself) {
 		/* found a bug in backref code? */
 		ret = -EIO;
 		btrfs_err(fs_info,
@@ -1434,7 +1428,7 @@ static int find_extent_clone(struct send_ctx *sctx,
 		    "find_extent_clone: data_offset=%llu, ino=%llu, num_bytes=%llu, logical=%llu",
 		    data_offset, ino, num_bytes, logical);
 
-	if (!backref_ctx->found)
+	if (!backref_ctx.found)
 		btrfs_debug(fs_info, "no clones found");
 
 	cur_clone_root = NULL;
@@ -1458,7 +1452,6 @@ static int find_extent_clone(struct send_ctx *sctx,
 
 out:
 	btrfs_free_path(tmp_path);
-	kfree(backref_ctx);
 	return ret;
 }
 
-- 
2.32.0


  parent reply	other threads:[~2021-07-27 21:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 12:51 [PATCH 0/7] Change allocation from kmalloc() to stack Goldwyn Rodrigues
2021-07-27 21:17 ` [PATCH 1/7] btrfs: Allocate walk_control on stack Goldwyn Rodrigues
2021-07-28  5:11   ` Anand Jain
2021-07-28  5:25     ` Anand Jain
2021-07-28 11:08   ` David Sterba
2021-07-27 21:17 ` [PATCH 2/7] btrfs: Allocate file_ra_state " Goldwyn Rodrigues
2021-07-28  5:29   ` Anand Jain
2021-07-27 21:17 ` [PATCH 3/7] btrfs: Allocate btrfs_ioctl_get_subvol_info_args " Goldwyn Rodrigues
2021-07-28  5:59   ` Anand Jain
2021-07-29 17:08   ` David Sterba
2021-07-29 17:22   ` David Sterba
2021-07-27 21:17 ` [PATCH 4/7] btrfs: Allocate btrfs_ioctl_balance_args " Goldwyn Rodrigues
2021-07-28  0:02   ` Darrick J. Wong
2021-07-28  2:04     ` Goldwyn Rodrigues
2021-07-28  1:19   ` kernel test robot
2021-07-27 21:17 ` [PATCH 5/7] btrfs: Allocate btrfs_ioctl_quota_rescan_args " Goldwyn Rodrigues
2021-07-28  6:01   ` Anand Jain
2021-07-27 21:17 ` [PATCH 6/7] btrfs: Allocate btrfs_ioctl_defrag_range_args " Goldwyn Rodrigues
2021-07-28  6:27   ` Anand Jain
2021-07-27 21:17 ` Goldwyn Rodrigues [this message]
2021-07-28  6:30   ` [PATCH 7/7] btrfs: Alloc backref_ctx " Anand Jain
  -- strict thread matches above, loose matches on Subject: below --
2021-07-27 21:17 [PATCH 0/7] Allocate structures on stack instead of kmalloc() Goldwyn Rodrigues
2021-07-29 16:51 ` 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=d1a4e43de270f291d97b1c00b7ca3b32ce699009.1627418762.git.rgoldwyn@suse.com \
    --to=rgoldwyn@suse.de \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=rgoldwyn@suse.com \
    /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 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).